Skip to content

Commit

Permalink
Fix compiler flags handling
Browse files Browse the repository at this point in the history
Filter out -fPIE for libraries, make sure we always add include paths to
CFLAGS (use overrides), and append -fPIC only for libraries.
  • Loading branch information
chris-se committed Oct 15, 2015
1 parent 0a0fc9d commit 4e023bb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
PKG_CONFIG ?= pkg-config
CFLAGS ?= -O2 -g
CFLAGS += $(shell ${PKG_CONFIG} --cflags gtk+-3.0) $(shell ${PKG_CONFIG} --cflags gobject-introspection-1.0) -pthread -Wall -fPIC
override CFLAGS += $(shell ${PKG_CONFIG} --cflags gtk+-3.0) $(shell ${PKG_CONFIG} --cflags gobject-introspection-1.0) -pthread -Wall
LDLIBS = -ldl
CFLAGS_LIB = $(filter-out -fPIE -fpie -pie,$(CFLAGS)) -fPIC
LDFLAGS_LIB = $(filter-out -fPIE -fpie -pie,$(LDFLAGS)) -fPIC

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

libgtk3-nocsd.so.0: gtk3-nocsd.o
$(CC) -shared $(CFLAGS) $(LDFLAGS) -Wl,-soname,libgtk3-nocsd.so.0 -o $@ $^ $(LDLIBS)
$(CC) -shared $(CFLAGS_LIB) $(LDFLAGS_LIB) -Wl,-soname,libgtk3-nocsd.so.0 -o $@ $^ $(LDLIBS)

gtk3-nocsd.o: gtk3-nocsd.c
$(CC) $(CPPFLAGS) $(CFLAGS_LIB) -o $@ -c $<

gtk3-nocsd: gtk3-nocsd.in
sed 's|@@libdir@@|$(libdir)|g' < $< > $@
Expand Down Expand Up @@ -47,8 +52,8 @@ testlibs/stamp: test-dummylib.c
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 \
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 \
0 1 2 3 4 5 6 7 8 9 ; do \
$(CC) $(CFLAGS) $(CPPFLAGS) -ftls-model=initial-exec -DTESTLIB_NAME=$$i -c -o testlibs/libdummy-$$i.o test-dummylib.c ; \
$(CC) -shared $(CFLAGS) $(LDFLAGS) -Wl,-soname,libdummy-$$i.so.0 -o testlibs/libdummy-$$i.so.0 testlibs/libdummy-$$i.o $(LDLIBS) ; \
$(CC) $(CPPFLAGS) $(CFLAGS_LIB) -ftls-model=initial-exec -DTESTLIB_NAME=$$i -c -o testlibs/libdummy-$$i.o test-dummylib.c ; \
$(CC) -shared $(CFLAGS_LIB) $(LDFLAGS_LIB) -Wl,-soname,libdummy-$$i.so.0 -o testlibs/libdummy-$$i.so.0 testlibs/libdummy-$$i.o $(LDLIBS) ; \
done
touch testlibs/stamp

Expand Down

0 comments on commit 4e023bb

Please sign in to comment.