Makefile
author Damiano Boppart <damiano.boppart@pep.security>
Tue, 18 Dec 2018 14:06:13 +0100
branchmake-cleanup
changeset 91 ee5ef7f04461
parent 86 8773b3febc6f
child 93 a6a94d0651bc
permissions -rw-r--r--
Fix clean target, and library search paths
     1 # Copyright 2018, pEp Foundation
     2 # This file is part of lib pEp Adapter
     3 # This file may be used under the terms of the GNU General Public License version 3
     4 # see LICENSE.txt
     5 
     6 include Makefile.conf
     7 
     8 ifneq ($(wildcard local.conf),)
     9     $(info ================================================)
    10     $(info Overrides in \`local.conf\` are used.)
    11     $(info ================================================)
    12 endif
    13 
    14 ifdef BUILD_CONFIG
    15     $(info ================================================)
    16     $(info Overrides in \`$(BUILD_CONFIG)\` are used.)
    17     $(info ================================================)
    18 endif
    19 
    20 SOURCE=$(wildcard *.cc)
    21 HEADERS=$(wildcard *.hh *.hxx)
    22 OBJECTS=$(subst .cc,.o,$(SOURCE))
    23 WITHOUT_TESTS=$(patsubst test%.o,,$(OBJECTS))
    24 TARGET=libpEpAdapter.a
    25 
    26 EXTRA_LIB_PATHS=.:
    27 ifdef ENGINE_LIB
    28 	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ENGINE_LIB)):
    29 endif
    30 
    31 # Remove trailing ':'
    32 EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
    33 
    34 ifeq ($(BUILD_FOR),Darwin)
    35     LIBPATH=DYLD_LIBRARY_PATH
    36 else
    37     LIBPATH=LD_LIBRARY_PATH
    38 endif
    39 
    40 TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS)
    41 
    42 
    43 .PHONY: all
    44 all: $(TARGET)
    45 
    46 # Rule copied from make's built-in rules
    47 %.o: %.cc %.hh
    48 	$(COMPILE.cc) $(OUTPUT_OPTION) $<
    49 
    50 $(TARGET): $(WITHOUT_TESTS)
    51 	ar -rc $@ $^
    52 
    53 .PHONY: clean
    54 clean:
    55 	rm -f $(TARGET) $(OBJECTS) *.a test_adapter test_library lib
    56 	rm -rf test_adapter.dSYM
    57 	rm -rf test_library.dSYM
    58 
    59 .PHONY: distclean
    60 distclean: clean
    61 	rm -Rf .gnupg .pEp_management*
    62 
    63 # $$(pwd) will return the incorrect directory, if make is run with `make -C ...`.
    64 .PHONY: test
    65 test: test_adapter test_library
    66 	 $(TEST_CMD_PFX) HOME=$$(pwd) ./test_adapter
    67 
    68 test_%: test_%.o $(TARGET)
    69 
    70 .PHONY: install
    71 install: $(TARGET)
    72 	-mkdir -p $(PREFIX)/include/pEp
    73 	cp $(HEADERS) $(PREFIX)/include/pEp/
    74 	cp $(TARGET) $(PREFIX)/lib/
    75 
    76 .PHONY: uninstall
    77 uninstall:
    78 	cd $(PREFIX)/include/pEp && rm -f $(HEADERS)
    79 	cd $(PREFIX)/lib && rm -f $(TARGET)