154 lines
4.3 KiB
Diff
154 lines
4.3 KiB
Diff
|
From ace0369d26868163dd4f3ba1612812a1c6187197 Mon Sep 17 00:00:00 2001
|
||
|
From: Julian Ospald <hasufell@posteo.de>
|
||
|
Date: Tue, 21 Feb 2017 17:18:42 +0100
|
||
|
Subject: [PATCH] Improve build system
|
||
|
Upstream: submitted https://github.com/gkdr/axc/pull/1
|
||
|
|
||
|
* respect toolchain
|
||
|
* make stuff more Make compatible
|
||
|
---
|
||
|
makefile | 85 ++++++++++++++++++++++++++++++++++++++++------------------------
|
||
|
1 file changed, 53 insertions(+), 32 deletions(-)
|
||
|
|
||
|
diff --git a/makefile b/makefile
|
||
|
index 2ca357f..7841a5f 100644
|
||
|
--- a/lib/axc/makefile
|
||
|
+++ b/lib/axc/makefile
|
||
|
@@ -1,3 +1,15 @@
|
||
|
+### toolchain
|
||
|
+#
|
||
|
+CC ?= gcc
|
||
|
+AR ?= ar
|
||
|
+PKG_CONFIG ?= pkg-config
|
||
|
+LIBGCRYPT_CONFIG ?= libgcrypt-config
|
||
|
+MKDIR = mkdir
|
||
|
+MKDIR_P = mkdir -p
|
||
|
+CMAKE ?= cmake
|
||
|
+CMAKE_FLAGS = -DCMAKE_BUILD_TYPE=Debug
|
||
|
+
|
||
|
+
|
||
|
SDIR = src
|
||
|
LDIR = lib
|
||
|
BDIR = build
|
||
|
@@ -9,76 +21,85 @@ AX_DIR=./lib/libaxolotl-c
|
||
|
AX_BDIR=$(AX_DIR)/build/src
|
||
|
AX_PATH=$(AX_BDIR)/libaxolotl-c.a
|
||
|
|
||
|
-PKGCFG_C=$(shell pkg-config --cflags sqlite3 glib-2.0) $(shell libgcrypt-config --cflags)
|
||
|
-PKGCFG_L=$(shell pkg-config --libs sqlite3 glib-2.0) $(shell libgcrypt-config --libs)
|
||
|
+PKGCFG_C=$(shell $(PKG_CONFIG) --cflags sqlite3 glib-2.0) \
|
||
|
+ $(shell $(LIBGCRYPT_CONFIG) --cflags)
|
||
|
+PKGCFG_L=$(shell $(PKG_CONFIG) --libs sqlite3 glib-2.0) \
|
||
|
+ $(shell $(LIBGCRYPT_CONFIG) --libs)
|
||
|
|
||
|
HEADERS=-I$(AX_DIR)/src
|
||
|
-CFLAGS=$(HEADERS) $(PKGCFG_C) -std=c11 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -funsigned-char -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE -fno-builtin-memset
|
||
|
+CFLAGS += $(HEADERS) $(PKGCFG_C) -std=c11 -Wall -Wextra -Wpedantic \
|
||
|
+ -Wstrict-overflow -fno-strict-aliasing -funsigned-char \
|
||
|
+ -fno-builtin-memset
|
||
|
+CPPFLAGS += -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE
|
||
|
TESTFLAGS=$(HEADERS) $(PKGCFG_C) -g -O0 --coverage
|
||
|
PICFLAGS=-fPIC $(CFLAGS)
|
||
|
-LFLAGS = -pthread -ldl $(PKGCFG_L) $(AX_PATH) -lm
|
||
|
-LFLAGS_T= -lcmocka $(LFLAGS)
|
||
|
+LDFLAGS += -pthread -ldl $(PKGCFG_L) $(AX_PATH) -lm
|
||
|
+LDFLAGS_T= -lcmocka $(LFLAGS)
|
||
|
|
||
|
all: $(BDIR)/libaxc.a
|
||
|
|
||
|
$(BDIR):
|
||
|
- mkdir -p $@
|
||
|
+ $(MKDIR_P) $@
|
||
|
|
||
|
client: $(SDIR)/message_client.c $(BDIR)/axc_store.o $(BDIR)/axc_crypto.o $(BDIR)/axc.o $(AX_PATH)
|
||
|
- mkdir -p $@
|
||
|
- gcc -D_POSIX_SOURCE -D_XOPEN_SOURCE=700 $(CFLAGS) $^ -o $@/$@.o $(LFLAGS)
|
||
|
-
|
||
|
+ $(MKDIR_P) $@
|
||
|
+ $(CC) $(CPPFLAGS) $(CFLAGS) $^ -o $@/$@.o $(LDFLAGS)
|
||
|
+
|
||
|
$(BDIR)/axc.o: $(SDIR)/axc.c $(BDIR)
|
||
|
- gcc $(PICFLAGS) -c $< -o $@
|
||
|
-
|
||
|
+ $(CC) $(PICFLAGS) $(CPPFLAGS) -c $< -o $@
|
||
|
+
|
||
|
$(BDIR)/axc-nt.o: $(SDIR)/axc.c $(BDIR)
|
||
|
- gcc $(PICFLAGS) -DNO_THREADS -c $< -o $@
|
||
|
-
|
||
|
+ $(CC) $(PICFLAGS) $(CPPFLAGS) -DNO_THREADS -c $< -o $@
|
||
|
+
|
||
|
$(BDIR)/axc_crypto.o: $(SDIR)/axc_crypto.c $(BDIR)
|
||
|
- gcc $(PICFLAGS) -c $< -o $@
|
||
|
+ $(CC) $(PICFLAGS) $(CPPFLAGS) -c $< -o $@
|
||
|
|
||
|
$(BDIR)/axc_store.o: $(SDIR)/axc_store.c $(BDIR)
|
||
|
- gcc $(PICFLAGS) -c $< -o $@
|
||
|
-
|
||
|
+ $(CC) $(PICFLAGS) $(CPPFLAGS) -c $< -o $@
|
||
|
+
|
||
|
$(BDIR)/libaxc.a: $(BDIR)/axc.o $(BDIR)/axc_crypto.o $(BDIR)/axc_store.o
|
||
|
- ar rcs $@ $^
|
||
|
-
|
||
|
+ $(AR) rcs $@ $^
|
||
|
+
|
||
|
$(BDIR)/libaxc-nt.a: $(BDIR)/axc-nt.o $(BDIR)/axc_crypto.o $(BDIR)/axc_store.o
|
||
|
- ar rcs $@ $^
|
||
|
+ $(AR) rcs $@ $^
|
||
|
|
||
|
$(AX_PATH):
|
||
|
- cd $(AX_DIR) && mkdir -p build && cd build && cmake -DCMAKE_BUILD_TYPE=Debug .. && make
|
||
|
-
|
||
|
+ cd $(AX_DIR) && \
|
||
|
+ $(MKDIR_P) build && \
|
||
|
+ cd build && \
|
||
|
+ $(CMAKE) $(CMAKE_FLAGS) .. && \
|
||
|
+ $(MAKE)
|
||
|
+
|
||
|
.PHONY: test
|
||
|
test: $(AX_PATH) test_store.o test_client.o
|
||
|
|
||
|
.PHONY: test_store.o
|
||
|
test_store.o: $(SDIR)/axc_store.c $(SDIR)/axc_crypto.c $(TDIR)/test_store.c
|
||
|
- gcc $(TESTFLAGS) -o $(TDIR)/$@ $(TDIR)/test_store.c $(SDIR)/axc_crypto.c $(LFLAGS_T)
|
||
|
+ $(CC) $(TESTFLAGS) -o $(TDIR)/$@ $(TDIR)/test_store.c $(SDIR)/axc_crypto.c $(LDFLAGS_T)
|
||
|
-$(TDIR)/$@
|
||
|
mv *.g* $(TDIR)
|
||
|
-
|
||
|
+
|
||
|
test_store: test_store.o
|
||
|
-
|
||
|
+
|
||
|
.PHONY: test_client.o
|
||
|
test_client.o: $(SDIR)/axc.c $(SDIR)/axc_crypto.c $(SDIR)/axc_store.c $(TDIR)/test_client.c
|
||
|
- gcc $(TESTFLAGS) -g $(HEADERS) -o $(TDIR)/$@ $(SDIR)/axc_crypto.c $(TDIR)/test_client.c $(LFLAGS_T)
|
||
|
+ $(CC) $(TESTFLAGS) -g $(HEADERS) -o $(TDIR)/$@ $(SDIR)/axc_crypto.c $(TDIR)/test_client.c $(LDFLAGS_T)
|
||
|
-$(TDIR)/$@
|
||
|
mv *.g* $(TDIR)
|
||
|
-
|
||
|
-test_client: test_client.o
|
||
|
-
|
||
|
+
|
||
|
+test_client: test_client.o
|
||
|
+
|
||
|
.PHONY: coverage
|
||
|
coverage: test
|
||
|
gcovr -r . --html --html-details -o $@.html
|
||
|
gcovr -r . -s
|
||
|
- mkdir -p $@
|
||
|
+ $(MKDIR_P) $@
|
||
|
mv $@.* $@
|
||
|
-
|
||
|
+
|
||
|
.PHONY: clean
|
||
|
clean:
|
||
|
rm -rf client $(BDIR) $(CDIR) $(AX_DIR)/build
|
||
|
rm -f $(TDIR)/*.o
|
||
|
rm -f $(TDIR)/*.gcno $(TDIR)/*.gcda $(TDIR)/*.sqlite
|
||
|
-
|
||
|
-
|
||
|
+
|
||
|
+
|
||
|
--
|
||
|
2.11.1
|
||
|
|