• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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=$(DESTDIR)$(PREFIX)/$(LIB_PATH)
69INSTALL_BIN_DIR=$(DESTDIR)$(PREFIX)/bin
70export INSTALL_INCLUDE_DIR=$(DESTDIR)$(PREFIX)/include/
71INSTALL_MAN_DIR=$(DESTDIR)$(PREFIX)/share/man/man1
72
73# compile flags
74CFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -Wlogical-op -fPIC
75CXXFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -Wlogical-op -fPIC -std=c++11
76LDFLAGS += -Wl,-z,defs
77ARFLAGS ?= rcs
78
79# debug variant
80ifdef DEBUG
81CFLAGS += -g -O0 -DDEBUG
82CXXFLAGS += -g -O0 -DDEBUG
83BUILD_VARIANT=dbg
84else
85CFLAGS += -O2 -DNDEBUG
86CXXFLAGS += -O2 -DNDEBUG
87BUILD_VARIANT=rel
88endif
89
90# export build flags
91export CFLAGS
92export CXXFLAGS
93export LDFLAGS
94export ARFLAGS
95
96# target directories - fixed for default packaging build
97PLAT_DIR ?= builddir
98export PLAT_DIR
99export LIB_TARGET_DIR=$(OCSD_LIB_ROOT)/$(PLAT_DIR)
100export LIB_TEST_TARGET_DIR=$(OCSD_TESTS)/lib/$(PLAT_DIR)
101export BIN_TEST_TARGET_DIR=$(OCSD_TESTS)/bin/$(PLAT_DIR)
102
103# Fish version out of header file (converting from hex)
104getver:=printf "%d" $$(awk '/\#define VARNAME/ { print $$3 }' $(OCSD_ROOT)/include/opencsd/ocsd_if_version.h)
105export SO_MAJOR_VER := $(shell $(subst VARNAME,OCSD_VER_MAJOR,$(getver)))
106SO_MINOR_VER := $(shell $(subst VARNAME,OCSD_VER_MINOR,$(getver)))
107SO_PATCH_VER := $(shell $(subst VARNAME,OCSD_VER_PATCH,$(getver)))
108export SO_VER := $(SO_MAJOR_VER).$(SO_MINOR_VER).$(SO_PATCH_VER)
109
110
111###########################################################
112# build targets
113
114all: libs tests
115
116libs: $(LIB_BASE_NAME)_lib  $(LIB_CAPI_NAME)_lib
117
118DEF_SO_PERM ?= 644
119
120install: libs tests
121	mkdir -p $(INSTALL_LIB_DIR) $(INSTALL_INCLUDE_DIR) $(INSTALL_BIN_DIR)
122	cp -d $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so $(INSTALL_LIB_DIR)/
123	cp -d $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so.$(SO_MAJOR_VER) $(INSTALL_LIB_DIR)/
124	$(INSTALL) --mode=$(DEF_SO_PERM) $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so.$(SO_VER) $(INSTALL_LIB_DIR)/
125	cp -d $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so $(INSTALL_LIB_DIR)/
126	cp -d $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so.$(SO_MAJOR_VER) $(INSTALL_LIB_DIR)/
127	$(INSTALL) --mode=$(DEF_SO_PERM) $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so.$(SO_VER) $(INSTALL_LIB_DIR)/
128ifndef DISABLE_STATIC
129	$(INSTALL) --mode=644 $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a $(INSTALL_LIB_DIR)/
130	$(INSTALL) --mode=644 $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a $(INSTALL_LIB_DIR)/
131endif
132	cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && make install_inc
133	$(INSTALL) --mode=755 $(BIN_TEST_TARGET_DIR)/trc_pkt_lister $(INSTALL_BIN_DIR)/
134
135install_man:
136	$(INSTALL) --mode=644 $(OCSD_ROOT)/docs/man/trc_pkt_lister.1 $(INSTALL_MAN_DIR)/
137
138
139################################
140# build  OpenCSD trace decode library
141#
142$(LIB_BASE_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so
143
144$(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so: $(LIB_BASE_NAME)_all
145$(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a: $(LIB_BASE_NAME)_all
146
147# single command builds both .a and .so targets in sub-makefile
148$(LIB_BASE_NAME)_all:
149	mkdir -p $(LIB_TARGET_DIR)
150	cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE)
151
152################################
153# build OpenCSD trace decode C API library
154#
155$(LIB_CAPI_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so
156
157$(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so: $(LIB_CAPI_NAME)_all
158$(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a:  $(LIB_CAPI_NAME)_all
159
160# single command builds both .a and .so targets in sub-makefile
161$(LIB_CAPI_NAME)_all:  $(LIB_BASE_NAME)_lib
162	mkdir -p $(LIB_TARGET_DIR)
163	cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE)
164
165#################################
166# build tests
167
168.PHONY: tests
169tests: libs
170	cd $(OCSD_ROOT)/tests/build/linux/echo_test_dcd_lib && $(MAKE)
171	cd $(OCSD_ROOT)/tests/build/linux/snapshot_parser_lib && $(MAKE)
172	cd $(OCSD_ROOT)/tests/build/linux/trc_pkt_lister && $(MAKE)
173	cd $(OCSD_ROOT)/tests/build/linux/c_api_pkt_print_test && $(MAKE)
174	cd $(OCSD_ROOT)/tests/build/linux/mem_buffer_eg && $(MAKE)
175
176#
177# build docs
178.PHONY: docs
179docs:
180	(cd $(OCSD_ROOT)/docs; doxygen doxygen_config.dox)
181
182
183#############################################################
184# clean targets
185#
186clean: clean_libs clean_tests clean_docs
187
188.PHONY: clean_libs clean_tests clean_docs clean_install
189
190clean_libs:
191	cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE) clean
192	cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE) clean
193
194clean_tests:
195	cd $(OCSD_ROOT)/tests/build/linux/echo_test_dcd_lib && $(MAKE) clean
196	cd $(OCSD_ROOT)/tests/build/linux/snapshot_parser_lib && $(MAKE) clean
197	cd $(OCSD_ROOT)/tests/build/linux/trc_pkt_lister && $(MAKE) clean
198	cd $(OCSD_ROOT)/tests/build/linux/c_api_pkt_print_test && $(MAKE) clean
199	cd $(OCSD_ROOT)/tests/build/linux/mem_buffer_eg && $(MAKE) clean
200	-rmdir $(OCSD_TESTS)/lib
201
202clean_docs:
203	-rm -r $(OCSD_ROOT)/docs/html
204
205clean_install:
206	-rm    $(INSTALL_LIB_DIR)/lib$(LIB_BASE_NAME).*
207	-rm    $(INSTALL_LIB_DIR)/lib$(LIB_CAPI_NAME).*
208	-rm -r $(INSTALL_INCLUDE_DIR)/$(LIB_UAPI_INC_DIR)
209	-rm    $(INSTALL_BIN_DIR)/trc_pkt_lister
210	-rm    $(INSTALL_MAN_DIR)/trc_pkt_lister.1
211