X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=Makefile;h=3ee81c24e8fcb2bbb7405956fd37ce1f4b725b99;hb=84b4c24ec6848505549af4b240df492317138f27;hp=80ec0bb92914055402ef4fea8a00d92df9590e14;hpb=1d51f4713f89ec9250425dabd347d452e431dd52;p=cparser diff --git a/Makefile b/Makefile index 80ec0bb..3ee81c2 100644 --- a/Makefile +++ b/Makefile @@ -1,112 +1,139 @@ +# include user-defined makefile settings -include config.mak -GOAL = $(BUILDDIR)/cparser - -BUILDDIR ?= build - -FIRM_CFLAGS ?= `pkg-config --cflags libfirm` -FIRM_LIBS ?= `pkg-config --libs libfirm` +top_srcdir ?= +top_builddir ?= build + +variant ?= debug# Different libfirm variants (debug, optimize, profile, coverage) +srcdir ?= $(top_srcdir) +builddir ?= $(top_builddir)/$(variant) + +#VPATH = $(srcdir) + +# Use libfirm subdir if it exists, otherwise use pkg-config +ifneq ("$(wildcard libfirm)", "") +FIRM_HOME ?= libfirm +FIRM_CPPFLAGS ?= -I$(FIRM_HOME)/include +FIRM_LIBS ?= -lm +LIBFIRM_FILE_BASE ?= build/$(variant)/libfirm.a +LIBFIRM_FILE ?= $(FIRM_HOME)/$(LIBFIRM_FILE_BASE) +else +FIRM_CPPFLAGS ?= `pkg-config --cflags libfirm` +FIRM_LIBS ?= `pkg-config --libs libfirm` +LIBFIRM_FILE = +endif CPPFLAGS = -I. -CPPFLAGS += $(FIRM_CFLAGS) +CPPFLAGS += $(FIRM_CPPFLAGS) CFLAGS += -Wall -W -Wstrict-prototypes -Wmissing-prototypes -std=c99 -pedantic -CFLAGS += -O0 -g3 -#CFLAGS += -O3 -march=pentium4 -fomit-frame-pointer -DNDEBUG -#CFLAGS += -pg -O3 -fno-inline -ICC_CFLAGS = -O0 -g3 -std=c99 -Wall -#LFLAGS += -pg -ICC ?= true -GCCO1 ?= true - -LFLAGS += $(FIRM_LIBS) - -SOURCES := \ - adt/hashset.c \ +CFLAGS_debug = -O0 -g +CFLAGS_optimize = -O3 -fomit-frame-pointer -DNDEBUG +CFLAGS_profile = -pg -O3 -fno-inline +CFLAGS_coverage = --coverage -O0 +CFLAGS += $(CFLAGS_$(variant)) + +LINKFLAGS_profile = -pg +LINKFLAGS_coverage = --coverage +LINKFLAGS += $(LINKFLAGS_$(variant)) $(FIRM_LIBS) + +cparser_SOURCES = \ adt/strset.c \ - adt/xmalloc.c \ + adt/strutil.c \ + adt/pset_new.c \ attribute.c \ parser.c \ ast.c \ ast2firm.c \ builtins.c \ diagnostic.c \ - driver/firm_cmdline.c \ - driver/firm_codegen.c \ + driver/firm_machine.c \ driver/firm_opt.c \ driver/firm_timing.c \ entity.c \ entitymap.c \ format_check.c \ - lexer.c \ + input.c \ + jump_target.c \ main.c \ mangle.c \ preprocessor.c \ printer.c \ + string_rep.c \ symbol_table.c \ token.c \ type.c \ type_hash.c \ types.c \ - walk_statements.c \ + help.c \ warning.c \ - wrappergen/write_caml.c \ + walk.c \ wrappergen/write_fluffy.c \ - wrappergen/write_jna.c - -OBJECTS = $(SOURCES:%.c=build/%.o) + wrappergen/write_jna.c \ + wrappergen/write_compoundsizes.c +cparser_OBJECTS = $(cparser_SOURCES:%.c=$(builddir)/%.o) +cparser_DEPS = $(cparser_OBJECTS:%.o=%.d) -SPLINTS = $(addsuffix .splint, $(SOURCES)) -CPARSERS = $(addsuffix .cparser, $(SOURCES)) -CPARSEROS = $(SOURCES:%.c=build/cpb/%.o) -CPARSEROS_E = $(SOURCES:%.c=build/cpbe/%.o) -CPARSEROS2 = $(SOURCES:%.c=build/cpb2/%.o) +SPLINTS = $(addsuffix .splint, $(cparser_SOURCES)) +CPARSERS = $(addsuffix .cparser, $(cparser_SOURCES)) +CPARSEROS = $(cparser_SOURCES:%.c=$(builddir)/cpb/%.o) +CPARSEROS_E = $(cparser_SOURCES:%.c=$(builddir)/cpbe/%.o) +CPARSEROS2 = $(cparser_SOURCES:%.c=$(builddir)/cpb2/%.o) Q = @ -all: $(DIRS) $(GOAL) +GOAL = $(builddir)/cparser +all: $(GOAL) -.PHONY: all clean dirs bootstrap bootstrap2 +# disable make builtin suffix rules +.SUFFIXES: -ifeq ($(findstring $(MAKECMDGOALS), clean depend),) --include .depend -endif +-include $(cparser_DEPS) +.PHONY: all bootstrap bootstrap2 bootstrape clean selfcheck splint libfirm_subdir + +$(cparser_SOURCES): config.h config.h: cp config.h.in $@ %.h: @true -REVISION ?= $(shell svnversion -n .) +REVISION ?= $(shell git describe --abbrev=40 --always --dirty --match '') -.depend: config.h $(SOURCES) - @echo "#define cparser_REVISION \"$(REVISION)\"" > .revision.h - $(Q)if diff -Nq .revision.h revision.h > /dev/null; then \ - rm .revision.h; \ - else \ - echo "===> UPDATING revision.h"; \ - mv .revision.h revision.h; \ - fi - @echo "===> DEPEND" - @rm -f $@ && touch $@ && makedepend -p "$@ build/" -Y -f $@ -- $(CPPFLAGS) -- $(SOURCES) 2> /dev/null && rm $@.bak +# Update revision.h if necessary +UNUSED := $(shell \ + REV="\#define cparser_REVISION \"$(REVISION)\""; \ + echo "$$REV" | cmp -s - revision.h 2> /dev/null || echo "$$REV" > revision.h \ +) -DIRS = build build/adt build/driver build/wrappergen build/cpb build/cpb/adt build/cpb/driver build/cpb/wrappergen build/cpb2 build/cpb2/adt build/cpb2/driver build/cpb2/wrappergen build/cpbe build/cpbe/adt build/cpbe/driver build/cpbe2/wrappergen -UNUSED := $(shell mkdir -p $(DIRS)) +DIRS := $(sort $(dir $(cparser_OBJECTS))) +UNUSED := $(shell mkdir -p $(DIRS) $(DIRS:$(builddir)/%=$(builddir)/cpb/%) $(DIRS:$(builddir)/%=$(builddir)/cpb2/%) $(DIRS:$(builddir)/%=$(builddir)/cpbe/%)) -$(GOAL): $(OBJECTS) $(LIBFIRM_FILE) +$(GOAL): $(LIBFIRM_FILE) $(cparser_OBJECTS) @echo "===> LD $@" - $(Q)$(CC) $(OBJECTS) $(LFLAGS) -o $(GOAL) + $(Q)$(CC) $(cparser_OBJECTS) $(LIBFIRM_FILE) -o $(GOAL) $(LINKFLAGS) + +ifneq ("$(LIBFIRM_FILE)", "") +ifneq ("$(MAKECMDGOALS)", "clean") +$(LIBFIRM_FILE): libfirm_subdir +# Re-evaluate Makefile after libfirm_subdir has been executed +Makefile: libfirm_subdir +# Build libfirm in subdirectory +libfirm_subdir: + $(Q)$(MAKE) -C $(FIRM_HOME) $(LIBFIRM_FILE_BASE) +endif +endif splint: $(SPLINTS) selfcheck: $(CPARSERS) -bootstrap: build/cpb build/cpb/adt build/cpb/driver $(CPARSEROS) cparser.bootstrap +bootstrap: cparser.bootstrap -bootstrape: build/cpb build/cpb/adt build/cpb/driver $(CPARSEROS_E) cparser.bootstrape +bootstrape: cparser.bootstrape -bootstrap2: build/cpb2 build/cpb2/adt build/cpb2/driver $(CPARSEROS2) cparser.bootstrap2 +bootstrap2: cparser.bootstrap2 %.c.splint: %.c @echo '===> SPLINT $<' @@ -116,46 +143,34 @@ bootstrap2: build/cpb2 build/cpb2/adt build/cpb2/driver $(CPARSEROS2) cparser.bo @echo '===> CPARSER $<' $(Q)./cparser $(CPPFLAGS) -fsyntax-only $< -$(DIRS): - @echo "===> MKDIR $@" - $(Q)mkdir -p $@ - -gen_builtins.h: builtins/builtins.c create_builtins_h.sh - @echo '===> CREATE_BUILTINS $<' - $(Q)./create_builtins_h.sh "$<" > $@ - -main.c: gen_builtins.h - -build/cpb/%.o: %.c build/cparser +$(builddir)/cpb/%.o: %.c $(builddir)/cparser @echo '===> CPARSER $<' - $(Q)./build/cparser $(CPPFLAGS) -std=c99 -Wall -g3 -c $< -o $@ + $(Q)./$(builddir)/cparser $(CPPFLAGS) -std=c99 -Wall -g3 -c $< -o $@ -build/cpbe/%.o: %.c - @echo '===> ECCP $<' +$(builddir)/cpbe/%.o: %.c + @echo '===> ECCP $@' $(Q)eccp $(CPPFLAGS) -std=c99 -Wall -c $< -o $@ -build/cpb2/%.o: %.c cparser.bootstrap +$(builddir)/cpb2/%.o: %.c cparser.bootstrap @echo '===> CPARSER.BOOTSTRAP $<' $(Q)./cparser.bootstrap $(CPPFLAGS) -Wall -g -c $< -o $@ cparser.bootstrap: $(CPARSEROS) @echo "===> LD $@" - $(Q)./build/cparser $(CPARSEROS) $(LFLAGS) -o $@ + $(Q)./$(builddir)/cparser $(CPARSEROS) $(LIBFIRM_FILE) $(LINKFLAGS) -o $@ cparser.bootstrape: $(CPARSEROS_E) @echo "===> LD $@" - $(Q)gcc $(CPARSEROS_E) $(LFLAGS) -o $@ + $(Q)gcc $(CPARSEROS_E) $(LINKFLAGS) -o $@ -cparser.bootstrap2: $(CPARSEROS2) +cparser.bootstrap2: cparser.bootstrap $(CPARSEROS2) @echo "===> LD $@" - $(Q)./cparser.bootstrap $(CPARSEROS2) $(LFLAGS) -o $@ + $(Q)./cparser.bootstrap $(CPARSEROS2) $(LIBFIRM_FILE) $(LINKFLAGS) -o $@ -build/%.o: %.c - @echo '===> CC $<' -#$(Q)$(ICC) $(CPPFLAGS) $(ICC_CFLAGS) -c $< -o $@ -#$(Q)$(GCCO1) $(CPPFLAGS) $(CFLAGS) -O1 -c $< -o $@ - $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@ +$(builddir)/%.o: %.c + @echo '===> CC $@' + $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -c -o $@ $< clean: @echo '===> CLEAN' - $(Q)rm -rf gen_builtins.h build/* $(GOAL) .depend + $(Q)rm -rf $(cparser_OBJECTS) $(GOAL)