More Makefile cleanup ENGINE-228
authorDamiano Boppart <damiano@pep-security.net>
Mon, 14 Aug 2017 02:26:09 +0200
branchENGINE-228
changeset 1958433df9ee336d
parent 1957 25bb8a7147ae
child 1959 fe4d994a1105
More Makefile cleanup
Makefile
Makefile.conf
asn.1/Makefile
build-config/Darwin.conf
build-config/Linux.conf
build-config/common.conf
db/Makefile
src/Makefile
sync/Makefile
test/Makefile
     1.1 --- a/Makefile	Sun Aug 13 16:19:56 2017 +0200
     1.2 +++ b/Makefile	Mon Aug 14 02:26:09 2017 +0200
     1.3 @@ -1,4 +1,6 @@
     1.4 -# this file is under GNU General Public License v3.0
     1.5 +# Copyright 2017, pEp Security SA
     1.6 +# This file is part of pEpEngine
     1.7 +# This file may be used under the terms of the GNU General Public License version 3
     1.8  # see LICENSE.txt
     1.9  
    1.10  include Makefile.conf
     2.1 --- a/Makefile.conf	Sun Aug 13 16:19:56 2017 +0200
     2.2 +++ b/Makefile.conf	Mon Aug 14 02:26:09 2017 +0200
     2.3 @@ -5,14 +5,13 @@
     2.4  
     2.5  # To use custom build configuration variables, put them in a new file at `build-config/<name>.conf`. Execute `export PLATFORM_OVERRIDE=<name>` before running make. If this environment variable is not set, make will load a default configuration for your platform.
     2.6  
     2.7 -BUILD_CONFIG=build-config
     2.8 -
     2.9 -include $(BUILD_CONFIG)/common.conf
    2.10 -ifdef PLATFORM_OVERRIDE
    2.11 -    include $(BUILD_CONFIG)/$(PLATFORM_OVERRIDE).conf
    2.12 +include build-config/common.conf
    2.13  # cross-compiling is currently not supported, but maybe you can hack something with `PLATFORM_OVERRIDE`
    2.14 -else ifeq ($(BUILD_ON),$(BUILD_FOR))
    2.15 -    include $(BUILD_CONFIG)/$(BUILD_ON).conf
    2.16 +ifeq ($(BUILD_ON),$(BUILD_FOR))
    2.17 +    include build-config/$(BUILD_ON).conf
    2.18  else
    2.19      $(error I don't know how to build for $(BUILD_FOR) on $(BUILD_ON))
    2.20  endif
    2.21 +ifdef PLATFORM_OVERRIDE
    2.22 +    include build-config/$(PLATFORM_OVERRIDE).conf
    2.23 +endif
     3.1 --- a/asn.1/Makefile	Sun Aug 13 16:19:56 2017 +0200
     3.2 +++ b/asn.1/Makefile	Mon Aug 14 02:26:09 2017 +0200
     3.3 @@ -16,7 +16,7 @@
     3.4  	rm -f converter-sample.c
     3.5  
     3.6  %.o: %.c %.h
     3.7 -	$(CC) $(CFLAGS) -I. -I$(ASN1C_INCLUDE) -c $< -o $@
     3.8 +	$(CC) $(CFLAGS) -I. $(ASN1C_INC) -c $< -o $@
     3.9  
    3.10  Sync-Protocols.c: pEp.asn1 devicegroup.asn1 protocols.asn1
    3.11  	$(ASN1C) -gen-PER -fincludes-quoted -fcompound-names -pdu=PEP.Message $^
     4.1 --- a/build-config/Darwin.conf	Sun Aug 13 16:19:56 2017 +0200
     4.2 +++ b/build-config/Darwin.conf	Mon Aug 14 02:26:09 2017 +0200
     4.3 @@ -8,8 +8,7 @@
     4.4  
     4.5  ######### C #########
     4.6  CC=clang -std=c99 -pthread
     4.7 -# FIXME I think -fPIC is not available in clang
     4.8 -CFLAGS= -fPIC -fstrict-aliasing -fcolor-diagnostics
     4.9 +CFLAGS=-fPIC -fstrict-aliasing -fcolor-diagnostics
    4.10  ifdef WARN
    4.11      CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
    4.12  else
    4.13 @@ -23,7 +22,7 @@
    4.14  
    4.15  ######### C++ #########
    4.16  CXX=clang -std=c++11
    4.17 -CXXFLAGS= -fcolor-diagnostics
    4.18 +CXXFLAGS=-fcolor-diagnostics -I../src -I../asn.1 $(ETPAN_INC)
    4.19  ifdef WARN
    4.20      CXXFLAGS+=
    4.21  else
    4.22 @@ -44,6 +43,7 @@
    4.23  ######### libetpan #########
    4.24  
    4.25  ######### OpenPGP #########
    4.26 +LIBGPGME=libgpgme.dylib
    4.27  
    4.28  ######### Engine internals #########
    4.29  
     5.1 --- a/build-config/Linux.conf	Sun Aug 13 16:19:56 2017 +0200
     5.2 +++ b/build-config/Linux.conf	Mon Aug 14 02:26:09 2017 +0200
     5.3 @@ -8,7 +8,7 @@
     5.4  
     5.5  ######### C #########
     5.6  CC=gcc -std=c99
     5.7 -CFLAGS= -fPIC -fstrict-aliasing -fdiagnostics-color=always
     5.8 +CFLAGS=-fPIC -fstrict-aliasing -fdiagnostics-color=always
     5.9  ifdef WARN
    5.10      CFLAGS+= -Wall -pedantic -Wstrict-aliasing=3
    5.11  else
    5.12 @@ -22,7 +22,7 @@
    5.13  
    5.14  ######### C++ #########
    5.15  CXX=g++ -std=gnu++11 -pthread
    5.16 -CXXFLAGS= -fdiagnostics-color=always
    5.17 +CXXFLAGS=-fdiagnostics-color=always -I../src -I../asn.1 $(ETPAN_INC)
    5.18  ifdef WARN
    5.19      CXXFLAGS+=
    5.20  else
    5.21 @@ -43,6 +43,7 @@
    5.22  ######### libetpan #########
    5.23  
    5.24  ######### OpenPGP #########
    5.25 +LIBGPGME=libgpgme.so.11
    5.26  
    5.27  ######### Engine internals #########
    5.28  
     6.1 --- a/build-config/common.conf	Sun Aug 13 16:19:56 2017 +0200
     6.2 +++ b/build-config/common.conf	Mon Aug 14 02:26:09 2017 +0200
     6.3 @@ -24,10 +24,15 @@
     6.4  
     6.5  ######### C++ #########
     6.6  #CXX This option is platform-specific
     6.7 +# CXXFLAGS is used for the tests only
     6.8  #CXXFLAGS This option is platform-specific
     6.9  
    6.10  ######### C and C++ #########
    6.11 -#LD=
    6.12 +# LD will be overwritten for test/Makefile
    6.13 +LD=$(CC)
    6.14 +# The following two variables will be appended to, you can thus not set them here to fixed value.
    6.15 +LDFLAGS=
    6.16 +LDLIBS=
    6.17  
    6.18  ######### YML2 #########
    6.19  YML2_PATH=$(HOME)/yml2
    6.20 @@ -35,35 +40,49 @@
    6.21  YML2_OPTS=--encoding=utf8
    6.22  
    6.23  ######### asn1c #########
    6.24 -# asn1c binary path
    6.25 +# asn1c binary
    6.26  ASN1C=asn1c
    6.27 -ASN1C_INCLUDE=/usr/include
    6.28 +# asn1c include search flag
    6.29 +ASN1C_INC=
    6.30 +#ASN1C_INC= -I$(HOME)/include
    6.31  
    6.32  ######### libetpan #########
    6.33 -# libetpan distribution path
    6.34 -ETPAN_IN=$(HOME)
    6.35 +# libetpan library search flag
    6.36 +ETPAN_LIB=-L$(PREFIX)/lib
    6.37 +# libetpan include search flag
    6.38 +ETPAN_INC=-I$(PREFIX)/include
    6.39  
    6.40  ######### OpenPGP #########
    6.41 -# Selects OpenPGP implementation. must be either `GPG` or `NETPGP`
    6.42 -OPENPGP=GPG
    6.43 -# Path of libGPGME binary
    6.44 -#LIBGPGME=/opt/local/lib/libgpgme.11.dylib
    6.45  # Path of GPG binary
    6.46  GPG_CMD=gpg
    6.47  ifneq ($(shell which gpg2),)
    6.48      GPG_CMD = gpg2
    6.49  endif
    6.50 +# Selects OpenPGP implementation. must be either `GPG` or `NETPGP`
    6.51 +OPENPGP=GPG
    6.52 +# Path of libGPGME binary
    6.53 +#LIBGPGME This option is platform-specific
    6.54 +# libGPGME library search flag
    6.55 +GPGME_LIB=
    6.56 +#GPGME_LIB=-L$(PREFIX)/lib
    6.57 +# libGPGME include search flag
    6.58 +GPGME_INC=
    6.59 +#GPGME_INC=-I$(PREFIX)/include
    6.60 +# NETPGP library search flag
    6.61 +NETPGP_LIB=
    6.62 +#NETPGP_LIB=-L$(PREFIX)/lib
    6.63 +# libGPGME include search flag
    6.64 +NETPGP_INC=
    6.65 +#NETPGP_INC=-I$(PREFIX)/include
    6.66  
    6.67  ######### Engine internals #########
    6.68  # C macros (not environment variables) that can be overridden:
    6.69  # DEFAULT_KEYSERVER - string with default keyserver
    6.70  # CRASHDUMP_DEFAULT_LINES - number of log lines to deliver for crashdumps
    6.71  # Example:
    6.72 -#    EXTRAMACROS= -DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
    6.73 -EXTRAMACROS=
    6.74 +#    EXTRA_MACROS= -DDEFAULT_KEYSERVER=\"default-server.org\" -DCRASHDUMP_DEFAULT_LINES=23
    6.75 +EXTRA_MACROS=
    6.76  
    6.77  ######### Misc #########
    6.78  # Maybe include these variables here. Check how they are used throughout the project before setting them here
    6.79 -#LDFLAGS=
    6.80 -#LDLIBS=
    6.81  #LLDB_BIN
     7.1 --- a/db/Makefile	Sun Aug 13 16:19:56 2017 +0200
     7.2 +++ b/db/Makefile	Mon Aug 14 02:26:09 2017 +0200
     7.3 @@ -1,4 +1,6 @@
     7.4 -# This file is under GNU General Public License 3.0
     7.5 +# Copyright 2017, pEp Security SA
     7.6 +# This file is part of pEpEngine
     7.7 +# This file may be used under the terms of the GNU General Public License version 3
     7.8  # see LICENSE.txt
     7.9  
    7.10  include ../Makefile.conf
    7.11 @@ -21,4 +23,4 @@
    7.12  
    7.13  .PHONY: clean
    7.14  clean:
    7.15 -	-rm -f system.db system.db~
    7.16 +	rm -f system.db system.db~
     8.1 --- a/src/Makefile	Sun Aug 13 16:19:56 2017 +0200
     8.2 +++ b/src/Makefile	Mon Aug 14 02:26:09 2017 +0200
     8.3 @@ -1,70 +1,57 @@
     8.4 +# Copyright 2017, pEp Security SA
     8.5 +# This file is part of pEpEngine
     8.6 +# This file may be used under the terms of the GNU General Public License version 3
     8.7 +# see LICENSE.txt
     8.8 +
     8.9  include ../Makefile.conf
    8.10  
    8.11 -LD?=$(CC)
    8.12 -
    8.13 -ETPAN_IN?=$(HOME)
    8.14 +CFLAGS+= $(ETPAN_INC) -I../asn.1 -DSYSTEM_DB=\"$(SYSTEM_DB)\" $(EXTRA_MACROS)
    8.15 +LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -shared
    8.16 +LDLIBS+= -lc -lasn1 -letpan 
    8.17  
    8.18  ifeq ($(BUILD_ON),Darwin)
    8.19 -ifeq ($(BUILD_FOR),Darwin)
    8.20 -
    8.21 -TARGET?=libpEpEngine.dylib
    8.22 -MACOSX_VERSION_MIN=10.6
    8.23 -LIBGPGME?=libgpgme.dylib
    8.24 -CC?=clang -std=c99 -pthread
    8.25 -CFLAGS?= -I$(ETPAN_IN)/include -I/opt/local/include -pedantic \
    8.26 -	-DSYSTEM_DB=\"$(SYSTEM_DB)\" -I../asn.1 $(EXTRAMACROS)
    8.27 -LDFLAGS?= -lc -shared -arch x86_64 \
    8.28 -	-L$(ETPAN_IN)/lib -L/usr/lib -L/opt/local/lib -letpan -lsqlite3 -L../asn.1 -lasn1 -lz -liconv
    8.29 -
    8.30 +    ifeq ($(BUILD_FOR),Darwin)
    8.31 +        #CFLAGS+= -I/opt/local/include
    8.32 +        #LDFLAGS+= -L/opt/local/lib
    8.33 +        LDLIBS+= -lsqlite3 -lz -liconv
    8.34 +    else
    8.35 +        $(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    8.36 +    endif
    8.37 +else ifeq ($(BUILD_ON),Linux)
    8.38 +    ifeq ($(BUILD_FOR),Linux)
    8.39 +        # FIXME Find out if SQLITE_THREADSAFE is needed for both platform.
    8.40 +        CFLAGS+= -DSQLITE_THREADSAFE=1 -D_GNU_SOURCE
    8.41 +        LDLIBS+= -ldl -luuid
    8.42 +    else
    8.43 +        $(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    8.44 +    endif
    8.45  else
    8.46 -$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    8.47 +    $(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    8.48  endif
    8.49  
    8.50 -else ifeq ($(BUILD_ON),Linux)
    8.51 -ifeq ($(BUILD_FOR),Linux)
    8.52  
    8.53 -TARGET=libpEpEngine.so
    8.54 -LIBGPGME?=libgpgme.so.11
    8.55 -CC=gcc -std=c99
    8.56 -CFLAGS?= -I$(ETPAN_IN)/include -fPIC -pedantic -DSYSTEM_DB=\"$(SYSTEM_DB)\" \
    8.57 -	-DSQLITE_THREADSAFE=1 -D_GNU_SOURCE -I../asn.1 $(EXTRAMACROS)
    8.58 -LDFLAGS?= -L$(ETPAN_IN)/lib -shared -lc -ldl -letpan -lpthread -L../asn.1 -lasn1 -luuid
    8.59 -
    8.60 +ifeq ($(OPENPGP),GPG)
    8.61 +    NO_SOURCE=pgp_netpgp.c
    8.62 +    CFLAGS+= -DUSE_GPG $(GPGME_INC) -DLIBGPGME=\"$(LIBGPGME)\"
    8.63 +    # FIXME Why was -lgpgme commented out?
    8.64 +    LDFLAGS+= $(GPGME_LIB)
    8.65 +else ifeq ($(OPENPGP),NETPGP)
    8.66 +    NO_SOURCE=pgp_gpg.c
    8.67 +    CFLAGS+= -DUSE_NETPGP $(NETGPG_INC)
    8.68 +    LDFLAGS+= $(NETGPG_LIB)
    8.69 +    LDLIBS+= -lnetpgp -lcurl
    8.70  else
    8.71 -$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    8.72 -endif
    8.73 -
    8.74 -else
    8.75 -$(error don't know how to make for $(BUILD_FOR) on $(BUILD_ON))
    8.76 -endif
    8.77 -
    8.78 -DEBUG?=NO
    8.79 -ifeq ("$(DEBUG)","NO")
    8.80 -    CFLAGS+= -DNDEBUG
    8.81 -endif
    8.82 -
    8.83 -OPENPGP?=GPG
    8.84 -ifeq ("$(OPENPGP)","GPG")
    8.85 -    NO_SOURCE=pgp_netpgp.c
    8.86 -    GPGME_IN?=$(HOME)
    8.87 -    CFLAGS+= -DUSE_GPG -I$(GPGME_IN)/include -DLIBGPGME=\"$(LIBGPGME)\"
    8.88 -    #LDFLAGS+= -L$(GPGME_IN)/lib -lgpgme
    8.89 -else ifeq ("$(OPENPGP)","NETPGP")
    8.90 -    NO_SOURCE=pgp_gpg.c
    8.91 -    NETPGP_IN?=$(HOME)
    8.92 -    CFLAGS+= -DUSE_NETPGP -I$(NETPGP_IN)/include
    8.93 -    LDFLAGS+= -L$(NETPGP_IN)/lib -lnetpgp -lcurl
    8.94 -else
    8.95 -	$(error Unknown OpenPGP library : $(OPENPGP))
    8.96 +    $(error Unknown OpenPGP library: $(OPENPGP))
    8.97  endif
    8.98  
    8.99  ALL_SOURCE=$(subst $(NO_SOURCE),,$(wildcard *.c))
   8.100 -
   8.101  DEPENDS=$(subst .c,.d,$(ALL_SOURCE))
   8.102  ALL_OBJECTS=$(subst .c,.o,$(ALL_SOURCE))
   8.103  
   8.104 +.PHONY: all
   8.105  all: $(TARGET)
   8.106  
   8.107 +# FIXME What is this?
   8.108  include Makefile.protocols
   8.109  
   8.110  %.d: %.c
   8.111 @@ -75,27 +62,27 @@
   8.112  
   8.113  -include $(DEPENDS)
   8.114  
   8.115 -#platform_windows.o: platform_windows.cpp
   8.116 -#	$(CXX) $(CXX_FLAGS) -o $@ -c $<
   8.117 +$(TARGET): libpEpEngine.a
   8.118 +	$(LD) $(ALL_OBJECTS) $(LDFLAGS) $(LDLIBS) -o $@
   8.119  
   8.120 -$(TARGET): libpEpEngine.a
   8.121 -	$(LD) $(ALL_OBJECTS) $(LDFLAGS) -o $@
   8.122 -
   8.123 +.PHONY: object
   8.124  objects: $(ALL_OBJECTS)
   8.125  
   8.126  libpEpEngine.a: $(ALL_OBJECTS)
   8.127 -	ar -r $@ $(ALL_OBJECTS)
   8.128 +	ar -rc $@ $^
   8.129  
   8.130  .PHONY: clean
   8.131 -
   8.132  clean:
   8.133  	rm -f *.d *.o *.a $(TARGET) *.dll *.so *.zip *.d.* *.def *~
   8.134  
   8.135 +.PHONY: install
   8.136  install: $(TARGET)
   8.137  	cp $< $(PREFIX)/lib/
   8.138  	mkdir -p $(PREFIX)/include/pEp
   8.139  	cp pEpEngine.h keymanagement.h message_api.h dynamic_api.h stringlist.h timestamp.h identity_list.h bloblist.h stringpair.h message.h mime.h cryptotech.h sync.h sync_fsm.h sync_app.h blacklist.h openpgp_compat.h $(PREFIX)/include/pEp/
   8.140  
   8.141 +.PHONY: uninstall
   8.142  uninstall:
   8.143  	rm -f $(PREFIX)/lib/$(TARGET)
   8.144 +	rm -rf $(PREFIX)/include/pEp
   8.145  
     9.1 --- a/sync/Makefile	Sun Aug 13 16:19:56 2017 +0200
     9.2 +++ b/sync/Makefile	Mon Aug 14 02:26:09 2017 +0200
     9.3 @@ -1,4 +1,6 @@
     9.4 -# This file is under GNU General Public License 3.0
     9.5 +# Copyright 2017, pEp Security SA
     9.6 +# This file is part of pEpEngine
     9.7 +# This file may be used under the terms of the GNU General Public License version 3
     9.8  # see LICENSE.txt
     9.9  
    9.10  include ../Makefile.conf
    10.1 --- a/test/Makefile	Sun Aug 13 16:19:56 2017 +0200
    10.2 +++ b/test/Makefile	Mon Aug 14 02:26:09 2017 +0200
    10.3 @@ -1,21 +1,18 @@
    10.4 -
    10.5 -# This file is under GNU General Public License 3.0
    10.6 +# Copyright 2017, pEp Security SA
    10.7 +# This file is part of pEpEngine
    10.8 +# This file may be used under the terms of the GNU General Public License version 3
    10.9  # see LICENSE.txt
   10.10  
   10.11 -HERE := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
   10.12 -LD?=$(CXX)
   10.13 +HERE:=$(CURDIR)
   10.14  
   10.15  include ../Makefile.conf
   10.16  
   10.17 -CC?=g++ -std=gnu++11 -pthread
   10.18 -CXX?=g++ -std=gnu++11 -pthread
   10.19 -LDFLAGS?=-L$(HOME)/lib
   10.20 -LDLIBS?=-letpan -lpEpEngine -lstdc++ -L../asn.1 -lasn1
   10.21 +LD=$(CXX)
   10.22 +LDFLAGS+= $(ETPAN_LIB) -L../asn.1
   10.23 +LDLIBS?=-letpan -lpEpEngine -lstdc++ -lasn1
   10.24  ifeq ($(BUILD_FOR),Linux)
   10.25  	LDLIBS+= -luuid
   10.26  endif
   10.27 -CXXFLAGS?=-std=c++11 -g -O0 -I../src -I../asn.1
   10.28 -# CXXFLAGS=-O3 -DNDEBUG
   10.29  
   10.30  ifeq ("$(OPENPGP)","NETPGP")
   10.31  	LDLIBS+= -lnetpgp