summaryrefslogtreecommitdiffstats
path: root/decoder/build/linux/makefile
blob: 5515737f0d0027938f8090ff7a2cd67686ec6c5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
########################################################
# Copyright 2015 ARM Limited. All rights reserved.
# 
# Redistribution and use in source and binary forms, with or without modification, 
# are permitted provided that the following conditions are met:
# 
# 1. Redistributions of source code must retain the above copyright notice, 
# this list of conditions and the following disclaimer.
# 
# 2. Redistributions in binary form must reproduce the above copyright notice, 
# this list of conditions and the following disclaimer in the documentation 
# and/or other materials provided with the distribution. 
# 
# 3. Neither the name of the copyright holder nor the names of its contributors 
# may be used to endorse or promote products derived from this software without 
# specific prior written permission. 
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND 
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
# 
#################################################################################
# OpenCSD - master makefile for libraries and tests
#
# command line options
# DEBUG=1 	    create a debug build
#

# Set project root - relative to build makefile
ifeq ($(OCSD_ROOT),)
OCSD_ROOT := $(shell echo $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) | sed 's,/build/linux.*,,')
export OCSD_ROOT
endif

# library names
LIB_BASE_NAME=opencsd
export LIB_BASE_NAME
LIB_CAPI_NAME=$(LIB_BASE_NAME)_c_api
export LIB_CAPI_NAME

# source root directories
export OCSD_LIB_ROOT=$(OCSD_ROOT)/lib

export OCSD_INCLUDE=$(OCSD_ROOT)/include
export OCSD_SOURCE=$(OCSD_ROOT)/source

export OCSD_TESTS=$(OCSD_ROOT)/tests
export LIB_UAPI_INC_DIR=opencsd

# tools
export MASTER_CC=$(CROSS_COMPILE)gcc
export MASTER_CXX=$(CROSS_COMPILE)g++
export MASTER_LINKER=$(CROSS_COMPILE)g++
export MASTER_LIB=$(CROSS_COMPILE)ar
export INSTALL=install


# installation directory
PREFIX ?=/usr
LIB_PATH ?= lib
INSTALL_LIB_DIR=$(DESTDIR)$(PREFIX)/$(LIB_PATH)
INSTALL_BIN_DIR=$(DESTDIR)$(PREFIX)/bin
export INSTALL_INCLUDE_DIR=$(DESTDIR)$(PREFIX)/include/
INSTALL_MAN_DIR=$(DESTDIR)$(PREFIX)/share/man/man1

# compile flags
CFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -Wlogical-op -fPIC
CXXFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -Wlogical-op -fPIC -std=c++11
LDFLAGS += -Wl,-z,defs
ARFLAGS ?= rcs

# debug variant
ifdef DEBUG
CFLAGS += -g -O0 -DDEBUG
CXXFLAGS += -g -O0 -DDEBUG
BUILD_VARIANT=dbg
else
CFLAGS += -O2 -DNDEBUG
CXXFLAGS += -O2 -DNDEBUG
BUILD_VARIANT=rel
endif

# export build flags
export CFLAGS
export CXXFLAGS
export LDFLAGS
export ARFLAGS

# target directories - fixed for default packaging build
PLAT_DIR ?= builddir
export PLAT_DIR
export LIB_TARGET_DIR=$(OCSD_LIB_ROOT)/$(PLAT_DIR)
export LIB_TEST_TARGET_DIR=$(OCSD_TESTS)/lib/$(PLAT_DIR)
export BIN_TEST_TARGET_DIR=$(OCSD_TESTS)/bin/$(PLAT_DIR)

# Fish version out of header file (converting from hex)
getver:=printf "%d" $$(awk '/\#define VARNAME/ { print $$3 }' $(OCSD_ROOT)/include/opencsd/ocsd_if_version.h)
export SO_MAJOR_VER := $(shell $(subst VARNAME,OCSD_VER_MAJOR,$(getver)))
SO_MINOR_VER := $(shell $(subst VARNAME,OCSD_VER_MINOR,$(getver)))
SO_PATCH_VER := $(shell $(subst VARNAME,OCSD_VER_PATCH,$(getver)))
export SO_VER := $(SO_MAJOR_VER).$(SO_MINOR_VER).$(SO_PATCH_VER)


###########################################################
# build targets

all: libs tests

libs: $(LIB_BASE_NAME)_lib  $(LIB_CAPI_NAME)_lib

DEF_SO_PERM ?= 644

install: libs tests
	mkdir -p $(INSTALL_LIB_DIR) $(INSTALL_INCLUDE_DIR) $(INSTALL_BIN_DIR)
	cp -d $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so $(INSTALL_LIB_DIR)/
	cp -d $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so.$(SO_MAJOR_VER) $(INSTALL_LIB_DIR)/
	$(INSTALL) --mode=$(DEF_SO_PERM) $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so.$(SO_VER) $(INSTALL_LIB_DIR)/
	cp -d $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so $(INSTALL_LIB_DIR)/
	cp -d $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so.$(SO_MAJOR_VER) $(INSTALL_LIB_DIR)/
	$(INSTALL) --mode=$(DEF_SO_PERM) $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so.$(SO_VER) $(INSTALL_LIB_DIR)/
ifndef DISABLE_STATIC
	$(INSTALL) --mode=644 $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a $(INSTALL_LIB_DIR)/
	$(INSTALL) --mode=644 $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a $(INSTALL_LIB_DIR)/
endif
	cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && make install_inc
	$(INSTALL) --mode=755 $(BIN_TEST_TARGET_DIR)/trc_pkt_lister $(INSTALL_BIN_DIR)/ 

install_man:
	mkdir -p $(INSTALL_MAN_DIR)
	$(INSTALL) --mode=644 $(OCSD_ROOT)/docs/man/trc_pkt_lister.1 $(INSTALL_MAN_DIR)/


################################
# build  OpenCSD trace decode library
#
$(LIB_BASE_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so

$(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).so: $(LIB_BASE_NAME)_all
$(LIB_TARGET_DIR)/lib$(LIB_BASE_NAME).a: $(LIB_BASE_NAME)_all

# single command builds both .a and .so targets in sub-makefile
$(LIB_BASE_NAME)_all:
	mkdir -p $(LIB_TARGET_DIR)
	cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE)

################################
# build OpenCSD trace decode C API library 
#
$(LIB_CAPI_NAME)_lib: $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a $(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so

$(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).so: $(LIB_CAPI_NAME)_all
$(LIB_TARGET_DIR)/lib$(LIB_CAPI_NAME).a:  $(LIB_CAPI_NAME)_all

# single command builds both .a and .so targets in sub-makefile
$(LIB_CAPI_NAME)_all:  $(LIB_BASE_NAME)_lib
	mkdir -p $(LIB_TARGET_DIR)
	cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE)

#################################
# build tests

.PHONY: tests
tests: libs
	cd $(OCSD_ROOT)/tests/build/linux/echo_test_dcd_lib && $(MAKE)
	cd $(OCSD_ROOT)/tests/build/linux/snapshot_parser_lib && $(MAKE)
	cd $(OCSD_ROOT)/tests/build/linux/trc_pkt_lister && $(MAKE)
	cd $(OCSD_ROOT)/tests/build/linux/c_api_pkt_print_test && $(MAKE)
	cd $(OCSD_ROOT)/tests/build/linux/mem_buffer_eg && $(MAKE)
	cd $(OCSD_ROOT)/tests/build/linux/frame_demux_test && $(MAKE)

#
# build docs
.PHONY: docs
docs:
	(cd $(OCSD_ROOT)/docs; doxygen doxygen_config.dox)


#############################################################
# clean targets
#
clean: clean_libs clean_tests clean_docs

.PHONY: clean_libs clean_tests clean_docs clean_install

clean_libs:
	cd $(OCSD_ROOT)/build/linux/ref_trace_decode_lib && $(MAKE) clean
	cd $(OCSD_ROOT)/build/linux/rctdl_c_api_lib && $(MAKE) clean

clean_tests:
	cd $(OCSD_ROOT)/tests/build/linux/echo_test_dcd_lib && $(MAKE) clean
	cd $(OCSD_ROOT)/tests/build/linux/snapshot_parser_lib && $(MAKE) clean
	cd $(OCSD_ROOT)/tests/build/linux/trc_pkt_lister && $(MAKE) clean
	cd $(OCSD_ROOT)/tests/build/linux/c_api_pkt_print_test && $(MAKE) clean
	cd $(OCSD_ROOT)/tests/build/linux/mem_buffer_eg && $(MAKE) clean
	cd $(OCSD_ROOT)/tests/build/linux/frame_demux_test && $(MAKE) clean
	-rmdir $(OCSD_TESTS)/lib

clean_docs:
	-rm -r $(OCSD_ROOT)/docs/html

clean_install:
	-rm    $(INSTALL_LIB_DIR)/lib$(LIB_BASE_NAME).*
	-rm    $(INSTALL_LIB_DIR)/lib$(LIB_CAPI_NAME).*
	-rm -r $(INSTALL_INCLUDE_DIR)/$(LIB_UAPI_INC_DIR)
	-rm    $(INSTALL_BIN_DIR)/trc_pkt_lister
	-rm    $(INSTALL_MAN_DIR)/trc_pkt_lister.1