Skip to content

Commit 36ba3f6

Browse files
committed
build: rework CFLAGS handling
Based on http://msteveb.github.io/autosetup/articles/handling-cflags/ using autosetup 0.7.1 Signed-off-by: Steve Bennett <[email protected]>
1 parent d6edb13 commit 36ba3f6

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

Makefile.in

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ SHOBJ_LDFLAGS ?= @SHOBJ_LDFLAGS@
4040
@else
4141
SHOBJ_LDFLAGS ?= @SHOBJ_LDFLAGS_R@
4242
@endif
43-
CFLAGS = @CFLAGS@ @CCOPTS@ @CPPFLAGS@
44-
CXXFLAGS = @CXXFLAGS@ @CXXOPTS@
43+
AS_CFLAGS = @AS_CFLAGS@
44+
AS_CXXFLAGS = @AS_CFLAGS@
45+
AS_CPPFLAGS = @AS_CPPFLAGS@
46+
CFLAGS ?= @CFLAGS@
47+
CXXFLAGS ?= @CXXFLAGS@
4548
LDFLAGS = @LDFLAGS@
4649
LDLIBS += @LDLIBS@
4750
LIBS += @LIBS@
@@ -50,11 +53,9 @@ prefix ?= @prefix@
5053
docdir = @docdir@
5154
srcdir := @srcdir@
5255

53-
CC += -Wall $(OPTIM) -I.
54-
CXX += -Wall $(OPTIM) -I.
56+
AS_CPPFLAGS += -Wall -I.
5557
@if [get-define srcdir] ne "."
56-
CFLAGS += -I@srcdir@
57-
CXXFLAGS += -I@srcdir@
58+
AS_CPPFLAGS += -I@srcdir@
5859
VPATH := @srcdir@
5960
@endif
6061

@@ -69,9 +70,9 @@ DEF_LD_PATH := @LD_LIBRARY_PATH@="@builddir@:$(@LD_LIBRARY_PATH@)"
6970
@endif
7071

7172
@if HAVE_CXX_EXTENSIONS
72-
JIMSH_CC := $(CXX) $(CXXFLAGS)
73+
JIMSH_CC := $(CXX) $(AS_CXXFLAGS) $(CXXFLAGS)
7374
@else
74-
JIMSH_CC := $(CC) $(CFLAGS)
75+
JIMSH_CC := $(CC) $(AS_FLAGS) $(CFLAGS)
7576
@endif
7677

7778
OBJS := _load-static-exts.o jim-subcmd.o jim-interactive.o jim-format.o jim.o utf8.o jimregexp.o jimiocompat.o \
@@ -93,11 +94,11 @@ all: $(JIMSH) @C_EXT_SHOBJS@
9394
$(ECHO) " TCLEXT _$*.c"
9495
$(Q)@tclsh@ @srcdir@/make-c-ext.tcl $< >_$*.c
9596
$(ECHO) " CC $@"
96-
$(Q)$(CC) $(CFLAGS) -c -o $@ _$*.c
97+
$(Q)$(CC) $(AS_CFLAGS) $(AS_CPPFLAGS) $(CFLAGS) $(CPPFLAGS) -c -o $@ _$*.c
9798

9899
.c.o:
99100
$(ECHO) " CC $@"
100-
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
101+
$(Q)$(CC) $(AS_CFLAGS) $(AS_CPPFLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $< -o $@
101102

102103
$(JIMSH): $(LIBJIM) jimsh.o initjimsh.o
103104
$(ECHO) " LINK $@"
@@ -163,7 +164,7 @@ $(LIBJIM): $(OBJS)
163164
$(Q)$(RANLIB) $@
164165
@else
165166
$(ECHO) " LDSO $@ libjim@SH_SOEXT@"
166-
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(SH_LDFLAGS) -o $@ $(OBJS) $(LDLIBS) $(LIBS)
167+
$(Q)$(CC) $(AS_CFLAGS) $(CFLAGS) $(LDFLAGS) $(SH_LDFLAGS) -o $@ $(OBJS) $(LDLIBS) $(LIBS)
167168
@if SH_SOEXT ne LIBSOEXT
168169
$(Q)ln -s -f $@ libjim@SH_SOEXT@
169170
@endif

auto.def

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ options-defaults {
1111
use cc cc-shared cc-db cc-lib pkg-config util
1212
use local
1313

14+
# CFLAGS, CXXFLAGS only come from the user
15+
define CFLAGS [get-env CFLAGS ""]
16+
define CXXFLAGS [get-env CFLAGS ""]
17+
1418
options {
1519
utf8 => "Include support for utf8-encoded strings"
1620
lineedit=1 => "Disable line editing"
@@ -190,19 +194,18 @@ if {"-Werror" in [get-define CFLAGS] && [cctest -cflags -Wno-error]} {
190194
cc-check-types "long long"
191195
cc-check-sizeof int
192196

193-
define CCOPTS ""
194-
define CXXOPTS ""
195-
if {[cctest -cflags -fno-unwind-tables]} {
196-
define-append CCOPTS -fno-unwind-tables
197-
}
198-
if {[cctest -cflags -fno-asynchronous-unwind-tables]} {
199-
define-append CCOPTS -fno-asynchronous-unwind-tables
197+
# Default optimisation
198+
define-append AS_CPPFLAGS -O2
199+
200+
# check, but don't add to -cflags
201+
cc-with {} {
202+
cc-check-flags -fno-unwind-tables -fno-asynchronous-unwind-tables
200203
}
201204
if {[opt-bool coverage]} {
202205
if {[cctest -link 1 -cflags --coverage]} {
203206
# When using coverage, disable ccache and compiler optimisation
204207
define CCACHE ""
205-
define-append CCOPTS --coverage -O0
208+
define-append AS_CFLAGS --coverage -O0
206209
define-append LDFLAGS --coverage
207210
define COVERAGE 1
208211
if {[cc-check-progs gcovr]} {
@@ -286,7 +289,7 @@ switch -glob -- $host_os {
286289
define TCL_PLATFORM_PLATFORM windows
287290
define TCL_PLATFORM_PATH_SEPARATOR {;}
288291
# Target WinXP or later. Should this be configurable?
289-
define-append CCOPTS -D_WIN32_WINNT=0x501 -Wno-deprecated-declarations
292+
define-append AS_CFLAGS -D_WIN32_WINNT=0x501 -Wno-deprecated-declarations
290293
}
291294
default {
292295
# Note that cygwin is considered a unix platform
@@ -370,7 +373,7 @@ proc opt-bool-or-full {opt} {
370373
if {[opt-bool-or-full utf8]} {
371374
msg-result "Enabling UTF-8"
372375
define JIM_UTF8
373-
define-append CCOPTS -DUSE_UTF8
376+
define-append AS_CFLAGS -DUSE_UTF8
374377
define PARSE_UNIDATA_FLAGS ""
375378
incr jimregexp
376379
} else {
@@ -399,7 +402,7 @@ if {[opt-bool-or-full ssl]} {
399402
define JIM_SSL
400403
define-append LDLIBS [pkg-config-get $pkg LIBS]
401404
define-append LDFLAGS [pkg-config-get $pkg LDFLAGS]
402-
define-append CCOPTS [pkg-config-get $pkg CFLAGS]
405+
define-append AS_CFLAGS [pkg-config-get $pkg CFLAGS]
403406
msg-result "Enabling SSL ($pkg)"
404407
define-append PKG_CONFIG_REQUIRES $pkg
405408
break
@@ -417,7 +420,7 @@ if {[opt-bool-or-full ssl]} {
417420
}
418421
# Later versions deprecate TLSv1_2_method, but older versions don't have TLS_method
419422
if {![cc-check-function-in-lib TLS_method ssl]} {
420-
define-append CCOPTS -DUSE_TLSv1_2_method
423+
define-append AS_CFLAGS -DUSE_TLSv1_2_method
421424
}
422425
}
423426
if {[opt-bool-or-full lineedit]} {
@@ -427,7 +430,7 @@ if {[opt-bool-or-full lineedit]} {
427430
define-append PARSE_UNIDATA_FLAGS -width
428431
lappend extra_objs linenoise.o
429432
if {[cc-check-inline] && [is-defined inline]} {
430-
define-append CCOPTS -Dinline=[get-define inline]
433+
define-append AS_CFLAGS -Dinline=[get-define inline]
431434
}
432435
}
433436
}

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/bin/sh
22
dir="`dirname "$0"`/autosetup"
3+
#@@INITCHECK@@#
34
WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"

0 commit comments

Comments
 (0)