blob: 2cdeae0cb12dea70cceba165d0d68ca4c40d402d [file] [log] [blame]
mleach228a5e02015-07-27 17:38:00 +01001########################################################
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#################################################################################
mleach38da0c72015-12-07 10:08:56 +000030# OpenCSD - master makefile for libraries and tests
mleach228a5e02015-07-27 17:38:00 +010031#
32# command line options
33# DEBUG=1 create a debug build
Mike Leach3a49f9c2017-09-07 17:08:49 +010034#
mleach228a5e02015-07-27 17:38:00 +010035
Mike Leach4688ff32018-04-10 12:02:42 +010036# Set project root - relative to build makefile
mleach48d83a62016-03-18 15:38:08 +000037ifeq ($(OCSD_ROOT),)
Mike Leach4688ff32018-04-10 12:02:42 +010038OCSD_ROOT := $(shell echo $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | sed 's,/build/linux.*,,')
mleach48d83a62016-03-18 15:38:08 +000039export OCSD_ROOT
mleach228a5e02015-07-27 17:38:00 +010040endif
41
mleach38da0c72015-12-07 10:08:56 +000042# library names
Mike Leach5583b702017-12-14 14:21:18 +000043LIB_BASE_NAME=opencsd
mleach38da0c72015-12-07 10:08:56 +000044export LIB_BASE_NAME
45LIB_CAPI_NAME=$(LIB_BASE_NAME)_c_api
46export LIB_CAPI_NAME
47
mleachbdcc5e82015-08-03 18:03:04 +010048# source root directories
mleach48d83a62016-03-18 15:38:08 +000049export OCSD_LIB_ROOT=$(OCSD_ROOT)/lib
mleach228a5e02015-07-27 17:38:00 +010050
mleach48d83a62016-03-18 15:38:08 +000051export OCSD_INCLUDE=$(OCSD_ROOT)/include
52export OCSD_SOURCE=$(OCSD_ROOT)/source
mleach228a5e02015-07-27 17:38:00 +010053
mleach48d83a62016-03-18 15:38:08 +000054export OCSD_TESTS=$(OCSD_ROOT)/tests
Mathieu Poirier2b898fe2017-12-11 13:39:56 -070055export LIB_UAPI_INC_DIR=opencsd
56
mleach228a5e02015-07-27 17:38:00 +010057# tools
Chunyan Zhang61429952017-01-11 21:03:21 +080058export MASTER_CC=$(CROSS_COMPILE)gcc
Mike Leach4688ff32018-04-10 12:02:42 +010059export MASTER_CXX=$(CROSS_COMPILE)g++
Chunyan Zhang61429952017-01-11 21:03:21 +080060export MASTER_LINKER=$(CROSS_COMPILE)g++
61export MASTER_LIB=$(CROSS_COMPILE)ar
Robert Walkerbd265052018-01-25 14:32:44 +000062export INSTALL=install
Mathieu Poirier2b898fe2017-12-11 13:39:56 -070063
Mike Leach4688ff32018-04-10 12:02:42 +010064
Mathieu Poirier2b898fe2017-12-11 13:39:56 -070065# installation directory
Mike Leach4688ff32018-04-10 12:02:42 +010066PREFIX ?=/usr
67LIB_PATH ?= lib
68INSTALL_LIB_DIR=$(PREFIX)/$(LIB_PATH)
69INSTALL_BIN_DIR=$(PREFIX)/bin
70export INSTALL_INCLUDE_DIR=$(PREFIX)/include/
mleach228a5e02015-07-27 17:38:00 +010071
72# compile flags
Mike Leach4688ff32018-04-10 12:02:42 +010073CFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -fpic
74CXXFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -fpic -std=c++11
75LDFLAGS += -Wl,-z,defs
76ARFLAGS ?= rcs
mleach228a5e02015-07-27 17:38:00 +010077
mleachbdcc5e82015-08-03 18:03:04 +010078# debug variant
mleach228a5e02015-07-27 17:38:00 +010079ifdef DEBUG
Mike Leach4688ff32018-04-10 12:02:42 +010080CFLAGS += -g -O0 -DDEBUG
81CXXFLAGS += -g -O0 -DDEBUG
mleach228a5e02015-07-27 17:38:00 +010082BUILD_VARIANT=dbg
83else
Mike Leach4688ff32018-04-10 12:02:42 +010084CFLAGS += -g -O2 -DNDEBUG
85CXXFLAGS += -g -O2 -DNDEBUG
mleach228a5e02015-07-27 17:38:00 +010086BUILD_VARIANT=rel
87endif
88
mleachbdcc5e82015-08-03 18:03:04 +010089# export build flags
Mike Leach4688ff32018-04-10 12:02:42 +010090export CFLAGS
91export CXXFLAGS
92export LDFLAGS
93export ARFLAGS
mleach228a5e02015-07-27 17:38:00 +010094
Mike Leach4688ff32018-04-10 12:02:42 +010095# target directories - fixed for default packaging build
96PLAT_DIR ?= builddir
97export PLAT_DIR
mleach48d83a62016-03-18 15:38:08 +000098export 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)
mleach228a5e02015-07-27 17:38:00 +0100101
Mike Leach4688ff32018-04-10 12:02:42 +0100102# Fish version out of header file (converting from hex)
Mike Leachb9f6f722018-10-03 11:07:36 +0100103getver:=printf "%d" $$(awk '/\#define VARNAME/ { print $$3 }' $(OCSD_ROOT)/include/opencsd/ocsd_if_version.h)
Mike Leach4688ff32018-04-10 12:02:42 +0100104export 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
mleach228a5e02015-07-27 17:38:00 +0100110###########################################################
111# build targets
112
113all: libs tests
114
Mike Leach9a47a922016-12-16 15:00:34 +0000115libs: $(LIB_BASE_NAME)_lib $(LIB_CAPI_NAME)_lib
mleach228a5e02015-07-27 17:38:00 +0100116
Mike Leach4688ff32018-04-10 12:02:42 +0100117install: 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 Poirier2b898fe2017-12-11 13:39:56 -0700127 cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && make install_inc
Mike Leach4688ff32018-04-10 12:02:42 +0100128 $(INSTALL) --mode=755 $(BIN_TEST_TARGET_DIR)/trc_pkt_lister $(INSTALL_BIN_DIR)/
129
Mathieu Poirier2b898fe2017-12-11 13:39:56 -0700130
mleachbdcc5e82015-08-03 18:03:04 +0100131################################
Mike Leach9a47a922016-12-16 15:00:34 +0000132# build OpenCSD trace decode library
mleachbdcc5e82015-08-03 18:03:04 +0100133#
Mike Leach9a47a922016-12-16 15:00:34 +0000134$(LIB_BASE_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so
mleach228a5e02015-07-27 17:38:00 +0100135
Mike Leach9a47a922016-12-16 15:00:34 +0000136$(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
mleach38da0c72015-12-07 10:08:56 +0000138
Mike Leach9a47a922016-12-16 15:00:34 +0000139# single command builds both .a and .so targets in sub-makefile
140$(LIB_BASE_NAME)_all:
mleach228a5e02015-07-27 17:38:00 +0100141 mkdir -p $(LIB_TARGET_DIR)
Paulo Neves532b85d2018-10-18 13:31:49 +0200142 cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE)
mleach228a5e02015-07-27 17:38:00 +0100143
mleachbdcc5e82015-08-03 18:03:04 +0100144################################
Mike Leach9a47a922016-12-16 15:00:34 +0000145# build OpenCSD trace decode C API library
mleachbdcc5e82015-08-03 18:03:04 +0100146#
Mike Leach9a47a922016-12-16 15:00:34 +0000147$(LIB_CAPI_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so
mleachbdcc5e82015-08-03 18:03:04 +0100148
Mike Leach9a47a922016-12-16 15:00:34 +0000149$(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
mleach38da0c72015-12-07 10:08:56 +0000154 mkdir -p $(LIB_TARGET_DIR)
Paulo Neves532b85d2018-10-18 13:31:49 +0200155 cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE)
mleach38da0c72015-12-07 10:08:56 +0000156
mleachbdcc5e82015-08-03 18:03:04 +0100157#################################
158# build tests
mleach228a5e02015-07-27 17:38:00 +0100159
mleachbdcc5e82015-08-03 18:03:04 +0100160.PHONY: tests
161tests: libs
Paulo Neves532b85d2018-10-18 13:31:49 +0200162 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)
mleachbdcc5e82015-08-03 18:03:04 +0100166
Mike Leach4688ff32018-04-10 12:02:42 +0100167#
168# build docs
169.PHONY: docs
170docs:
171 (cd $(OCSD_ROOT)/docs; doxygen doxygen_config.dox)
172
173
mleachbdcc5e82015-08-03 18:03:04 +0100174#############################################################
175# clean targets
176#
Mike Leach4688ff32018-04-10 12:02:42 +0100177clean: clean_libs clean_tests clean_docs
mleachbdcc5e82015-08-03 18:03:04 +0100178
Mike Leach4688ff32018-04-10 12:02:42 +0100179.PHONY: clean_libs clean_tests clean_docs clean_install
mleachbdcc5e82015-08-03 18:03:04 +0100180
181clean_libs:
Paulo Neves532b85d2018-10-18 13:31:49 +0200182 cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE) clean
183 cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE) clean
mleachbdcc5e82015-08-03 18:03:04 +0100184
185clean_tests:
Paulo Neves532b85d2018-10-18 13:31:49 +0200186 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 Leach4688ff32018-04-10 12:02:42 +0100190 -rmdir $(OCSD_TESTS)/lib
191
192clean_docs:
193 -rm -r $(OCSD_ROOT)/docs/html
Mathieu Poirier2b898fe2017-12-11 13:39:56 -0700194
195clean_install:
Mike Leach4688ff32018-04-10 12:02:42 +0100196 -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)