Skip to content

Commit b4d2623

Browse files
author
Kevin Pyle
committed
Support building for a gcc other than the host compiler
This allows compiling a gcc-python-plugin to run in the context of a cross-compiler. Using the cross-compiler to build gcc-python-plugin would produce a plugin that cannot be loaded on the host system.
1 parent 73cae8e commit b4d2623

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ PLUGIN_GENERATED_SOURCE_FILES:= \
5555
autogenerated-tree.c \
5656
autogenerated-variable.c
5757

58+
TARGET_GCC:=$(CC)
59+
5860
PLUGIN_OBJECT_SOURCE_FILES:= $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
5961
PLUGIN_OBJECT_GENERATED_FILES:= $(patsubst %.c,%.o,$(PLUGIN_GENERATED_SOURCE_FILES))
6062
PLUGIN_OBJECT_FILES:= $(PLUGIN_OBJECT_SOURCE_FILES) $(PLUGIN_OBJECT_GENERATED_FILES)
61-
GCCPLUGINS_DIR:= $(shell $(CC) --print-file-name=plugin)
63+
GCCPLUGINS_DIR:= $(shell $(TARGET_GCC) --print-file-name=plugin)
6264

6365
GENERATOR_DEPS=cpybuilder.py wrapperbuilder.py print-gcc-version
6466

@@ -132,7 +134,7 @@ plugin: autogenerated-config.h $(PLUGIN_DSO)
132134
# When running the plugin from a working copy, use LD_LIBARY_PATH=gcc-c-api
133135
# so that the plugin can find its libgcc-c-api.so there
134136
#
135-
INVOCATION_ENV_VARS := LD_LIBRARY_PATH=gcc-c-api CC=$(CC)
137+
INVOCATION_ENV_VARS := LD_LIBRARY_PATH=gcc-c-api CC="$(TARGET_GCC)"
136138

137139
# When installing, both the plugin and libgcc-c-api.so will be installed to
138140
# $(GCCPLUGINS_DIR), so we give the plugin an RPATH of $(GCCPLUGINS_DIR)
@@ -149,7 +151,7 @@ $(PLUGIN_DSO): $(PLUGIN_OBJECT_FILES) $(LIBGCC_C_API_SO)
149151
-lgcc-c-api -Lgcc-c-api -Wl,-rpath=$(GCCPLUGINS_DIR)
150152

151153
$(LIBGCC_C_API_SO):
152-
cd gcc-c-api && make libgcc-c-api.so CC=$(CC)
154+
cd gcc-c-api && make libgcc-c-api.so CC="$(CC)" TARGET_GCC="$(TARGET_GCC)"
153155

154156
$(PLUGIN_OBJECT_GENERATED_FILES): CPPFLAGS+= $(if $(srcdir),-I$(srcdir))
155157

@@ -170,11 +172,11 @@ clean:
170172
$(RM) -r docs/_build
171173
$(RM) -f gcc-with-$(PLUGIN_NAME).1 gcc-with-$(PLUGIN_NAME).1.gz
172174
$(RM) -f print-gcc-version
173-
cd gcc-c-api && make clean
175+
cd gcc-c-api && make clean CC="$(CC)" TARGET_GCC="$(TARGET_GCC)"
174176
find tests -name "*.o" -delete
175177

176178
autogenerated-config.h: $(addprefix $(srcdir),generate-config-h.py configbuilder.py)
177-
$(PYTHON) $< -o $@ --gcc="$(CC)" --plugindir="$(GCCPLUGINS_DIR)"
179+
$(PYTHON) $< -o $@ --gcc="$(TARGET_GCC)" --plugindir="$(GCCPLUGINS_DIR)"
178180

179181
autogenerated-%.txt: $(srcdir)%.txt.in
180182
$(CPP) $(CPPFLAGS) -x c-header $^ -o $@
@@ -266,7 +268,7 @@ TEST_CFLAGS= \
266268

267269
# A catch-all test for quick experimentation with the API:
268270
test: plugin
269-
$(INVOCATION_ENV_VARS) $(CC) -v $(TEST_CFLAGS) $(CURDIR)/test.c
271+
$(INVOCATION_ENV_VARS) $(TARGET_GCC) -v $(TEST_CFLAGS) $(CURDIR)/test.c
270272

271273
# Selftest for the cpychecker.py code:
272274
testcpychecker: plugin
@@ -277,10 +279,10 @@ testcpybuilder:
277279
$(PYTHON) testcpybuilder.py -v
278280

279281
dump_gimple:
280-
$(CC) -fdump-tree-gimple $(CURDIR)/test.c
282+
$(TARGET_GCC) -fdump-tree-gimple $(CURDIR)/test.c
281283

282284
debug: plugin
283-
$(INVOCATION_ENV_VARS) $(CC) -v $(TEST_CFLAGS) $(CURDIR)/test.c
285+
$(INVOCATION_ENV_VARS) $(TARGET_GCC) -v $(TEST_CFLAGS) $(CURDIR)/test.c
284286

285287
# A simple demo, to make it easy to demonstrate the cpychecker:
286288
demo: plugin

gcc-c-api/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ GENERATED_HEADERS:= \
7070
gcc-type.h \
7171
gcc-variable.h
7272

73-
GCCPLUGINS_DIR:= $(shell $(CC) --print-file-name=plugin)
73+
TARGET_GCC:=$(CC)
74+
75+
GCCPLUGINS_DIR:= $(shell $(TARGET_GCC) --print-file-name=plugin)
7476

7577
LIBGCC_C_API_SO := libgcc-c-api.so
7678

0 commit comments

Comments
 (0)