commit 40334a9febd8128bfd9609af893b4f58fb2c2058
Author: Kevin Pyle <gcc-python-plugin.8eaf7cd8e5128d8191fe(a)spamgourmet.com>
Date: Sat Mar 24 16:12:29 2012 -0500
Build: enable out-of-tree build
Add $(srcdir) so that the caller can run "make -f
$PATH_TO_SOURCE/Makefile srcdir=$PATH_TO_SOURCE". By default, srcdir
will be blank, so this should have no effect on in-tree builds.
Makefile | 47 +++++++++++++++++++++++++++++------------------
1 files changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/Makefile b/Makefile
index d8d2fd8..3abb5c7 100644
--- a/Makefile
+++ b/Makefile
@@ -37,6 +37,8 @@ PLUGIN_SOURCE_FILES= \
gcc-python-variable.c \
gcc-python-version.c \
gcc-python-wrapper.c \
+
+PLUGIN_GENERATED_SOURCE_FILES:= \
autogenerated-callgraph.c \
autogenerated-cfg.c \
autogenerated-option.c \
@@ -50,7 +52,9 @@ PLUGIN_SOURCE_FILES= \
autogenerated-tree.c \
autogenerated-variable.c
-PLUGIN_OBJECT_FILES= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
+PLUGIN_OBJECT_SOURCE_FILES:= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
+PLUGIN_OBJECT_GENERATED_FILES:= $(patsubst %.c,%.o,$(PLUGIN_GENERATED_SOURCE_FILES))
+PLUGIN_OBJECT_FILES:= $(PLUGIN_OBJECT_SOURCE_FILES) $(PLUGIN_OBJECT_GENERATED_FILES)
GCCPLUGINS_DIR:= $(shell $(CC) --print-file-name=plugin)
GENERATOR_DEPS=cpybuilder.py wrapperbuilder.py
@@ -91,15 +95,15 @@ PYTHON_CONFIG=python-config
#PYTHON_CONFIG=python3.2dmu-config
PYTHON_CFLAGS=$(shell $(PYTHON_CONFIG) --cflags)
-PYTHON_LDFLAGS=$(shell $(PYTHON_CONFIG) --ldflags)
+PYTHON_LIBS=$(shell $(PYTHON_CONFIG) --libs)
-CPPFLAGS+= -I$(GCCPLUGINS_DIR)/include
+CPPFLAGS+= -I$(GCCPLUGINS_DIR)/include -I.
# Allow user to pick optimization, choose whether warnings are fatal,
# and choose debugging information level.
CFLAGS?=-O2 -Werror -g
# Force these settings
CFLAGS+= -fPIC -fno-strict-aliasing -Wall $(PYTHON_CFLAGS)
-LDFLAGS+= $(PYTHON_LDFLAGS)
+LIBS+= $(PYTHON_LIBS)
ifneq "$(PLUGIN_PYTHONPATH)" ""
CPPFLAGS+= -DPLUGIN_PYTHONPATH='"$(PLUGIN_PYTHONPATH)"'
endif
@@ -109,25 +113,32 @@ all: autogenerated-config.h testcpybuilder test-suite testcpychecker
plugin: autogenerated-config.h python.so
python.so: $(PLUGIN_OBJECT_FILES)
- $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared $^ -o $@
+ $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared $^ -o $@ $(LIBS)
+
+$(PLUGIN_OBJECT_GENERATED_FILES): CPPFLAGS+= $(if $(srcdir),-I$(srcdir))
+
+# This is the standard .c->.o recipe, but it needs to be stated
+# explicitly to support the case that $(srcdir) is not blank.
+$(PLUGIN_OBJECT_SOURCE_FILES): %.o: $(srcdir)%.c autogenerated-config.h $(srcdir)gcc-python.h
+ $(COMPILE.c) $(OUTPUT_OPTION) $<
clean:
$(RM) *.so *.o autogenerated*
$(RM) -r docs/_build
-autogenerated-config.h: configbuilder.py generate-config-h.py
- $(PYTHON) generate-config-h.py -o $@ --gcc=$(CC)
+autogenerated-config.h: $(addprefix $(srcdir),generate-config-h.py configbuilder.py)
+ $(PYTHON) $< -o $@ --gcc=$(CC)
-autogenerated-%.txt: %.txt.in
+autogenerated-%.txt: $(srcdir)%.txt.in
$(CPP) $(CPPFLAGS) -x c-header $^ -o $@
-autogenerated-%.c: generate-%-c.py $(GENERATOR_DEPS)
+autogenerated-%.c: $(addprefix $(srcdir),generate-%-c.py $(GENERATOR_DEPS))
$(PYTHON) $< > $@
-autogenerated-gimple.c: autogenerated-gimple-types.txt maketreetypes.py
-autogenerated-tree.c: autogenerated-tree-types.txt maketreetypes.py
-autogenerated-rtl.c: autogenerated-rtl-types.txt maketreetypes.py
-autogenerated-variable.c: autogenerated-gimple-types.txt maketreetypes.py
+autogenerated-gimple.c: autogenerated-gimple-types.txt autogenerated-tree-types.txt autogenerated-rtl-types.txt $(srcdir)maketreetypes.py
+autogenerated-tree.c: autogenerated-tree-types.txt $(srcdir)maketreetypes.py
+autogenerated-rtl.c: autogenerated-rtl-types.txt $(srcdir)maketreetypes.py
+autogenerated-variable.c: autogenerated-gimple-types.txt $(srcdir)maketreetypes.py
# Hint for debugging: add -v to the gcc options
# to get a command line for invoking individual subprocesses
@@ -157,16 +168,16 @@ debug: plugin
# A simple demo, to make it easy to demonstrate the cpychecker:
demo: plugin
- ./gcc-with-cpychecker $(PYTHON_CFLAGS) demo.c
+ $(srcdir)./gcc-with-cpychecker $(PYTHON_CFLAGS) demo.c
json-examples: plugin
- ./gcc-with-cpychecker -I/usr/include/python2.7 libcpychecker/html/test/example1/bug.c
+ $(srcdir)./gcc-with-cpychecker -I/usr/include/python2.7 libcpychecker/html/test/example1/bug.c
test-suite: plugin
$(PYTHON) run-test-suite.py
show-ssa: plugin
- ./gcc-with-python examples/show-ssa.py test.c
+ $(srcdir)./gcc-with-python examples/show-ssa.py test.c
html: docs/tables-of-passes.rst docs/passes.svg
cd docs && $(MAKE) html
@@ -174,11 +185,11 @@ html: docs/tables-of-passes.rst docs/passes.svg
# We commit this generated file to SCM to allow the docs to be built without
# needing to build the plugin:
docs/tables-of-passes.rst: plugin generate-tables-of-passes-rst.py
- ./gcc-with-python generate-tables-of-passes-rst.py test.c > $@
+ $(srcdir)./gcc-with-python generate-tables-of-passes-rst.py test.c > $@
# Likewise for this generated file:
docs/passes.svg: plugin generate-passes-svg.py
- ./gcc-with-python generate-passes-svg.py test.c
+ $(srcdir)./gcc-with-python generate-passes-svg.py test.c
# Utility target, to help me to make releases
# - creates a tag in git, and pushes it