Skip to content

Commit df15eee

Browse files
committed
Merge pull request #2 from kevin-dot-pyle/master
Build system improvements
2 parents a29cf4f + 6816d4d commit df15eee

File tree

8 files changed

+68
-77
lines changed

8 files changed

+68
-77
lines changed

Makefile

Lines changed: 56 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see
1616
# <http://www.gnu.org/licenses/>.
1717

18-
GCC=gcc
18+
.PHONY: all clean debug dump_gimple plugin show-ssa tarball test-suite testcpychecker testcpybuilder
1919

2020
PLUGIN_SOURCE_FILES= \
2121
gcc-python.c \
@@ -37,6 +37,8 @@ PLUGIN_SOURCE_FILES= \
3737
gcc-python-variable.c \
3838
gcc-python-version.c \
3939
gcc-python-wrapper.c \
40+
41+
PLUGIN_GENERATED_SOURCE_FILES:= \
4042
autogenerated-callgraph.c \
4143
autogenerated-cfg.c \
4244
autogenerated-option.c \
@@ -50,8 +52,10 @@ PLUGIN_SOURCE_FILES= \
5052
autogenerated-tree.c \
5153
autogenerated-variable.c
5254

53-
PLUGIN_OBJECT_FILES= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
54-
GCCPLUGINS_DIR:= $(shell $(GCC) --print-file-name=plugin)
55+
PLUGIN_OBJECT_SOURCE_FILES:= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
56+
PLUGIN_OBJECT_GENERATED_FILES:= $(patsubst %.c,%.o,$(PLUGIN_GENERATED_SOURCE_FILES))
57+
PLUGIN_OBJECT_FILES:= $(PLUGIN_OBJECT_SOURCE_FILES) $(PLUGIN_OBJECT_GENERATED_FILES)
58+
GCCPLUGINS_DIR:= $(shell $(CC) --print-file-name=plugin)
5559

5660
GENERATOR_DEPS=cpybuilder.py wrapperbuilder.py
5761

@@ -90,85 +94,65 @@ PYTHON_CONFIG=python-config
9094
#PYTHON=python3-debug
9195
#PYTHON_CONFIG=python3.2dmu-config
9296

93-
PYTHON_CFLAGS=$(shell $(PYTHON_CONFIG) --cflags)
94-
PYTHON_LDFLAGS=$(shell $(PYTHON_CONFIG) --ldflags)
97+
PYTHON_INCLUDES=$(shell $(PYTHON_CONFIG) --includes)
98+
PYTHON_LIBS=$(shell $(PYTHON_CONFIG) --libs)
99+
100+
GCC_PYTHON_PLUGIN_SO := python.so
95101

96-
CFLAGS+= -I$(GCCPLUGINS_DIR)/include -fPIC -fno-strict-aliasing -O2 -Wall -Werror -g $(PYTHON_CFLAGS) $(PYTHON_LDFLAGS)
102+
CPPFLAGS+= -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -I. $(PYTHON_INCLUDES)
103+
# Allow user to pick optimization, choose whether warnings are fatal,
104+
# and choose debugging information level.
105+
CFLAGS?=-O2 -Werror -g
106+
# Force these settings
107+
CFLAGS+= -fPIC -fno-strict-aliasing -Wall
108+
LIBS+= $(PYTHON_LIBS)
97109
ifneq "$(PLUGIN_PYTHONPATH)" ""
98-
CFLAGS+= -DPLUGIN_PYTHONPATH='"$(PLUGIN_PYTHONPATH)"'
110+
CPPFLAGS+= -DPLUGIN_PYTHONPATH='"$(PLUGIN_PYTHONPATH)"'
99111
endif
100112

101113
all: autogenerated-config.h testcpybuilder test-suite testcpychecker
102114

103-
plugin: autogenerated-config.h python.so
104-
105-
python.so: $(PLUGIN_OBJECT_FILES)
106-
$(GCC) $(CFLAGS) -shared $^ -o $@
107-
108-
clean:
109-
rm -f *.so *.o
110-
rm -f autogenerated*
111-
rm -rf docs/_build
112-
113-
autogenerated-config.h: configbuilder.py generate-config-h.py
114-
$(PYTHON) generate-config-h.py -o $@ --gcc=$(GCC)
115-
116-
autogenerated-gimple-types.txt: gimple-types.txt.in
117-
cpp $(CFLAGS) $^ -o $@
118-
119-
autogenerated-rtl-types.txt: rtl-types.txt.in
120-
cpp $(CFLAGS) $^ -o $@
115+
plugin: autogenerated-config.h $(GCC_PYTHON_PLUGIN_SO)
121116

122-
autogenerated-tree-types.txt: tree-types.txt.in
123-
cpp $(CFLAGS) $^ -o $@
117+
$(GCC_PYTHON_PLUGIN_SO): $(PLUGIN_OBJECT_FILES)
118+
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -shared $^ -o $@ $(LIBS)
124119

125-
autogenerated-callgraph.c: $(GENERATOR_DEPS) generate-callgraph-c.py
126-
$(PYTHON) generate-callgraph-c.py > $@
120+
$(PLUGIN_OBJECT_GENERATED_FILES): CPPFLAGS+= $(if $(srcdir),-I$(srcdir))
127121

128-
autogenerated-cfg.c: $(GENERATOR_DEPS) generate-cfg-c.py
129-
$(PYTHON) generate-cfg-c.py > $@
122+
# This is the standard .c->.o recipe, but it needs to be stated
123+
# explicitly to support the case that $(srcdir) is not blank.
124+
$(PLUGIN_OBJECT_SOURCE_FILES): %.o: $(srcdir)%.c autogenerated-config.h $(srcdir)gcc-python.h
125+
$(COMPILE.c) $(OUTPUT_OPTION) $<
130126

131-
autogenerated-function.c: $(GENERATOR_DEPS) generate-function-c.py
132-
$(PYTHON) generate-function-c.py > $@
133-
134-
autogenerated-gimple.c: $(GENERATOR_DEPS) generate-gimple-c.py autogenerated-gimple-types.txt maketreetypes.py
135-
$(PYTHON) generate-gimple-c.py > $@
136-
137-
autogenerated-location.c: $(GENERATOR_DEPS) generate-location-c.py
138-
$(PYTHON) generate-location-c.py > $@
139-
140-
autogenerated-option.c: $(GENERATOR_DEPS) generate-option-c.py
141-
$(PYTHON) generate-option-c.py > $@
142-
143-
autogenerated-parameter.c: $(GENERATOR_DEPS) generate-parameter-c.py
144-
$(PYTHON) generate-parameter-c.py > $@
145-
146-
autogenerated-pass.c: $(GENERATOR_DEPS) generate-pass-c.py
147-
$(PYTHON) generate-pass-c.py > $@
127+
clean:
128+
$(RM) *.so *.o autogenerated*
129+
$(RM) -r docs/_build
148130

149-
autogenerated-pretty-printer.c: $(GENERATOR_DEPS) generate-pretty-printer-c.py
150-
$(PYTHON) generate-pretty-printer-c.py > $@
131+
autogenerated-config.h: $(addprefix $(srcdir),generate-config-h.py configbuilder.py)
132+
$(PYTHON) $< -o $@ --gcc=$(CC)
151133

152-
autogenerated-tree.c: $(GENERATOR_DEPS) generate-tree-c.py autogenerated-tree-types.txt maketreetypes.py
153-
$(PYTHON) generate-tree-c.py > $@
134+
autogenerated-%.txt: $(srcdir)%.txt.in
135+
$(CPP) $(CPPFLAGS) -x c-header $^ -o $@
154136

155-
autogenerated-rtl.c: $(GENERATOR_DEPS) generate-rtl-c.py autogenerated-rtl-types.txt maketreetypes.py
156-
$(PYTHON) generate-rtl-c.py > $@
137+
$(PLUGIN_GENERATED_SOURCE_FILES): autogenerated-%.c: $(addprefix $(srcdir),generate-%-c.py $(GENERATOR_DEPS))
138+
$(PYTHON) $< > $@
157139

158-
autogenerated-variable.c: $(GENERATOR_DEPS) generate-variable-c.py autogenerated-gimple-types.txt maketreetypes.py
159-
$(PYTHON) generate-variable-c.py > $@
140+
autogenerated-gimple.c: autogenerated-gimple-types.txt autogenerated-tree-types.txt autogenerated-rtl-types.txt $(srcdir)maketreetypes.py
141+
autogenerated-tree.c: autogenerated-tree-types.txt $(srcdir)maketreetypes.py
142+
autogenerated-rtl.c: autogenerated-rtl-types.txt $(srcdir)maketreetypes.py
143+
autogenerated-variable.c: autogenerated-gimple-types.txt $(srcdir)maketreetypes.py
160144

161145
# Hint for debugging: add -v to the gcc options
162146
# to get a command line for invoking individual subprocesses
163147
# Doing so seems to require that paths be absolute, rather than relative
164148
# to this directory
165149
TEST_CFLAGS= \
166-
-fplugin=$(shell pwd)/python.so \
150+
-fplugin=$(CURDIR)/$(GCC_PYTHON_PLUGIN_SO) \
167151
-fplugin-arg-python-script=test.py
168152

169153
# A catch-all test for quick experimentation with the API:
170154
test: plugin
171-
$(GCC) -v $(TEST_CFLAGS) $(shell pwd)/test.c
155+
$(CC) -v $(TEST_CFLAGS) $(CURDIR)/test.c
172156

173157
# Selftest for the cpychecker.py code:
174158
testcpychecker: plugin
@@ -179,35 +163,35 @@ testcpybuilder:
179163
$(PYTHON) testcpybuilder.py -v
180164

181165
dump_gimple:
182-
$(GCC) -fdump-tree-gimple $(shell pwd)/test.c
166+
$(CC) -fdump-tree-gimple $(CURDIR)/test.c
183167

184168
debug: plugin
185-
$(GCC) -v $(TEST_CFLAGS) $(shell pwd)/test.c
169+
$(CC) -v $(TEST_CFLAGS) $(CURDIR)/test.c
186170

187171
# A simple demo, to make it easy to demonstrate the cpychecker:
188172
demo: plugin
189-
./gcc-with-cpychecker $(shell $(PYTHON_CONFIG) --cflags) demo.c
173+
$(srcdir)./gcc-with-cpychecker $(PYTHON_CFLAGS) demo.c
190174

191175
json-examples: plugin
192-
./gcc-with-cpychecker -I/usr/include/python2.7 libcpychecker/html/test/example1/bug.c
176+
$(srcdir)./gcc-with-cpychecker -I/usr/include/python2.7 libcpychecker/html/test/example1/bug.c
193177

194178
test-suite: plugin
195179
$(PYTHON) run-test-suite.py
196180

197181
show-ssa: plugin
198-
./gcc-with-python examples/show-ssa.py test.c
182+
$(srcdir)./gcc-with-python examples/show-ssa.py test.c
199183

200184
html: docs/tables-of-passes.rst docs/passes.svg
201185
cd docs && $(MAKE) html
202186

203187
# We commit this generated file to SCM to allow the docs to be built without
204188
# needing to build the plugin:
205189
docs/tables-of-passes.rst: plugin generate-tables-of-passes-rst.py
206-
./gcc-with-python generate-tables-of-passes-rst.py test.c > $@
190+
$(srcdir)./gcc-with-python generate-tables-of-passes-rst.py test.c > $@
207191

208192
# Likewise for this generated file:
209193
docs/passes.svg: plugin generate-passes-svg.py
210-
./gcc-with-python generate-passes-svg.py test.c
194+
$(srcdir)./gcc-with-python generate-passes-svg.py test.c
211195

212196
# Utility target, to help me to make releases
213197
# - creates a tag in git, and pushes it
@@ -216,12 +200,15 @@ docs/passes.svg: plugin generate-passes-svg.py
216200
# The following assumes that VERSION has been set e.g.
217201
# $ make tarball VERSION=0.4
218202

219-
tarball:
203+
$(HOME)/rpmbuild/SOURCES/%.tar.gz:
204+
test -n "$(VERSION)"
220205
-git tag -d v$(VERSION)
221206
git tag -a v$(VERSION) -m"$(VERSION)"
222-
git archive --format=tar --prefix=gcc-python-plugin-$(VERSION)/ v$(VERSION) | gzip > gcc-python-plugin-$(VERSION).tar.gz
223-
sha256sum gcc-python-plugin-$(VERSION).tar.gz
224-
cp gcc-python-plugin-$(VERSION).tar.gz ~/rpmbuild/SOURCES/
207+
git archive --format=tar --prefix=$*/ v$(VERSION) | gzip > $*.tar.gz
208+
sha256sum $*.tar.gz
209+
cp $*.tar.gz $@
210+
211+
tarball: $(HOME)/rpmbuild/SOURCES/gcc-python-plugin-$(VERSION).tar.gz
225212

226213
# Notes to self on making a release
227214
# ---------------------------------

configbuilder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def compile(self, test, src, extraargs):
134134
with open(srcpath, 'w') as f:
135135
f.write(src)
136136
outpath = os.path.join(dirpath, 'feature-test.o')
137-
args= [os.environ.get('GCC', 'gcc'),
137+
args= [os.environ.get('CC', 'gcc'),
138138
'-c', # don't run the linker (no main)
139139
'-o', outpath,
140140
srcpath] + extraargs

cpybuilder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
from subprocess import Popen, PIPE
1919
import re
20-
import six
2120

2221
# For the purpose of the GCC plugin, it's OK to assume that we're compiling
2322
# with GCC itself, and thus we can use GCC extensions

gcc-python-option.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <Python.h>
2121
#include "gcc-python.h"
2222
#include "gcc-python-wrappers.h"
23-
#include "c-family/c-common.h" /* for warn_format */
23+
#include "c-common.h" /* for warn_format */
2424
#include "diagnostic.h"
2525

2626

gcc-python.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ int plugin_is_GPL_compatible;
3434
#include "cgraph.h"
3535
#include "opts.h"
3636

37-
#include "c-family/c-pragma.h" /* for parse_in */
37+
/*
38+
* Use an unqualified name here and rely on dual search paths to let the
39+
* compiler find it. This deals with c-pragma.h moving to a
40+
* subdirectory in newer versions of gcc.
41+
*/
42+
#include "c-pragma.h" /* for parse_in */
3843

3944
#if 0
4045
#define LOG(msg) \

run-test-suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def run_test(testdir):
253253
env['LC_ALL'] = 'C'
254254

255255
# Generate the command-line for invoking gcc:
256-
args = [os.environ.get('GCC', 'gcc')]
256+
args = [os.environ.get('CC', 'gcc')]
257257
args += ['-c'] # (don't run the linker)
258258
args += ['-o', outfile]
259259
args += ['-fplugin=%s' % os.path.abspath('python.so'),

test-builder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from subprocess import Popen, PIPE, check_call
4848

4949

50-
GCCPLUGINS_DIR = Popen([os.environ.get('GCC', 'gcc'),
50+
GCCPLUGINS_DIR = Popen([os.environ.get('CC', 'gcc'),
5151
'--print-file-name=plugin'], stdout=PIPE).communicate()[0].strip()
5252

5353

@@ -58,7 +58,7 @@
5858

5959
for pyconfig in pyconfigs:
6060
cflags = Popen([pyconfig, '--cflags', '--ldflags'], stdout=PIPE).communicate()[0]
61-
args = [os.environ.get('GCC', 'gcc')]
61+
args = [os.environ.get('CC', 'gcc')]
6262
args += ['-x', 'c'] # specify that it's C
6363
args += ['-o', 'test.so']
6464
args += cflags.split()

testcpybuilder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def write_src(self, modname, extra_cflags = None):
6969

7070

7171
def compile_src(self, extra_cflags = None):
72-
self.args = [os.environ.get('GCC', 'gcc')]
72+
self.args = [os.environ.get('CC', 'gcc')]
7373
self.args += ['-o', self.modfile]
7474
self.args += ['-I' + sc.get_python_inc(),
7575
'-I' + sc.get_python_inc(plat_specific=True)]

0 commit comments

Comments
 (0)