mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 1 | ######################################################## |
| 2 | # Copyright 2015 ARM Limited. All rights reserved. |
| 3 | # |
| 4 | # Redistribution and use in source and binary forms, with or without modification, |
| 5 | # are permitted provided that the following conditions are met: |
| 6 | # |
| 7 | # 1. Redistributions of source code must retain the above copyright notice, |
| 8 | # this list of conditions and the following disclaimer. |
| 9 | # |
| 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | # this list of conditions and the following disclaimer in the documentation |
| 12 | # and/or other materials provided with the distribution. |
| 13 | # |
| 14 | # 3. Neither the name of the copyright holder nor the names of its contributors |
| 15 | # may be used to endorse or promote products derived from this software without |
| 16 | # specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND |
| 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 22 | # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | # |
| 29 | ################################################################################# |
mleach | 38da0c7 | 2015-12-07 10:08:56 +0000 | [diff] [blame] | 30 | # OpenCSD - master makefile for libraries and tests |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 31 | # |
| 32 | # command line options |
| 33 | # DEBUG=1 create a debug build |
Mike Leach | 3a49f9c | 2017-09-07 17:08:49 +0100 | [diff] [blame] | 34 | # |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 35 | |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 36 | # Set project root - relative to build makefile |
mleach | 48d83a6 | 2016-03-18 15:38:08 +0000 | [diff] [blame] | 37 | ifeq ($(OCSD_ROOT),) |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 38 | OCSD_ROOT := $(shell echo $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | sed 's,/build/linux.*,,') |
mleach | 48d83a6 | 2016-03-18 15:38:08 +0000 | [diff] [blame] | 39 | export OCSD_ROOT |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 40 | endif |
| 41 | |
mleach | 38da0c7 | 2015-12-07 10:08:56 +0000 | [diff] [blame] | 42 | # library names |
Mike Leach | 5583b70 | 2017-12-14 14:21:18 +0000 | [diff] [blame] | 43 | LIB_BASE_NAME=opencsd |
mleach | 38da0c7 | 2015-12-07 10:08:56 +0000 | [diff] [blame] | 44 | export LIB_BASE_NAME |
| 45 | LIB_CAPI_NAME=$(LIB_BASE_NAME)_c_api |
| 46 | export LIB_CAPI_NAME |
| 47 | |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 48 | # source root directories |
mleach | 48d83a6 | 2016-03-18 15:38:08 +0000 | [diff] [blame] | 49 | export OCSD_LIB_ROOT=$(OCSD_ROOT)/lib |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 50 | |
mleach | 48d83a6 | 2016-03-18 15:38:08 +0000 | [diff] [blame] | 51 | export OCSD_INCLUDE=$(OCSD_ROOT)/include |
| 52 | export OCSD_SOURCE=$(OCSD_ROOT)/source |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 53 | |
mleach | 48d83a6 | 2016-03-18 15:38:08 +0000 | [diff] [blame] | 54 | export OCSD_TESTS=$(OCSD_ROOT)/tests |
Mathieu Poirier | 2b898fe | 2017-12-11 13:39:56 -0700 | [diff] [blame] | 55 | export LIB_UAPI_INC_DIR=opencsd |
| 56 | |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 57 | # tools |
Chunyan Zhang | 6142995 | 2017-01-11 21:03:21 +0800 | [diff] [blame] | 58 | export MASTER_CC=$(CROSS_COMPILE)gcc |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 59 | export MASTER_CXX=$(CROSS_COMPILE)g++ |
Chunyan Zhang | 6142995 | 2017-01-11 21:03:21 +0800 | [diff] [blame] | 60 | export MASTER_LINKER=$(CROSS_COMPILE)g++ |
| 61 | export MASTER_LIB=$(CROSS_COMPILE)ar |
Robert Walker | bd26505 | 2018-01-25 14:32:44 +0000 | [diff] [blame] | 62 | export INSTALL=install |
Mathieu Poirier | 2b898fe | 2017-12-11 13:39:56 -0700 | [diff] [blame] | 63 | |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 64 | |
Mathieu Poirier | 2b898fe | 2017-12-11 13:39:56 -0700 | [diff] [blame] | 65 | # installation directory |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 66 | PREFIX ?=/usr |
| 67 | LIB_PATH ?= lib |
| 68 | INSTALL_LIB_DIR=$(PREFIX)/$(LIB_PATH) |
| 69 | INSTALL_BIN_DIR=$(PREFIX)/bin |
| 70 | export INSTALL_INCLUDE_DIR=$(PREFIX)/include/ |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 71 | |
| 72 | # compile flags |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 73 | CFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -fpic |
| 74 | CXXFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -fpic -std=c++11 |
| 75 | LDFLAGS += -Wl,-z,defs |
| 76 | ARFLAGS ?= rcs |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 77 | |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 78 | # debug variant |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 79 | ifdef DEBUG |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 80 | CFLAGS += -g -O0 -DDEBUG |
| 81 | CXXFLAGS += -g -O0 -DDEBUG |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 82 | BUILD_VARIANT=dbg |
| 83 | else |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 84 | CFLAGS += -g -O2 -DNDEBUG |
| 85 | CXXFLAGS += -g -O2 -DNDEBUG |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 86 | BUILD_VARIANT=rel |
| 87 | endif |
| 88 | |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 89 | # export build flags |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 90 | export CFLAGS |
| 91 | export CXXFLAGS |
| 92 | export LDFLAGS |
| 93 | export ARFLAGS |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 94 | |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 95 | # target directories - fixed for default packaging build |
| 96 | PLAT_DIR ?= builddir |
| 97 | export PLAT_DIR |
mleach | 48d83a6 | 2016-03-18 15:38:08 +0000 | [diff] [blame] | 98 | export LIB_TARGET_DIR=$(OCSD_LIB_ROOT)/$(PLAT_DIR) |
| 99 | export LIB_TEST_TARGET_DIR=$(OCSD_TESTS)/lib/$(PLAT_DIR) |
| 100 | export BIN_TEST_TARGET_DIR=$(OCSD_TESTS)/bin/$(PLAT_DIR) |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 101 | |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 102 | # Fish version out of header file (converting from hex) |
Mike Leach | b9f6f72 | 2018-10-03 11:07:36 +0100 | [diff] [blame] | 103 | getver:=printf "%d" $$(awk '/\#define VARNAME/ { print $$3 }' $(OCSD_ROOT)/include/opencsd/ocsd_if_version.h) |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 104 | export SO_MAJOR_VER := $(shell $(subst VARNAME,OCSD_VER_MAJOR,$(getver))) |
| 105 | SO_MINOR_VER := $(shell $(subst VARNAME,OCSD_VER_MINOR,$(getver))) |
| 106 | SO_PATCH_VER := $(shell $(subst VARNAME,OCSD_VER_PATCH,$(getver))) |
| 107 | export SO_VER := $(SO_MAJOR_VER).$(SO_MINOR_VER).$(SO_PATCH_VER) |
| 108 | |
| 109 | |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 110 | ########################################################### |
| 111 | # build targets |
| 112 | |
| 113 | all: libs tests |
| 114 | |
Mike Leach | 9a47a92 | 2016-12-16 15:00:34 +0000 | [diff] [blame] | 115 | libs: $(LIB_BASE_NAME)_lib $(LIB_CAPI_NAME)_lib |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 116 | |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 117 | install: libs tests |
| 118 | mkdir -p $(INSTALL_LIB_DIR) $(INSTALL_INCLUDE_DIR) $(INSTALL_BIN_DIR) |
| 119 | cp -d $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so $(INSTALL_LIB_DIR)/ |
| 120 | cp -d $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so.$(SO_MAJOR_VER) $(INSTALL_LIB_DIR)/ |
| 121 | $(INSTALL) --mode=644 $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so.$(SO_VER) $(INSTALL_LIB_DIR)/ |
| 122 | cp -d $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so $(INSTALL_LIB_DIR)/ |
| 123 | cp -d $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so.$(SO_MAJOR_VER) $(INSTALL_LIB_DIR)/ |
| 124 | $(INSTALL) --mode=644 $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so.$(SO_VER) $(INSTALL_LIB_DIR)/ |
| 125 | $(INSTALL) --mode=644 $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a $(INSTALL_LIB_DIR)/ |
| 126 | $(INSTALL) --mode=644 $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a $(INSTALL_LIB_DIR)/ |
Mathieu Poirier | 2b898fe | 2017-12-11 13:39:56 -0700 | [diff] [blame] | 127 | cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && make install_inc |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 128 | $(INSTALL) --mode=755 $(BIN_TEST_TARGET_DIR)/trc_pkt_lister $(INSTALL_BIN_DIR)/ |
| 129 | |
Mathieu Poirier | 2b898fe | 2017-12-11 13:39:56 -0700 | [diff] [blame] | 130 | |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 131 | ################################ |
Mike Leach | 9a47a92 | 2016-12-16 15:00:34 +0000 | [diff] [blame] | 132 | # build OpenCSD trace decode library |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 133 | # |
Mike Leach | 9a47a92 | 2016-12-16 15:00:34 +0000 | [diff] [blame] | 134 | $(LIB_BASE_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 135 | |
Mike Leach | 9a47a92 | 2016-12-16 15:00:34 +0000 | [diff] [blame] | 136 | $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so: $(LIB_BASE_NAME)_all |
| 137 | $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a: $(LIB_BASE_NAME)_all |
mleach | 38da0c7 | 2015-12-07 10:08:56 +0000 | [diff] [blame] | 138 | |
Mike Leach | 9a47a92 | 2016-12-16 15:00:34 +0000 | [diff] [blame] | 139 | # single command builds both .a and .so targets in sub-makefile |
| 140 | $(LIB_BASE_NAME)_all: |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 141 | mkdir -p $(LIB_TARGET_DIR) |
Paulo Neves | 532b85d | 2018-10-18 13:31:49 +0200 | [diff] [blame^] | 142 | cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE) |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 143 | |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 144 | ################################ |
Mike Leach | 9a47a92 | 2016-12-16 15:00:34 +0000 | [diff] [blame] | 145 | # build OpenCSD trace decode C API library |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 146 | # |
Mike Leach | 9a47a92 | 2016-12-16 15:00:34 +0000 | [diff] [blame] | 147 | $(LIB_CAPI_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 148 | |
Mike Leach | 9a47a92 | 2016-12-16 15:00:34 +0000 | [diff] [blame] | 149 | $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so: $(LIB_CAPI_NAME)_all |
| 150 | $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a: $(LIB_CAPI_NAME)_all |
| 151 | |
| 152 | # single command builds both .a and .so targets in sub-makefile |
| 153 | $(LIB_CAPI_NAME)_all: $(LIB_BASE_NAME)_lib |
mleach | 38da0c7 | 2015-12-07 10:08:56 +0000 | [diff] [blame] | 154 | mkdir -p $(LIB_TARGET_DIR) |
Paulo Neves | 532b85d | 2018-10-18 13:31:49 +0200 | [diff] [blame^] | 155 | cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE) |
mleach | 38da0c7 | 2015-12-07 10:08:56 +0000 | [diff] [blame] | 156 | |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 157 | ################################# |
| 158 | # build tests |
mleach | 228a5e0 | 2015-07-27 17:38:00 +0100 | [diff] [blame] | 159 | |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 160 | .PHONY: tests |
| 161 | tests: libs |
Paulo Neves | 532b85d | 2018-10-18 13:31:49 +0200 | [diff] [blame^] | 162 | cd $(OCSD_ROOT)/tests/build/linux/echo_test_dcd_lib && $(MAKE) |
| 163 | cd $(OCSD_ROOT)/tests/build/linux/snapshot_parser_lib && $(MAKE) |
| 164 | cd $(OCSD_ROOT)/tests/build/linux/trc_pkt_lister && $(MAKE) |
| 165 | cd $(OCSD_ROOT)/tests/build/linux/c_api_pkt_print_test && $(MAKE) |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 166 | |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 167 | # |
| 168 | # build docs |
| 169 | .PHONY: docs |
| 170 | docs: |
| 171 | (cd $(OCSD_ROOT)/docs; doxygen doxygen_config.dox) |
| 172 | |
| 173 | |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 174 | ############################################################# |
| 175 | # clean targets |
| 176 | # |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 177 | clean: clean_libs clean_tests clean_docs |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 178 | |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 179 | .PHONY: clean_libs clean_tests clean_docs clean_install |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 180 | |
| 181 | clean_libs: |
Paulo Neves | 532b85d | 2018-10-18 13:31:49 +0200 | [diff] [blame^] | 182 | cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE) clean |
| 183 | cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE) clean |
mleach | bdcc5e8 | 2015-08-03 18:03:04 +0100 | [diff] [blame] | 184 | |
| 185 | clean_tests: |
Paulo Neves | 532b85d | 2018-10-18 13:31:49 +0200 | [diff] [blame^] | 186 | cd $(OCSD_ROOT)/tests/build/linux/echo_test_dcd_lib && $(MAKE) clean |
| 187 | cd $(OCSD_ROOT)/tests/build/linux/snapshot_parser_lib && $(MAKE) clean |
| 188 | cd $(OCSD_ROOT)/tests/build/linux/trc_pkt_lister && $(MAKE) clean |
| 189 | cd $(OCSD_ROOT)/tests/build/linux/c_api_pkt_print_test && $(MAKE) clean |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 190 | -rmdir $(OCSD_TESTS)/lib |
| 191 | |
| 192 | clean_docs: |
| 193 | -rm -r $(OCSD_ROOT)/docs/html |
Mathieu Poirier | 2b898fe | 2017-12-11 13:39:56 -0700 | [diff] [blame] | 194 | |
| 195 | clean_install: |
Mike Leach | 4688ff3 | 2018-04-10 12:02:42 +0100 | [diff] [blame] | 196 | -rm $(INSTALL_LIB_DIR)/lib$(LIB_BASE_NAME).* |
| 197 | -rm $(INSTALL_LIB_DIR)/lib$(LIB_CAPI_NAME).* |
| 198 | -rm -r $(INSTALL_INCLUDE_DIR)/$(LIB_UAPI_INC_DIR) |