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################################################################################# 30# OpenCSD - master makefile for libraries and tests 31# 32# command line options 33# DEBUG=1 create a debug build 34# 35 36# Set project root - relative to build makefile 37ifeq ($(OCSD_ROOT),) 38OCSD_ROOT := $(shell echo $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | sed 's,/build/linux.*,,') 39export OCSD_ROOT 40endif 41 42# library names 43LIB_BASE_NAME=opencsd 44export LIB_BASE_NAME 45LIB_CAPI_NAME=$(LIB_BASE_NAME)_c_api 46export LIB_CAPI_NAME 47 48# source root directories 49export OCSD_LIB_ROOT=$(OCSD_ROOT)/lib 50 51export OCSD_INCLUDE=$(OCSD_ROOT)/include 52export OCSD_SOURCE=$(OCSD_ROOT)/source 53 54export OCSD_TESTS=$(OCSD_ROOT)/tests 55export LIB_UAPI_INC_DIR=opencsd 56 57# tools 58export MASTER_CC=$(CROSS_COMPILE)gcc 59export MASTER_CXX=$(CROSS_COMPILE)g++ 60export MASTER_LINKER=$(CROSS_COMPILE)g++ 61export MASTER_LIB=$(CROSS_COMPILE)ar 62export INSTALL=install 63 64 65# installation directory 66PREFIX ?=/usr 67LIB_PATH ?= lib 68INSTALL_LIB_DIR=$(PREFIX)/$(LIB_PATH) 69INSTALL_BIN_DIR=$(PREFIX)/bin 70export INSTALL_INCLUDE_DIR=$(PREFIX)/include/ 71 72# compile flags 73CFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -fPIC 74CXXFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -fPIC -std=c++11 75LDFLAGS += -Wl,-z,defs 76ARFLAGS ?= rcs 77 78# debug variant 79ifdef DEBUG 80CFLAGS += -g -O0 -DDEBUG 81CXXFLAGS += -g -O0 -DDEBUG 82BUILD_VARIANT=dbg 83else 84CFLAGS += -O2 -DNDEBUG 85CXXFLAGS += -O2 -DNDEBUG 86BUILD_VARIANT=rel 87endif 88 89# export build flags 90export CFLAGS 91export CXXFLAGS 92export LDFLAGS 93export ARFLAGS 94 95# target directories - fixed for default packaging build 96PLAT_DIR ?= builddir 97export PLAT_DIR 98export LIB_TARGET_DIR=$(OCSD_LIB_ROOT)/$(PLAT_DIR) 99export LIB_TEST_TARGET_DIR=$(OCSD_TESTS)/lib/$(PLAT_DIR) 100export BIN_TEST_TARGET_DIR=$(OCSD_TESTS)/bin/$(PLAT_DIR) 101 102# Fish version out of header file (converting from hex) 103getver:=printf "%d" $$(awk '/\#define VARNAME/ { print $$3 }' $(OCSD_ROOT)/include/opencsd/ocsd_if_version.h) 104export SO_MAJOR_VER := $(shell $(subst VARNAME,OCSD_VER_MAJOR,$(getver))) 105SO_MINOR_VER := $(shell $(subst VARNAME,OCSD_VER_MINOR,$(getver))) 106SO_PATCH_VER := $(shell $(subst VARNAME,OCSD_VER_PATCH,$(getver))) 107export SO_VER := $(SO_MAJOR_VER).$(SO_MINOR_VER).$(SO_PATCH_VER) 108 109 110########################################################### 111# build targets 112 113all: libs tests 114 115libs: $(LIB_BASE_NAME)_lib $(LIB_CAPI_NAME)_lib 116 117install: 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)/ 127 cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && make install_inc 128 $(INSTALL) --mode=755 $(BIN_TEST_TARGET_DIR)/trc_pkt_lister $(INSTALL_BIN_DIR)/ 129 130 131################################ 132# build OpenCSD trace decode library 133# 134$(LIB_BASE_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so 135 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 138 139# single command builds both .a and .so targets in sub-makefile 140$(LIB_BASE_NAME)_all: 141 mkdir -p $(LIB_TARGET_DIR) 142 cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE) 143 144################################ 145# build OpenCSD trace decode C API library 146# 147$(LIB_CAPI_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so 148 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 154 mkdir -p $(LIB_TARGET_DIR) 155 cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE) 156 157################################# 158# build tests 159 160.PHONY: tests 161tests: libs 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) 166 cd $(OCSD_ROOT)/tests/build/linux/mem_buffer_eg && $(MAKE) 167 168# 169# build docs 170.PHONY: docs 171docs: 172 (cd $(OCSD_ROOT)/docs; doxygen doxygen_config.dox) 173 174 175############################################################# 176# clean targets 177# 178clean: clean_libs clean_tests clean_docs 179 180.PHONY: clean_libs clean_tests clean_docs clean_install 181 182clean_libs: 183 cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE) clean 184 cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE) clean 185 186clean_tests: 187 cd $(OCSD_ROOT)/tests/build/linux/echo_test_dcd_lib && $(MAKE) clean 188 cd $(OCSD_ROOT)/tests/build/linux/snapshot_parser_lib && $(MAKE) clean 189 cd $(OCSD_ROOT)/tests/build/linux/trc_pkt_lister && $(MAKE) clean 190 cd $(OCSD_ROOT)/tests/build/linux/c_api_pkt_print_test && $(MAKE) clean 191 cd $(OCSD_ROOT)/tests/build/linux/mem_buffer_eg && $(MAKE) clean 192 -rmdir $(OCSD_TESTS)/lib 193 194clean_docs: 195 -rm -r $(OCSD_ROOT)/docs/html 196 197clean_install: 198 -rm $(INSTALL_LIB_DIR)/lib$(LIB_BASE_NAME).* 199 -rm $(INSTALL_LIB_DIR)/lib$(LIB_CAPI_NAME).* 200 -rm -r $(INSTALL_INCLUDE_DIR)/$(LIB_UAPI_INC_DIR) 201