let jam create gen_builtins.h
authorMatthias Braun <matze@braunis.de>
Sun, 14 Feb 2010 23:41:05 +0000 (23:41 +0000)
committerMatthias Braun <matze@braunis.de>
Sun, 14 Feb 2010 23:41:05 +0000 (23:41 +0000)
[r27158]

.build_plugin
Makefile
create_builtins_h.sh

index bbd79f6..572ce4b 100644 (file)
@@ -3,6 +3,30 @@ SOURCES = ;
 for d in $(DIRS) {
        SOURCES += [ Wildcard $(d) : *.c *.h ] ;
 }
+
+actions RunGenerator bind GENERATOR {
+       $(GENERATOR) $(>) > $(<)
+}
+
+rule BuiltinGenerator {
+       local target = [ LocateTarget $(<) : $(SUBDIR) ] ;
+       local source = [ SearchSource $(>) ] ;
+       local generator = [ SearchSource $(3) ] ;
+       local header = $(target) ;
+       Depends $(<) : $(target) ;
+       Depends $(target) : $(generator) ;
+       Depends $(target) : $(source) ;
+       RunGenerator $(target) : $(source) ;
+       GENERATOR on $(target) = $(generator) ;
+
+       Includes $(header:G=) : $(header) ;
+
+       Clean clean : $(target) ;
+
+       return $(target) ;
+}
+BuiltinGenerator gen_builtins.h : builtins/builtins.c : create_builtins_h.sh ;
+
 Application cparser : $(SOURCES) ;
 CppFlags cparser : -DFIRM_BACKEND -I$(top_srcdir)/libfirm/include ;
 IncludeDir cparser : . ;
index 8432df0..1ed5445 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,7 @@ SOURCES := \
        parser.c \
        ast.c \
        ast2firm.c \
+       builtins.c \
        diagnostic.c \
        driver/firm_cmdline.c \
        driver/firm_codegen.c \
@@ -122,11 +123,11 @@ $(DIRS):
        @echo "===> MKDIR $@"
        $(Q)mkdir -p $@
 
-builtins.h: builtins/builtins.c create_builtins_h.sh
+gen_builtins.h: builtins/builtins.c create_builtins_h.sh
        @echo '===> CREATE_BUILTINS $<'
-       $(Q)./create_builtins_h.sh > $@
+       $(Q)./create_builtins_h.sh "$<" > $@
 
-main.c: builtins.h
+main.c: gen_builtins.h
 
 build/cpb/%.o: %.c build/cparser
        @echo '===> CPARSER $<'
index 441f281..f8b560e 100755 (executable)
@@ -1,12 +1,14 @@
 #!/bin/sh
 
+INPUT="$1"
+
 cat <<__EOF__
 /* WARNING: automatically generated file. Generated from builtins/builtins.c */
 
 static const char builtins[] =
 __EOF__
 
-cat builtins/builtins.c | sed -e "s/^/\\\"/g" -e "s/$/\\\n\\\"/g"
+cat "$INPUT" | sed -e "s/^/\\\"/g" -e "s/$/\\\n\\\"/g"
 
 cat << __EOF__
 ;