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
This commit is contained in:
Sören Tempel 2021-11-24 17:44:05 +01:00
parent 86949ae500
commit 2593090220
2 changed files with 26 additions and 24 deletions

View file

@ -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

View file

@ -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