From 82d6200d2f412cbc6636bf0661fea8cbee08e5a2 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 18 Mar 2012 16:21:28 -0500 Subject: [PATCH 01/15] Derive gcc name from $CC, not $GCC Make assumes that CC will be set to the active C compiler, so package managers automatically set CC accordingly. Read $CC instead of $GCC to take advantage of that. --- Makefile | 14 ++++++-------- configbuilder.py | 2 +- run-test-suite.py | 2 +- test-builder.py | 4 ++-- testcpybuilder.py | 2 +- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 8efad812..dcba3a45 100644 --- a/Makefile +++ b/Makefile @@ -15,8 +15,6 @@ # along with this program. If not, see # . -GCC=gcc - PLUGIN_SOURCE_FILES= \ gcc-python.c \ gcc-python-attribute.c \ @@ -51,7 +49,7 @@ PLUGIN_SOURCE_FILES= \ autogenerated-variable.c PLUGIN_OBJECT_FILES= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES)) -GCCPLUGINS_DIR:= $(shell $(GCC) --print-file-name=plugin) +GCCPLUGINS_DIR:= $(shell $(CC) --print-file-name=plugin) GENERATOR_DEPS=cpybuilder.py wrapperbuilder.py @@ -103,7 +101,7 @@ all: autogenerated-config.h testcpybuilder test-suite testcpychecker plugin: autogenerated-config.h python.so python.so: $(PLUGIN_OBJECT_FILES) - $(GCC) $(CFLAGS) -shared $^ -o $@ + $(CC) $(CFLAGS) -shared $^ -o $@ clean: rm -f *.so *.o @@ -111,7 +109,7 @@ clean: rm -rf docs/_build autogenerated-config.h: configbuilder.py generate-config-h.py - $(PYTHON) generate-config-h.py -o $@ --gcc=$(GCC) + $(PYTHON) generate-config-h.py -o $@ --gcc=$(CC) autogenerated-gimple-types.txt: gimple-types.txt.in cpp $(CFLAGS) $^ -o $@ @@ -168,7 +166,7 @@ TEST_CFLAGS= \ # A catch-all test for quick experimentation with the API: test: plugin - $(GCC) -v $(TEST_CFLAGS) $(shell pwd)/test.c + $(CC) -v $(TEST_CFLAGS) $(shell pwd)/test.c # Selftest for the cpychecker.py code: testcpychecker: plugin @@ -179,10 +177,10 @@ testcpybuilder: $(PYTHON) testcpybuilder.py -v dump_gimple: - $(GCC) -fdump-tree-gimple $(shell pwd)/test.c + $(CC) -fdump-tree-gimple $(shell pwd)/test.c debug: plugin - $(GCC) -v $(TEST_CFLAGS) $(shell pwd)/test.c + $(CC) -v $(TEST_CFLAGS) $(shell pwd)/test.c # A simple demo, to make it easy to demonstrate the cpychecker: demo: plugin diff --git a/configbuilder.py b/configbuilder.py index 0bebfef7..3a420bbb 100644 --- a/configbuilder.py +++ b/configbuilder.py @@ -134,7 +134,7 @@ def compile(self, test, src, extraargs): with open(srcpath, 'w') as f: f.write(src) outpath = os.path.join(dirpath, 'feature-test.o') - args= [os.environ.get('GCC', 'gcc'), + args= [os.environ.get('CC', 'gcc'), '-c', # don't run the linker (no main) '-o', outpath, srcpath] + extraargs diff --git a/run-test-suite.py b/run-test-suite.py index 47d3a95d..d277b3f3 100644 --- a/run-test-suite.py +++ b/run-test-suite.py @@ -253,7 +253,7 @@ def run_test(testdir): env['LC_ALL'] = 'C' # Generate the command-line for invoking gcc: - args = [os.environ.get('GCC', 'gcc')] + args = [os.environ.get('CC', 'gcc')] args += ['-c'] # (don't run the linker) args += ['-o', outfile] args += ['-fplugin=%s' % os.path.abspath('python.so'), diff --git a/test-builder.py b/test-builder.py index 9a0b1ed9..4540fe6f 100644 --- a/test-builder.py +++ b/test-builder.py @@ -47,7 +47,7 @@ from subprocess import Popen, PIPE, check_call -GCCPLUGINS_DIR = Popen([os.environ.get('GCC', 'gcc'), +GCCPLUGINS_DIR = Popen([os.environ.get('CC', 'gcc'), '--print-file-name=plugin'], stdout=PIPE).communicate()[0].strip() @@ -58,7 +58,7 @@ for pyconfig in pyconfigs: cflags = Popen([pyconfig, '--cflags', '--ldflags'], stdout=PIPE).communicate()[0] - args = [os.environ.get('GCC', 'gcc')] + args = [os.environ.get('CC', 'gcc')] args += ['-x', 'c'] # specify that it's C args += ['-o', 'test.so'] args += cflags.split() diff --git a/testcpybuilder.py b/testcpybuilder.py index 2c766cd4..424bb713 100644 --- a/testcpybuilder.py +++ b/testcpybuilder.py @@ -69,7 +69,7 @@ def write_src(self, modname, extra_cflags = None): def compile_src(self, extra_cflags = None): - self.args = [os.environ.get('GCC', 'gcc')] + self.args = [os.environ.get('CC', 'gcc')] self.args += ['-o', self.modfile] self.args += ['-I' + sc.get_python_inc(), '-I' + sc.get_python_inc(plat_specific=True)] From 3ea2de7efa17b1ab60b9aa9382aacf5b93925096 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 18 Mar 2012 16:21:28 -0500 Subject: [PATCH 02/15] Build: add various pseudo-targets to .PHONY Listing these targets in .PHONY forces make not to check for a corresponding file. This is a slight performance improvement and avoids unwanted behavior if the build directory ever has a file named 'all', 'clean', etc. --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index dcba3a45..90bc716a 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,8 @@ # along with this program. If not, see # . +.PHONY: all clean debug dump_gimple plugin show-ssa tarball test-suite testcpychecker testcpybuilder + PLUGIN_SOURCE_FILES= \ gcc-python.c \ gcc-python-attribute.c \ From 5bdf3521338a7183d77f05c58165095d50351138 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 18 Mar 2012 16:21:28 -0500 Subject: [PATCH 03/15] Use $(CURDIR) instead of shell call. GNU make sets CURDIR to the value of the current directory. Use that instead of running a subshell to execute 'pwd'. --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 90bc716a..9d3a2267 100644 --- a/Makefile +++ b/Makefile @@ -163,12 +163,12 @@ autogenerated-variable.c: $(GENERATOR_DEPS) generate-variable-c.py autogenerated # Doing so seems to require that paths be absolute, rather than relative # to this directory TEST_CFLAGS= \ - -fplugin=$(shell pwd)/python.so \ + -fplugin=$(CURDIR)/python.so \ -fplugin-arg-python-script=test.py # A catch-all test for quick experimentation with the API: test: plugin - $(CC) -v $(TEST_CFLAGS) $(shell pwd)/test.c + $(CC) -v $(TEST_CFLAGS) $(CURDIR)/test.c # Selftest for the cpychecker.py code: testcpychecker: plugin @@ -179,10 +179,10 @@ testcpybuilder: $(PYTHON) testcpybuilder.py -v dump_gimple: - $(CC) -fdump-tree-gimple $(shell pwd)/test.c + $(CC) -fdump-tree-gimple $(CURDIR)/test.c debug: plugin - $(CC) -v $(TEST_CFLAGS) $(shell pwd)/test.c + $(CC) -v $(TEST_CFLAGS) $(CURDIR)/test.c # A simple demo, to make it easy to demonstrate the cpychecker: demo: plugin From 4c083ca0670865fa4370af0fdf52d9dbeaed4e3b Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 18 Mar 2012 16:21:28 -0500 Subject: [PATCH 04/15] Use pattern rules for building generated files. Most of the generated files follow one of a small number of general recipes. Replace the explicit per-file recipes with a pattern rule. --- Makefile | 50 ++++++++------------------------------------------ 1 file changed, 8 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 9d3a2267..3425c5f7 100644 --- a/Makefile +++ b/Makefile @@ -113,50 +113,16 @@ clean: autogenerated-config.h: configbuilder.py generate-config-h.py $(PYTHON) generate-config-h.py -o $@ --gcc=$(CC) -autogenerated-gimple-types.txt: gimple-types.txt.in - cpp $(CFLAGS) $^ -o $@ +autogenerated-%.txt: %.txt.in + $(CPP) $(CPPFLAGS) -x c-header $^ -o $@ -autogenerated-rtl-types.txt: rtl-types.txt.in - cpp $(CFLAGS) $^ -o $@ +autogenerated-%.c: generate-%-c.py $(GENERATOR_DEPS) + $(PYTHON) $< > $@ -autogenerated-tree-types.txt: tree-types.txt.in - cpp $(CFLAGS) $^ -o $@ - -autogenerated-callgraph.c: $(GENERATOR_DEPS) generate-callgraph-c.py - $(PYTHON) generate-callgraph-c.py > $@ - -autogenerated-cfg.c: $(GENERATOR_DEPS) generate-cfg-c.py - $(PYTHON) generate-cfg-c.py > $@ - -autogenerated-function.c: $(GENERATOR_DEPS) generate-function-c.py - $(PYTHON) generate-function-c.py > $@ - -autogenerated-gimple.c: $(GENERATOR_DEPS) generate-gimple-c.py autogenerated-gimple-types.txt maketreetypes.py - $(PYTHON) generate-gimple-c.py > $@ - -autogenerated-location.c: $(GENERATOR_DEPS) generate-location-c.py - $(PYTHON) generate-location-c.py > $@ - -autogenerated-option.c: $(GENERATOR_DEPS) generate-option-c.py - $(PYTHON) generate-option-c.py > $@ - -autogenerated-parameter.c: $(GENERATOR_DEPS) generate-parameter-c.py - $(PYTHON) generate-parameter-c.py > $@ - -autogenerated-pass.c: $(GENERATOR_DEPS) generate-pass-c.py - $(PYTHON) generate-pass-c.py > $@ - -autogenerated-pretty-printer.c: $(GENERATOR_DEPS) generate-pretty-printer-c.py - $(PYTHON) generate-pretty-printer-c.py > $@ - -autogenerated-tree.c: $(GENERATOR_DEPS) generate-tree-c.py autogenerated-tree-types.txt maketreetypes.py - $(PYTHON) generate-tree-c.py > $@ - -autogenerated-rtl.c: $(GENERATOR_DEPS) generate-rtl-c.py autogenerated-rtl-types.txt maketreetypes.py - $(PYTHON) generate-rtl-c.py > $@ - -autogenerated-variable.c: $(GENERATOR_DEPS) generate-variable-c.py autogenerated-gimple-types.txt maketreetypes.py - $(PYTHON) generate-variable-c.py > $@ +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 # Hint for debugging: add -v to the gcc options # to get a command line for invoking individual subprocesses From c0c5a85c6ad3b73c989bf375e9321629c7c9f404 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 18 Mar 2012 16:21:28 -0500 Subject: [PATCH 05/15] Split CPPFLAGS/CFLAGS/LDFLAGS. Users may want to set other optimization or debug levels, so split CFLAGS handling into two parts. The first part, which will be overridden by user environment variables, sets the default optimization and debug level for the project. The second part then applies values that should always be used. Also, move CPPFLAGS and LDFLAGS to their respective variables. --- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 3425c5f7..65308d1f 100644 --- a/Makefile +++ b/Makefile @@ -93,9 +93,15 @@ PYTHON_CONFIG=python-config PYTHON_CFLAGS=$(shell $(PYTHON_CONFIG) --cflags) PYTHON_LDFLAGS=$(shell $(PYTHON_CONFIG) --ldflags) -CFLAGS+= -I$(GCCPLUGINS_DIR)/include -fPIC -fno-strict-aliasing -O2 -Wall -Werror -g $(PYTHON_CFLAGS) $(PYTHON_LDFLAGS) +CPPFLAGS+= -I$(GCCPLUGINS_DIR)/include +# 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) ifneq "$(PLUGIN_PYTHONPATH)" "" - CFLAGS+= -DPLUGIN_PYTHONPATH='"$(PLUGIN_PYTHONPATH)"' + CPPFLAGS+= -DPLUGIN_PYTHONPATH='"$(PLUGIN_PYTHONPATH)"' endif all: autogenerated-config.h testcpybuilder test-suite testcpychecker @@ -103,7 +109,7 @@ all: autogenerated-config.h testcpybuilder test-suite testcpychecker plugin: autogenerated-config.h python.so python.so: $(PLUGIN_OBJECT_FILES) - $(CC) $(CFLAGS) -shared $^ -o $@ + $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared $^ -o $@ clean: rm -f *.so *.o From 3f76a93818b47ca237c21a6d697df1e2e7c6d792 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 18 Mar 2012 16:21:29 -0500 Subject: [PATCH 06/15] Use $(RM), not explicit "rm -f". GNU make defines $RM as "rm -f", but using the indirect form allows the user to override it if needed. --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 65308d1f..bfe60b34 100644 --- a/Makefile +++ b/Makefile @@ -112,9 +112,8 @@ python.so: $(PLUGIN_OBJECT_FILES) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared $^ -o $@ clean: - rm -f *.so *.o - rm -f autogenerated* - rm -rf docs/_build + $(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) From df0fe2c24d1b3b51bd74431097fb9cfea5b362ce Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 18 Mar 2012 16:21:29 -0500 Subject: [PATCH 07/15] demo: reuse Python CFLAGS variable Convert demo recipe to use existing $(PYTHON_CFLAGS) instead of calling python-config again. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bfe60b34..eb82bb29 100644 --- a/Makefile +++ b/Makefile @@ -157,7 +157,7 @@ debug: plugin # A simple demo, to make it easy to demonstrate the cpychecker: demo: plugin - ./gcc-with-cpychecker $(shell $(PYTHON_CONFIG) --cflags) demo.c + ./gcc-with-cpychecker $(PYTHON_CFLAGS) demo.c json-examples: plugin ./gcc-with-cpychecker -I/usr/include/python2.7 libcpychecker/html/test/example1/bug.c From 4f4e14cb5b9ebe864f34d6144abda46e0edd6e90 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 18 Mar 2012 16:21:29 -0500 Subject: [PATCH 08/15] Build: rework 'tarball' to remove redundant references to output name --- Makefile | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index eb82bb29..892efd78 100644 --- a/Makefile +++ b/Makefile @@ -187,12 +187,14 @@ docs/passes.svg: plugin generate-passes-svg.py # The following assumes that VERSION has been set e.g. # $ make tarball VERSION=0.4 -tarball: +$(HOME)/rpmbuild/SOURCES/%.tar.gz: -git tag -d v$(VERSION) git tag -a v$(VERSION) -m"$(VERSION)" - git archive --format=tar --prefix=gcc-python-plugin-$(VERSION)/ v$(VERSION) | gzip > gcc-python-plugin-$(VERSION).tar.gz - sha256sum gcc-python-plugin-$(VERSION).tar.gz - cp gcc-python-plugin-$(VERSION).tar.gz ~/rpmbuild/SOURCES/ + git archive --format=tar --prefix=$*/ v$(VERSION) | gzip > $*.tar.gz + sha256sum $*.tar.gz + cp $*.tar.gz $@ + +tarball: $(HOME)/rpmbuild/SOURCES/gcc-python-plugin-$(VERSION).tar.gz # Notes to self on making a release # --------------------------------- From 4a34de52589e84e2a328c5092db2241a961adab0 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 18 Mar 2012 16:21:29 -0500 Subject: [PATCH 09/15] Build: tarball: disallow empty version An empty version is almost certainly a misspelled invocation. Disallow it. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 892efd78..d8d2fd84 100644 --- a/Makefile +++ b/Makefile @@ -188,6 +188,7 @@ docs/passes.svg: plugin generate-passes-svg.py # $ make tarball VERSION=0.4 $(HOME)/rpmbuild/SOURCES/%.tar.gz: + test -n "$(VERSION)" -git tag -d v$(VERSION) git tag -a v$(VERSION) -m"$(VERSION)" git archive --format=tar --prefix=$*/ v$(VERSION) | gzip > $*.tar.gz From 40334a9febd8128bfd9609af893b4f58fb2c2058 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sat, 24 Mar 2012 16:12:29 -0500 Subject: [PATCH 10/15] 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 file changed, 29 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index d8d2fd84..3abb5c70 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 From 99da8c8d990d254b328f4b65d4d58f527c8acb74 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sat, 24 Mar 2012 18:05:22 -0500 Subject: [PATCH 11/15] Build: only use Python includes, not all Python CFLAGS Python CFLAGS may contain settings that conflict with our own preferences, such as alternate optimization, debug, or warning choices. We only need to know where the headers were installed, so switch to --includes instead of --cflags. --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 3abb5c70..d5ee30c2 100644 --- a/Makefile +++ b/Makefile @@ -94,15 +94,15 @@ PYTHON_CONFIG=python-config #PYTHON=python3-debug #PYTHON_CONFIG=python3.2dmu-config -PYTHON_CFLAGS=$(shell $(PYTHON_CONFIG) --cflags) +PYTHON_INCLUDES=$(shell $(PYTHON_CONFIG) --includes) PYTHON_LIBS=$(shell $(PYTHON_CONFIG) --libs) -CPPFLAGS+= -I$(GCCPLUGINS_DIR)/include -I. +CPPFLAGS+= -I$(GCCPLUGINS_DIR)/include -I. $(PYTHON_INCLUDES) # 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) +CFLAGS+= -fPIC -fno-strict-aliasing -Wall LIBS+= $(PYTHON_LIBS) ifneq "$(PLUGIN_PYTHONPATH)" "" CPPFLAGS+= -DPLUGIN_PYTHONPATH='"$(PLUGIN_PYTHONPATH)"' From 598c56676f6a217543701590c91c91931041179f Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 25 Mar 2012 12:14:59 -0500 Subject: [PATCH 12/15] Build: find c-pragma.h,c-common.h regardless of gcc version Add an extra -I line for the non-flattened location, then change all inclusions to rely on the preprocessor search path to find the file. It is legal to specify a non-existent directory in the search path, so this will work with both old and new layouts. --- Makefile | 2 +- gcc-python-option.c | 2 +- gcc-python.c | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d5ee30c2..db854ff5 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,7 @@ PYTHON_CONFIG=python-config PYTHON_INCLUDES=$(shell $(PYTHON_CONFIG) --includes) PYTHON_LIBS=$(shell $(PYTHON_CONFIG) --libs) -CPPFLAGS+= -I$(GCCPLUGINS_DIR)/include -I. $(PYTHON_INCLUDES) +CPPFLAGS+= -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -I. $(PYTHON_INCLUDES) # Allow user to pick optimization, choose whether warnings are fatal, # and choose debugging information level. CFLAGS?=-O2 -Werror -g diff --git a/gcc-python-option.c b/gcc-python-option.c index 04835f59..14131379 100644 --- a/gcc-python-option.c +++ b/gcc-python-option.c @@ -20,7 +20,7 @@ #include #include "gcc-python.h" #include "gcc-python-wrappers.h" -#include "c-family/c-common.h" /* for warn_format */ +#include "c-common.h" /* for warn_format */ #include "diagnostic.h" diff --git a/gcc-python.c b/gcc-python.c index 6204bd4c..f037988f 100644 --- a/gcc-python.c +++ b/gcc-python.c @@ -34,7 +34,12 @@ int plugin_is_GPL_compatible; #include "cgraph.h" #include "opts.h" -#include "c-family/c-pragma.h" /* for parse_in */ +/* + * Use an unqualified name here and rely on dual search paths to let the + * compiler find it. This deals with c-pragma.h moving to a + * subdirectory in newer versions of gcc. + */ +#include "c-pragma.h" /* for parse_in */ #if 0 #define LOG(msg) \ From 4f23afefa35c2555f7a96f70ac26ab79ab0796e3 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 25 Mar 2012 12:28:39 -0500 Subject: [PATCH 13/15] Build: move name 'python.so' to Make variable Allow the user to change the name of the generated shared object by specifying an alternate $GCC_PYTHON_PLUGIN_SO on the command line. --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index db854ff5..e94c82f2 100644 --- a/Makefile +++ b/Makefile @@ -97,6 +97,8 @@ PYTHON_CONFIG=python-config PYTHON_INCLUDES=$(shell $(PYTHON_CONFIG) --includes) PYTHON_LIBS=$(shell $(PYTHON_CONFIG) --libs) +GCC_PYTHON_PLUGIN_SO := python.so + CPPFLAGS+= -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -I. $(PYTHON_INCLUDES) # Allow user to pick optimization, choose whether warnings are fatal, # and choose debugging information level. @@ -110,9 +112,9 @@ endif all: autogenerated-config.h testcpybuilder test-suite testcpychecker -plugin: autogenerated-config.h python.so +plugin: autogenerated-config.h $(GCC_PYTHON_PLUGIN_SO) -python.so: $(PLUGIN_OBJECT_FILES) +$(GCC_PYTHON_PLUGIN_SO): $(PLUGIN_OBJECT_FILES) $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared $^ -o $@ $(LIBS) $(PLUGIN_OBJECT_GENERATED_FILES): CPPFLAGS+= $(if $(srcdir),-I$(srcdir)) @@ -145,7 +147,7 @@ autogenerated-variable.c: autogenerated-gimple-types.txt $(srcdir)maketreetypes. # Doing so seems to require that paths be absolute, rather than relative # to this directory TEST_CFLAGS= \ - -fplugin=$(CURDIR)/python.so \ + -fplugin=$(CURDIR)/$(GCC_PYTHON_PLUGIN_SO) \ -fplugin-arg-python-script=test.py # A catch-all test for quick experimentation with the API: From 687460b420e884c7f36b71855ff6d955103c3a95 Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Sun, 25 Mar 2012 15:27:45 -0500 Subject: [PATCH 14/15] Build: cpybuilder.py does not use six.py, so remove import Remove unnecessary import of six.py, so that gcc-python-plugin can be built (although not tested) without installing six.py. --- cpybuilder.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cpybuilder.py b/cpybuilder.py index 41f613da..3dc36fbd 100644 --- a/cpybuilder.py +++ b/cpybuilder.py @@ -17,7 +17,6 @@ from subprocess import Popen, PIPE import re -import six # For the purpose of the GCC plugin, it's OK to assume that we're compiling # with GCC itself, and thus we can use GCC extensions From 6816d4d1737943ca5a0bf262b1863007c968493d Mon Sep 17 00:00:00 2001 From: Kevin Pyle Date: Mon, 26 Mar 2012 21:34:14 -0500 Subject: [PATCH 15/15] Build: prevent deletion of autogenerated-*.c Per comment from David Malcolm, deleting autogenerated-*.c files is undesirable because it makes debugging more difficult. Switch to a static pattern rule to discourage Make from deleting these files. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index e94c82f2..cd177ced 100644 --- a/Makefile +++ b/Makefile @@ -134,7 +134,7 @@ autogenerated-config.h: $(addprefix $(srcdir),generate-config-h.py configbuilder autogenerated-%.txt: $(srcdir)%.txt.in $(CPP) $(CPPFLAGS) -x c-header $^ -o $@ -autogenerated-%.c: $(addprefix $(srcdir),generate-%-c.py $(GENERATOR_DEPS)) +$(PLUGIN_GENERATED_SOURCE_FILES): autogenerated-%.c: $(addprefix $(srcdir),generate-%-c.py $(GENERATOR_DEPS)) $(PYTHON) $< > $@ autogenerated-gimple.c: autogenerated-gimple-types.txt autogenerated-tree-types.txt autogenerated-rtl-types.txt $(srcdir)maketreetypes.py