Skip to content

Commit 4e023bb

Browse files
committed
Fix compiler flags handling
Filter out -fPIE for libraries, make sure we always add include paths to CFLAGS (use overrides), and append -fPIC only for libraries.
1 parent 0a0fc9d commit 4e023bb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Makefile

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
PKG_CONFIG ?= pkg-config
22
CFLAGS ?= -O2 -g
3-
CFLAGS += $(shell ${PKG_CONFIG} --cflags gtk+-3.0) $(shell ${PKG_CONFIG} --cflags gobject-introspection-1.0) -pthread -Wall -fPIC
3+
override CFLAGS += $(shell ${PKG_CONFIG} --cflags gtk+-3.0) $(shell ${PKG_CONFIG} --cflags gobject-introspection-1.0) -pthread -Wall
44
LDLIBS = -ldl
5+
CFLAGS_LIB = $(filter-out -fPIE -fpie -pie,$(CFLAGS)) -fPIC
6+
LDFLAGS_LIB = $(filter-out -fPIE -fpie -pie,$(LDFLAGS)) -fPIC
57

68
prefix ?= /usr/local
79
libdir ?= $(prefix)/lib
@@ -15,7 +17,10 @@ clean:
1517
[ ! -d testlibs ] || rm -r testlibs
1618

1719
libgtk3-nocsd.so.0: gtk3-nocsd.o
18-
$(CC) -shared $(CFLAGS) $(LDFLAGS) -Wl,-soname,libgtk3-nocsd.so.0 -o $@ $^ $(LDLIBS)
20+
$(CC) -shared $(CFLAGS_LIB) $(LDFLAGS_LIB) -Wl,-soname,libgtk3-nocsd.so.0 -o $@ $^ $(LDLIBS)
21+
22+
gtk3-nocsd.o: gtk3-nocsd.c
23+
$(CC) $(CPPFLAGS) $(CFLAGS_LIB) -o $@ -c $<
1924

2025
gtk3-nocsd: gtk3-nocsd.in
2126
sed 's|@@libdir@@|$(libdir)|g' < $< > $@
@@ -47,8 +52,8 @@ testlibs/stamp: test-dummylib.c
4752
for i in A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
4853
a b c d e f g h i j k l m n o p q r s t u v w x y z \
4954
0 1 2 3 4 5 6 7 8 9 ; do \
50-
$(CC) $(CFLAGS) $(CPPFLAGS) -ftls-model=initial-exec -DTESTLIB_NAME=$$i -c -o testlibs/libdummy-$$i.o test-dummylib.c ; \
51-
$(CC) -shared $(CFLAGS) $(LDFLAGS) -Wl,-soname,libdummy-$$i.so.0 -o testlibs/libdummy-$$i.so.0 testlibs/libdummy-$$i.o $(LDLIBS) ; \
55+
$(CC) $(CPPFLAGS) $(CFLAGS_LIB) -ftls-model=initial-exec -DTESTLIB_NAME=$$i -c -o testlibs/libdummy-$$i.o test-dummylib.c ; \
56+
$(CC) -shared $(CFLAGS_LIB) $(LDFLAGS_LIB) -Wl,-soname,libdummy-$$i.so.0 -o testlibs/libdummy-$$i.so.0 testlibs/libdummy-$$i.o $(LDLIBS) ; \
5257
done
5358
touch testlibs/stamp
5459

0 commit comments

Comments
 (0)