From 2593090220228243b90a6109048c8cdf19f7a45f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Tempel?= Date: Wed, 24 Nov 2021 17:44:05 +0100 Subject: [PATCH] Allow prepending include/library search path through -COPT/-CLNK This commit separates include/library search directory options from "normal" compiler/linker options and places options passed via the `-COPT`/`-CLNK` command-line flags in-between. This allows overwriting the default search paths, since contrary to all other options, the search paths must be prepend for an -I/-L option to take precedence over an existing one. This should (hopefully) make it entirely unnecessary to ever build Cyclone twice in order to have all changes in the current source tree take effect. Fixes #476 --- Makefile.config | 22 ++++++++++++---------- cyclone.scm | 28 ++++++++++++++-------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Makefile.config b/Makefile.config index 93fd383d..bcc91833 100644 --- a/Makefile.config +++ b/Makefile.config @@ -28,12 +28,14 @@ LIBS += -ldl endif # Compiler options -CFLAGS += $(CYC_PROFILING) $(CYC_GCC_OPT_FLAGS) -fPIC -Wall -Wno-shift-negative-value -Wno-unused-command-line-argument -Iinclude -BASE_CFLAGS ?= $(CYC_PROFILING) $(CYC_GCC_OPT_FLAGS) -fPIC -Wall -Wno-shift-negative-value -Wno-unused-command-line-argument -I$(PREFIX)/include +CFLAGS += $(CYC_PROFILING) $(CYC_GCC_OPT_FLAGS) -fPIC -Wall -Wno-shift-negative-value -Wno-unused-command-line-argument +BASE_CFLAGS ?= $(CYC_PROFILING) $(CYC_GCC_OPT_FLAGS) -fPIC -Wall -Wno-shift-negative-value -Wno-unused-command-line-argument # Used by Cyclone to compile programs, no need for PIC there -BASE_PROG_CFLAGS ?= $(CYC_PROFILING) $(CYC_GCC_OPT_FLAGS) -Wall -I$(PREFIX)/include -COMP_CFLAGS ?= $(BASE_CFLAGS) -L$(PREFIX)/lib -COMP_PROG_CFLAGS ?= $(BASE_PROG_CFLAGS) +BASE_PROG_CFLAGS ?= $(CYC_PROFILING) $(CYC_GCC_OPT_FLAGS) -Wall +COMP_CFLAGS ?= $(BASE_CFLAGS) +COMP_LIBDIRS ?= -L$(PREFIX)/lib +COMP_INCDIRS ?= -I$(PREFIX)/include +COMP_PROG_CFLAGS ?= $(BASE_PROG_CFLAGS) # Use these lines instead for debugging or profiling #CFLAGS = -g -Wall @@ -57,15 +59,15 @@ endif # concurrencykit was installed via Ports, it won't be picked up without explicitly looking # for it here ifeq ($(OS),FreeBSD) -LDFLAGS += -L/usr/local/lib -CFLAGS += -I/usr/local/include +COMP_LIBDIRS += -L/usr/local/lib +COMP_INCDIRS += -I/usr/local/include endif # Commands "baked into" cyclone for invoking the C compiler -CC_PROG ?= "$(CC) ~src-file~ $(COMP_PROG_CFLAGS) -c -o ~exec-file~.o" -CC_EXEC ?= "$(CC) ~exec-file~.o ~obj-files~ $(LIBS) $(COMP_CFLAGS) -o ~exec-file~" -CC_LIB ?= "$(CC) ~src-file~ $(COMP_CFLAGS) -c -o ~exec-file~.o" +CC_PROG ?= "$(CC) ~src-file~ $(COMP_PROG_CFLAGS) ~cc-extra~ $(COMP_INCDIRS) -c -o ~exec-file~.o" +CC_EXEC ?= "$(CC) ~exec-file~.o ~obj-files~ $(LIBS) $(COMP_CFLAGS) ~ld-extra~ $(COMP_LIBDIRS) -o ~exec-file~" +CC_LIB ?= "$(CC) ~src-file~ $(COMP_CFLAGS) ~cc-extra~ $(COMP_LIBDIRS) -c -o ~exec-file~.o" CC_SO ?= "$(CC) -shared $(LDFLAGS) -o ~exec-file~.so ~exec-file~.o" AR ?= ar diff --git a/cyclone.scm b/cyclone.scm index 5e6d2c2a..d66e6104 100644 --- a/cyclone.scm +++ b/cyclone.scm @@ -882,27 +882,27 @@ (string-append (string-replace-all (string-replace-all - ;(Cyc-compilation-environment 'cc-prog) - (get-comp-env 'cc-prog cc-prog) - "~src-file~" src-file) + (string-replace-all + ;(Cyc-compilation-environment 'cc-prog) + (get-comp-env 'cc-prog cc-prog) + "~src-file~" src-file) + "~cc-extra~" cc-opts) "~exec-file~" exec-file) " " - cc-opts - " " cc-opts*)) (comp-objs-cmd (string-append (string-replace-all (string-replace-all (string-replace-all - ;(Cyc-compilation-environment 'cc-exec) - (get-comp-env 'cc-exec cc-exec) - "~exec-file~" exec-file) + (string-replace-all + ;(Cyc-compilation-environment 'cc-exec) + (get-comp-env 'cc-exec cc-exec) + "~exec-file~" exec-file) + "~ld-extra~" cc-prog-linker-opts) "~obj-files~" objs-str) "~exec-file~" exec-file) " " - cc-prog-linker-opts - " " c-linker-options ))) ;(write `(DEBUG all imports ,lib-deps objs ,objs-str)) @@ -922,12 +922,12 @@ (string-append (string-replace-all (string-replace-all - (get-comp-env 'cc-lib cc-lib) - "~src-file~" src-file) + (string-replace-all + (get-comp-env 'cc-lib cc-lib) + "~src-file~" src-file) + "~cc-extra~" cc-opts) "~exec-file~" exec-file) " " - cc-opts - " " cc-opts*)) (comp-so-cmd (string-append