ast2firm: Implement casting from complex to real types.
[cparser] / Makefile
index 7f489c7..c015777 100644 (file)
--- a/Makefile
+++ b/Makefile
+# 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  = -DHAVE_CONFIG_H -DFIRM_BACKEND
-CPPFLAGS += -I.
-CPPFLAGS += $(FIRM_CFLAGS)
+CPPFLAGS  = -I.
+CPPFLAGS += $(FIRM_CPPFLAGS)
 
-CFLAGS += -Wall -W -Wstrict-prototypes -Wmissing-prototypes -Werror -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 -Werror
-LFLAGS += -pg
-ICC    ?= true
-GCCO1  ?= true
+CFLAGS += -Wall -W -Wstrict-prototypes -Wmissing-prototypes -std=c99
+CFLAGS_debug    = -O0 -g
+CFLAGS_optimize = -O3 -fomit-frame-pointer -DNDEBUG
+CFLAGS_profile  = -pg -O3 -fno-inline
+CFLAGS_coverage = --coverage -O0
+CFLAGS += $(CFLAGS_$(variant))
 
-LFLAGS += $(FIRM_LIBS)
+LINKFLAGS_profile  = -pg
+LINKFLAGS_coverage = --coverage
+LINKFLAGS += $(LINKFLAGS_$(variant)) $(FIRM_LIBS)
 
-SOURCES := \
-       adt/hashset.c \
+cparser_SOURCES = \
        adt/strset.c \
-       adt/obstack.c \
-       adt/obstack_printf.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_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 \
-       parser.c \
+       mangle.c \
+       preprocessor.c \
+       printer.c \
+       string_rep.c \
        symbol_table.c \
        token.c \
        type.c \
-       types.c \
        type_hash.c \
+       types.c \
+       help.c \
        warning.c \
-       write_fluffy.c \
-       driver/firm_cmdline.c \
-       driver/firm_timing.c \
-       driver/firm_codegen.c \
-       driver/firm_opt.c \
-       driver/gen_firm_asm.c \
+       walk.c \
+       wrappergen/write_fluffy.c \
+       wrappergen/write_jna.c \
+       wrappergen/write_compoundsizes.c
+cparser_OBJECTS = $(cparser_SOURCES:%.c=$(builddir)/%.o)
+cparser_DEPS    = $(cparser_OBJECTS:%.o=%.d)
+
+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)
 
-OBJECTS = $(SOURCES:%.c=build/%.o)
+Q = @
 
-SPLINTS = $(addsuffix .splint, $(SOURCES))
-CPARSERS = $(addsuffix .cparser, $(SOURCES))
-CPARSEROS = $(SOURCES:%.c=build/cpb/%.o)
+GOAL = $(builddir)/cparser
+all: $(GOAL)
 
-Q = @
+# disable make builtin suffix rules
+.SUFFIXES:
 
-.PHONY : all clean dirs
+-include $(cparser_DEPS)
 
-all: $(GOAL)
+.PHONY: all bootstrap bootstrap2 bootstrape clean selfcheck splint libfirm_subdir
 
-ifeq ($(findstring $(MAKECMDGOALS), clean depend),)
--include .depend
-endif
+$(cparser_SOURCES): config.h
+config.h:
+       cp config.h.in $@
 
 %.h:
        @true
 
-.depend: $(SOURCES)
-       @echo "#define cparser_REVISION \"`svnversion -n .`\"" > .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
-
-$(GOAL): build/adt build/driver $(OBJECTS)
-       @echo "===> LD $@"
-       $(Q)$(CC) $(OBJECTS) $(LFLAGS) -o $(GOAL)
+REVISION ?= $(shell git describe --abbrev=40 --always --dirty --match '')
 
-cparser.bootstrap: $(CPARSEROS)
-       @echo "===> LD $@"
-       $(Q)$(CC) $(CPARSEROS) $(LFLAGS) -o $@
+# 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   := $(sort $(dir $(cparser_OBJECTS)))
+UNUSED := $(shell mkdir -p $(DIRS) $(DIRS:$(builddir)/%=$(builddir)/cpb/%) $(DIRS:$(builddir)/%=$(builddir)/cpb2/%) $(DIRS:$(builddir)/%=$(builddir)/cpbe/%))
 
+$(GOAL): $(LIBFIRM_FILE) $(cparser_OBJECTS)
+       @echo "===> LD $@"
+       $(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: cparser.bootstrape
+
+bootstrap2: cparser.bootstrap2
 
 %.c.splint: %.c
        @echo '===> SPLINT $<'
@@ -101,21 +143,34 @@ bootstrap: build/cpb build/cpb/adt build/cpb/driver $(CPARSEROS) cparser.bootstr
        @echo '===> CPARSER $<'
        $(Q)./cparser $(CPPFLAGS) -fsyntax-only $<
 
-build/adt build/driver build/cpb build/cpb/adt build/cpb/driver:
-       @echo "===> MKDIR $@"
-       $(Q)mkdir -p $@
-
-build/cpb/%.o: %.c
+$(builddir)/cpb/%.o: %.c $(builddir)/cparser
        @echo '===> CPARSER $<'
-       $(Q)./cparser $(CPPFLAGS) -Wall -c $< -o $@
+       $(Q)./$(builddir)/cparser $(CPPFLAGS) -std=c99 -Wall -g3 -c $< -o $@
+
+$(builddir)/cpbe/%.o: %.c
+       @echo '===> ECCP $@'
+       $(Q)eccp $(CPPFLAGS) -std=c99 -Wall -c $< -o $@
+
+$(builddir)/cpb2/%.o: %.c cparser.bootstrap
+       @echo '===> CPARSER.BOOTSTRAP $<'
+       $(Q)./cparser.bootstrap $(CPPFLAGS) -Wall -g -c $< -o $@
+
+cparser.bootstrap: $(CPARSEROS)
+       @echo "===> LD $@"
+       $(Q)./$(builddir)/cparser $(CPARSEROS) $(LIBFIRM_FILE) $(LINKFLAGS) -o $@
+
+cparser.bootstrape: $(CPARSEROS_E)
+       @echo "===> LD $@"
+       $(Q)gcc $(CPARSEROS_E) $(LINKFLAGS) -o $@
+
+cparser.bootstrap2: cparser.bootstrap $(CPARSEROS2)
+       @echo "===> LD $@"
+       $(Q)./cparser.bootstrap $(CPARSEROS2) $(LIBFIRM_FILE) $(LINKFLAGS) -o $@
 
-build/%.o: %.c
-       @echo '===> CC $<'
-#-$(Q)build/cparser $(CPPFLAGS) $(CFLAGS) -fsyntax-only $<
-       $(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 build/* $(GOAL) .depend
+       $(Q)rm -rf $(cparser_OBJECTS) $(GOAL)