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