Skip to content

Commit c83c08c

Browse files
committed
Fix compiler/linker flags handling
- Make flags always overridable by user ({C,LD}FLAGS ?=) - Move customizable bits (-O, -g) into default CFLAGS/LDFLAGS, and leave mandatory ones in BASIC_{C,LD}FLAGS - Apply BASIC_{C,LD}FLAGS before {C,LD}FLAGS, because the latter may contain e.g. additional -I/-L paths and these should come after local ones such as -I./argparse
1 parent 6ac9ae3 commit c83c08c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ all::
77

88
### Defaults
99

10-
BASIC_CFLAGS = -O2 -std=c99 -Wall -I./argparse
10+
BASIC_CFLAGS = -std=c99 -Wall -I./argparse
1111
BASIC_LDFLAGS = -lm -lsodium
1212

1313
# Guard against environment variables
@@ -29,13 +29,13 @@ uname_P := $(shell sh -c 'uname -p 2>/dev/null || echo not')
2929
uname_V := $(shell sh -c 'uname -v 2>/dev/null || echo not')
3030

3131
# CFLAGS and LDFLAGS are for users to override
32-
CFLAGS = -g -O2 -Wall
33-
LDFLAGS =
32+
CFLAGS ?= -g -O2 -Wall
33+
LDFLAGS ?=
3434
STRIP ?= strip
3535

3636
# We use ALL_* variants
37-
ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS)
38-
ALL_LDFLAGS = $(LDFLAGS) $(BASIC_LDFLAGS)
37+
ALL_CFLAGS = $(BASIC_CFLAGS) $(CFLAGS)
38+
ALL_LDFLAGS = $(BASIC_LDFLAGS) $(LDFLAGS)
3939

4040
ifdef PREFIX
4141
prefix = $(PREFIX)

argparse/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Defaults
2-
BASIC_CFLAGS = -Wall -O3 -g -ggdb -fPIC
2+
CFLAGS ?= -O3 -g -ggdb
3+
LDFLAGS ?=
4+
5+
BASIC_CFLAGS = -Wall -fPIC
36
BASIC_LDFLAGS = -lm
47

58
# We use ALL_* variants
6-
ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS)
7-
ALL_LDFLAGS = $(LDFLAGS) $(BASIC_LDFLAGS)
9+
ALL_CFLAGS = $(BASIC_CFLAGS) $(CFLAGS)
10+
ALL_LDFLAGS = $(BASIC_LDFLAGS) $(LDFLAGS)
811

912
LIBNAME=libargparse
1013

0 commit comments

Comments
 (0)