build: harden and make it possible to build with -fPIE

This commit is contained in:
Oyvind Albrigtsen 2019-04-09 15:38:06 +02:00
parent 30c3a8d70f
commit f395468612
5 changed files with 48 additions and 16 deletions

View File

@ -2,7 +2,9 @@ CC=@CC@
CXX=@CXX@
CFLAGS=@CFLAGS@
CFLAGS+=-fPIC -Wall -Wformat=2 -Wstrict-prototypes -Wshadow -D_GNU_SOURCE
CFLAGS+=-Wall -Wformat=2 -Wstrict-prototypes -Wshadow -D_GNU_SOURCE
CXXFLAGS=@CXXFLAGS@
CXXFLAGS+=-Wall -Wformat=2 -Wstrict-prototypes -Wshadow -D_GNU_SOURCE
LEX=@LEX@
YACC=@YACC@

View File

@ -24,7 +24,7 @@ INCLUDES=-I../include `nss-config --cflags` `nspr-config --cflags` \
`xml2-config --cflags`
# nss sucks in way too much stuff
LIBS+=-lnss3 `xml2-config --libs`
LIBS+=-lnss3 `xml2-config --libs` -Wl,-z,now
TARGETS=${TARGET}
@ -40,7 +40,16 @@ fence_xvm: ${TARGET}
ln -snf $^ $@
fence_virt: ${fence_virt_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -L../common -lfence_virt
$(CC) $(CFLAGS) -o $@ $^ -shared $(LIBS) -L../common -lfence_virt
mcast.o: mcast.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
options.o: options.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
serial.o: serial.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^ $(INCLUDES)

View File

@ -24,6 +24,18 @@ all: ${TARGETS}
libfence_virt.a: ${libfence_virt_a_SOURCE:.c=.o}
ar rc $@ $^
fdops.o: fdops.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
ip_lookup.o: ip_lookup.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
mcast.o: mcast.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
tcp.o: tcp.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^ $(INCLUDES)

View File

@ -42,7 +42,7 @@ config.c: y.tab.h config.l
$(LEX) -oconfig.c config.l
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^ $(INCLUDES)
$(CC) $(CFLAGS) -fPIE -c -o $@ $^ $(INCLUDES)
clean:
rm -f ${TARGETS} *~ *.o testprog config.tab.c config.tab.h config.c

View File

@ -32,7 +32,7 @@ NSS_LIBS=-lnss3
XML_LIBS=`xml2-config --libs`
INCLUDES=-I../include `nss-config --cflags` `nspr-config --cflags` `xml2-config --cflags`
LIBS+=-L../common -lfence_virt -Wl,-wrap,syslog,-wrap,closelog -lpthread -luuid
LIBS+=-L../common -lfence_virt -Wl,-z,now,-wrap,syslog,-wrap,closelog -lpthread -luuid
MODULE_PATH=${libdir}/${PACKAGE_NAME}
@ -159,40 +159,49 @@ endif
all: ${TARGETS} ${MODULES}
fence_virtd: ${fence_virtd_SOURCES:.c=.o} ${fence_virtd_cxx_SOURCES:.cpp=.opp}
$(CXX) -o $@ $^ $(MAIN_LIBS) $(LIBS)
$(CXX) $(CXXFLAGS) -o $@ $^ $(MAIN_LIBS) $(LIBS)
multicast.so: ${multicast_so_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -shared $(NSS_LIBS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(NSS_LIBS)
libvirt.so: ${libvirt_so_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS)
libvirt-qmf.so: ${libvirt_qmf_so_SOURCES:.c=.o} ${libvirt_qmf_cxx_so_SOURCES:.cpp=.opp}
$(CXX) -o $@ $^ $(LIBS) -shared $(VIRT_QPID)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) -shared $(VIRT_QPID)
pm-fence.so: ${pm_fence_so_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -shared $(PACEMAKER_LIBS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(PACEMAKER_LIBS)
cpg.so: ${cpg_so_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) $(XML_LIBS) $(COROSYNC_LIBS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) $(XML_LIBS) $(COROSYNC_LIBS)
null.so: ${null_so_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -shared
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared
serial.so: ${serial_so_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) $(XML_LIBS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(VIRT_LIBS) $(UUID_LIBS) $(XML_LIBS)
tcp.so: ${tcp_so_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -shared $(NSS_LIBS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(NSS_LIBS)
vsock.so: ${vsock_so_SOURCES:.c=.o}
$(CC) -o $@ $^ $(LIBS) -shared $(NSS_LIBS)
$(CC) $(CFLAGS) -o $@ $^ $(LIBS) -shared $(NSS_LIBS)
cpg-virt.o: cpg-virt.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
virt.o: virt.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
virt-serial.o: virt-serial.c
$(CC) $(CFLAGS) -fPIC -c -o $@ $^ $(INCLUDES)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $^ $(INCLUDES)
%.opp: %.cpp
$(CXX) $(CFLAGS) -c -o $@ $^ $(INCLUDES)
$(CXX) $(CXXFLAGS) -c -o $@ $^ $(INCLUDES)
install: all
if [ ! -d ${DESTDIR}/${sbindir} ]; then \