From 48e4c07fcd33fe1743119bde5cfa1ab414f2208a Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Tue, 21 Feb 2017 17:28:03 +0100 Subject: [PATCH] Improve build system Upstream: submitted https://github.com/gkdr/libomemo/pull/3 * respect toolchain * make stuff more Make compatible --- makefile | 80 ++++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 32 deletions(-) diff --git a/makefile b/makefile index 0785924..5d7ca01 100644 --- a/lib/libomemo/makefile +++ b/lib/libomemo/makefile @@ -1,3 +1,14 @@ +### toolchain +# +CC ?= gcc +AR ?= ar +LIBTOOL ?= libtool +PKG_CONFIG ?= pkg-config +LIBGCRYPT_CONFIG ?= libgcrypt-config +MKDIR = mkdir +MKDIR_P = mkdir -p + + SDIR = src BDIR = build TDIR = test @@ -7,66 +18,71 @@ LDIR = lib # -fno-builtin-memset is enough to make gcc not optimize it away FILES = -PKGCFG_C=$(shell pkg-config --cflags glib-2.0 sqlite3 mxml) $(shell libgcrypt-config --cflags) -PKGCFG_L=$(shell pkg-config --libs glib-2.0 sqlite3 mxml) $(shell libgcrypt-config --libs) +PKGCFG_C=$(shell $(PKG_CONFIG) --cflags glib-2.0 sqlite3 mxml) \ + $(shell $(LIBGCRYPT_CONFIG) --cflags) +PKGCFG_L=$(shell $(PKG_CONFIG) --libs glib-2.0 sqlite3 mxml) \ + $(shell $(LIBGCRYPT_CONFIG) --libs) -CFLAGS =-std=c11 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -funsigned-char -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -fno-builtin-memset $(PKGCFG_C) +CFLAGS += -std=c11 -Wall -Wextra -Wpedantic -Wstrict-overflow \ + -fno-strict-aliasing -funsigned-char \ + -fno-builtin-memset $(PKGCFG_C) +CPPFLAGS += -D_XOPEN_SOURCE=700 -D_BSD_SOURCE CFLAGS_CONVERSATIONS=$(CFLAGS) -DOMEMO_XMLNS='"eu.siacs.conversations.axolotl"' -DOMEMO_NS_SEPARATOR='"."' -DOMEMO_NS_NOVERSION COVFLAGS = --coverage -O0 -g $(CFLAGS) -LFLAGS =-pthread -ldl -lm $(PKGCFG_L) -TESTFLAGS = -lcmocka $(LFLAGS) +LDFLAGS += -pthread -ldl -lm $(PKGCFG_L) +TESTFLAGS = -lcmocka $(LDFLAGS) all: $(BDIR)/libomemo-conversations.a $(BDIR): - mkdir -p $@ - -libomemo: $(SDIR)/libomemo.c libomemo_crypto libomemo_storage $(BDIR) - libtool --mode=compile gcc -c $(SDIR)/$@.c $(CFLAGS) -o $(BDIR)/$@.lo - libtool --mode=link gcc -o $(BDIR)/$@.la $(BDIR)/$@.lo $(BDIR)/$@_crypto.lo $(BDIR)/$@_storage.lo - + $(MKDIR_P) $@ + +libomemo: $(SDIR)/libomemo.c libomemo_crypto libomemo_storage $(BDIR) + $(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/$@.c $(CFLAGS) $(CPPFLAGS) -o $(BDIR)/$@.lo + $(LIBTOOL) --mode=link $(CC) -o $(BDIR)/$@.la $(BDIR)/$@.lo $(BDIR)/$@_crypto.lo $(BDIR)/$@_storage.lo + libomemo-conversations: $(SDIR)/libomemo.c libomemo_crypto libomemo_storage $(BDIR) - libtool --mode=compile gcc -c $(SDIR)/libomemo.c $(CFLAGS_CONVERSATIONS) -o $(BDIR)/libomemo.lo - libtool --mode=link gcc -o $(BDIR)/libomemo.la $(BDIR)/libomemo.lo $(BDIR)/libomemo_crypto.lo $(BDIR)/libomemo_storage.lo + $(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/libomemo.c $(CFLAGS_CONVERSATIONS) -o $(BDIR)/libomemo.lo + $(LIBTOOL) --mode=link $(CC) -o $(BDIR)/libomemo.la $(BDIR)/libomemo.lo $(BDIR)/libomemo_crypto.lo $(BDIR)/libomemo_storage.lo libomemo_crypto: $(SDIR)/libomemo_crypto.c build - libtool --mode=compile gcc -c $(SDIR)/$@.c $(CFLAGS) -o $(BDIR)/$@.lo + $(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/$@.c $(CFLAGS) $(CPPFLAGS) -o $(BDIR)/$@.lo libomemo_storage: $(SDIR)/libomemo_storage.c build - libtool --mode=compile gcc -c $(SDIR)/$@.c $(CFLAGS) -o $(BDIR)/$@.lo + $(LIBTOOL) --mode=compile $(CC) -c $(SDIR)/$@.c $(CFLAGS) $(CPPFLAGS) -o $(BDIR)/$@.lo $(BDIR)/libomemo.o: $(BDIR) $(SDIR)/libomemo.c $(SDIR)/libomemo.h - gcc -c $(CFLAGS) $(SDIR)/libomemo.c -o $@ - + $(CC) -c $(CFLAGS) $(CPPFLAGS) $(SDIR)/libomemo.c -o $@ + $(BDIR)/libomemo-conversations.o: $(SDIR)/libomemo.c $(BDIR) - gcc -c $(SDIR)/libomemo.c $(CFLAGS_CONVERSATIONS) -fPIC -o $@ - + $(CC) -c $(SDIR)/libomemo.c $(CFLAGS_CONVERSATIONS) -fPIC -o $@ + $(BDIR)/libomemo_crypto.o: $(SDIR)/libomemo_crypto.c $(BDIR) - gcc -c $(SDIR)/libomemo_crypto.c $(CFLAGS) -fPIC -o $@ + $(CC) -c $(SDIR)/libomemo_crypto.c $(CFLAGS) $(CPPFLAGS) -fPIC -o $@ $(BDIR)/libomemo_storage.o: $(SDIR)/libomemo_storage.c $(BDIR) - gcc -c $(SDIR)/libomemo_storage.c $(CFLAGS) -fPIC -o $@ - + $(CC) -c $(SDIR)/libomemo_storage.c $(CFLAGS) $(CPPFLAGS) -fPIC -o $@ + $(BDIR)/libomemo-conversations.a: $(BDIR)/libomemo-conversations.o $(BDIR)/libomemo_crypto.o $(BDIR)/libomemo_storage.o - ar rcs $@ $^ - + $(AR) rcs $@ $^ + .PHONY = test_libomemo.o test_libomemo: $(TDIR)/test_libomemo.c $(SDIR)/libomemo.c - gcc $(COVFLAGS) $< $(FILES) -o $(TDIR)/$@.o $(TESTFLAGS) + $(CC) $(COVFLAGS) $< $(FILES) -o $(TDIR)/$@.o $(TESTFLAGS) -$(TDIR)/$@.o mv *.g* $(TDIR) - + .PHONY: test_crypto test_crypto: $(TDIR)/test_crypto.c $(SDIR)/libomemo_crypto.c - gcc $(COVFLAGS) $< $(FILES) -o $(TDIR)/$@.o $(TESTFLAGS) + $(CC) $(COVFLAGS) $< $(FILES) -o $(TDIR)/$@.o $(TESTFLAGS) -$(TDIR)/$@.o - mv *.g* $(TDIR) - + mv *.g* $(TDIR) + .PHONY: test_storage test_storage: $(TDIR)/test_storage.c $(SDIR)/libomemo_storage.c - gcc $(COVFLAGS) $< $(FILES) -o $(TDIR)/$@.o $(TESTFLAGS) + $(CC) $(COVFLAGS) $< $(FILES) -o $(TDIR)/$@.o $(TESTFLAGS) -$(TDIR)/$@.o - mv *.g* $(TDIR) + mv *.g* $(TDIR) .PHONY: test test : test_libomemo test_crypto test_storage @@ -75,7 +91,7 @@ test : test_libomemo test_crypto test_storage coverage: test gcovr -r . --html --html-details -o $@.html gcovr -r . -s - mkdir -p $@ + $(MKDIR_P) $@ mv $@.* $@ .PHONY: clean -- 2.11.1