better dependency management
[m6w6/ext-psi] / Makefile.frag
index 79af1be30d759bc6147f83426290a480754da552..d192749f055844e19afee4154f5af134d02b504f 100644 (file)
@@ -1,12 +1,17 @@
 # provide headers in builddir, so they do not end up in /usr/include/ext/psi/src
 
 PHP_PSI_HEADERS := $(addprefix $(PHP_PSI_BUILDDIR)/,$(PHP_PSI_HEADERS))
+PHP_PSI_SOURCES := $(addprefix $(PHP_PSI_SRCDIR)/,$(PHP_PSI_SOURCES))
 
+$(PHP_PSI_BUILDDIR)/types:
+       mkdir -p $@
+$(PHP_PSI_BUILDDIR)/types/%.h: $(PHP_PSI_SRCDIR)/src/types/%.h | $(PHP_PSI_BUILDDIR)/types
+       @cat >$@ <$<
 $(PHP_PSI_BUILDDIR)/%.h: $(PHP_PSI_SRCDIR)/src/%.h
        @cat >$@ <$<
 
-all: psi-build-headers
-clean: psi-clean-headers
+install-headers: psi-build-headers
+clean: psi-clean
 
 .PHONY: psi-build-headers
 psi-build-headers: $(PHP_PSI_HEADERS)
@@ -14,17 +19,68 @@ psi-build-headers: $(PHP_PSI_HEADERS)
 .PHONY: psi-clean-headers
 psi-clean-headers:
        -rm -f $(PHP_PSI_HEADERS)
+       -rmdir $(PHP_PSI_BUILDDIR)/types
+
+.PHONY: psi-clean-sources
+psi-clean-sources:
+       -rm -f $(PHP_PSI_BUILDDIR)/src/*o
+       -rm -f $(PHP_PSI_BUILDDIR)/src/types/*o
+       -rm -f $(PHP_PSI_SRCDIR)/src/parser.c $(PHP_PSI_SRCDIR)/src/parser_proc.c $(PHP_PSI_SRCDIR)/src/parser_proc.y
+
+.PHONY: psi-clean-aux
+psi-clean-aux:
+       -rm -f lempar.c lemon.c lemon
+
+.PHONY: psi-clean
+psi-clean: psi-clean-headers psi-clean-sources psi-clean-aux
+
 
 lempar.c:
-       curl -sSo $@ "http://www.sqlite.org/src/raw/tool/lempar.c?name=3617143ddb9b176c3605defe6a9c798793280120"
+       curl -sSo $@ "http://www.sqlite.org/src/raw/tool/lempar.c?name=3ec1463a034b37d87d782be5f6b8b10a3b1ecbe7"
 
 lemon.c:
-       curl -sSo $@ "http://www.sqlite.org/src/raw/tool/lemon.c?name=039f813b520b9395740c52f9cbf36c90b5d8df03"
+       curl -sSo $@ "http://www.sqlite.org/src/raw/tool/lemon.c?name=799e73e19a33b8dd7767a7fa34618ed2a9c2397d"
 
 ./lemon: lemon.c | lempar.c
+       $(CC) -o $@ $<
+
+$(PHP_PSI_SRCDIR)/src/parser_proc.h: $(PHP_PSI_SRCDIR)/src/parser_proc.c
 
+$(PHP_PSI_SRCDIR)/src/parser_proc.inc:
+$(PHP_PSI_SRCDIR)/src/parser_proc.y: $(PHP_PSI_SRCDIR)/src/parser_def.h $(PHP_PSI_SRCDIR)/src/parser_proc.inc
+       cat $(PHP_PSI_SRCDIR)/src/parser_proc.inc >$@
+       $(CPP) -P -DGENERATE $< >>$@
 $(PHP_PSI_SRCDIR)/src/parser_proc.c: $(PHP_PSI_SRCDIR)/src/parser_proc.y $(LEMON)
-       $(LEMON) -c $<
+       $(LEMON) $<
 
+$(PHP_PSI_SRCDIR)/src/parser.re: $(PHP_PSI_SRCDIR)/src/parser_proc.h
+       touch $@
 $(PHP_PSI_SRCDIR)/src/parser.c: $(PHP_PSI_SRCDIR)/src/parser.re
        $(RE2C) -o $@ $<
+
+$(PHP_PSI_SRCDIR)/src/types/decl.c: $(PHP_PSI_SRCDIR)/php_psi_macros.h $(PHP_PSI_SRCDIR)/php_psi_redirs.h
+$(PHP_PSI_SRCDIR)/src/context.c: $(PHP_PSI_SRCDIR)/php_psi_consts.h $(PHP_PSI_SRCDIR)/php_psi_decls.h $(PHP_PSI_SRCDIR)/php_psi_fn_decls.h $(PHP_PSI_SRCDIR)/php_psi_structs.h $(PHP_PSI_SRCDIR)/php_psi_types.h $(PHP_PSI_SRCDIR)/php_psi_unions.h $(PHP_PSI_SRCDIR)/php_psi_va_decls.h
+
+# -- deps
+
+PHP_PSI_DEPEND = $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(PHP_PSI_SOURCES:.c=.dep))
+
+.PHONY: psi-clean-depend
+psi-clean-depend:
+       -rm -f $(PHP_PSI_DEPEND) $(PHP_PSI_BUILDDIR)/php_psi.dep
+
+psi-clean: psi-clean-depend
+
+$(PHP_PSI_BUILDDIR)/%.dep: $(PHP_PSI_SRCDIR)/%.c
+       $(CC) -MM -MG -MF $@ -MT $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(@:.dep=.lo)) \
+               $(CPPFLAGS) $(DEFS) $(INCLUDES) $< \
+                       || touch $@
+
+DEPS = 
+ifneq  ($(DEPS),)
+-include $(PHP_PSI_DEPEND)
+-include $(PHP_PSI_BUILDDIR)/php_psi.dep
+endif
+
+
+# -- deps