8de2dfabf3ed65d69d7d54fa3f42104982dbe923
[o-du/phy.git] / fhi_lib / app / Makefile
1 #/******************************************************************************
2 #*
3 #*   Copyright (c) 2019 Intel.
4 #*
5 #*   Licensed under the Apache License, Version 2.0 (the "License");
6 #*   you may not use this file except in compliance with the License.
7 #*   You may obtain a copy of the License at
8 #*
9 #*       http://www.apache.org/licenses/LICENSE-2.0
10 #*
11 #*   Unless required by applicable law or agreed to in writing, software
12 #*   distributed under the License is distributed on an "AS IS" BASIS,
13 #*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #*   See the License for the specific language governing permissions and
15 #*   limitations under the License.
16 #*
17 #*******************************************************************************/
18
19 MYCUSTOMTAB='     '
20 MYCUSTOMSPACE='============================================================================================'
21 MYCUSTOMSPACE1='------------------------------------------------------------'
22
23 ##############################################################
24 #  Tools configuration
25 ##############################################################
26 CC  := icc
27 CPP := icpc
28 AS := as
29 AR := ar
30 LD := icc
31 OBJDUMP := objdump
32
33 ifeq ($(SHELL),cmd.exe)
34 MD := mkdir.exe -p
35 CP := cp.exe -f
36 RM := rm.exe -rf
37 else
38 MD := mkdir -p
39 CP := cp -f
40 RM := rm -rf
41 endif
42
43 PROJECT_NAME := sample-app
44 PROJECT_TYPE := elf
45 PROJECT_DIR  := $(XRAN_DIR)/app
46 BUILDDIR := ./build
47 PROJECT_BINARY := $(BUILDDIR)/$(PROJECT_NAME)
48
49 ifeq ($(RTE_SDK),)
50     $(error "Please define RTE_SDK environment variable")
51 endif
52
53 RTE_TARGET ?= x86_64-native-linuxapp-gcc
54 RTE_INC := $(RTE_SDK)/$(RTE_TARGET)/include
55
56 API_DIR := $(XRAN_DIR)/lib/api
57 SRC_DIR := $(PROJECT_DIR)/src
58
59 ifeq ($(MLOG),1)
60 ifeq ($(MLOG_DIR),)
61     MLOG_DIR=$(XRAN_DIR)/../mlog
62 endif
63 endif
64
65 CC_SRC = $(SRC_DIR)/common.c \
66         $(SRC_DIR)/sample-app.c \
67         $(SRC_DIR)/config.c
68
69 CC_FLAGS += -std=gnu11 -Wall -Wno-deprecated-declarations  \
70         -fdata-sections \
71         -ffunction-sections \
72         -g \
73         -Wall \
74         -Wimplicit-function-declaration \
75         -g -O3 -wd1786
76 CC_FLAGS += -fstack-protector-strong -z,now, -z,relro -z noexecstack -Wformat -Wformat-security -Werror=format-security -fno-strict-overflow -fwrapv
77
78 CPP_FLAGS := -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -D_REENTRANT -pipe -no-prec-div \
79                 -no-prec-div -fp-model fast=2\
80                 -no-prec-sqrt  -falign-functions=16 -fast-transcendentals \
81         -Werror -Wno-unused-variable -std=c++11 -mcmodel=large
82
83 INC :=  -I$(API_DIR) -I$(RTE_INC)
84 DEF :=
85
86 ifeq ($(MLOG),1)
87         INC  += -I$(MLOG_DIR)/source
88         DEF += -DMLOG_ENABLED
89 else
90         DEF += -UMLOG_ENABLED
91 endif
92
93 XRAN_LIB_DIR=$(XRAN_DIR)/lib/build
94 LD_FLAGS += -L$(XRAN_LIB_DIR) -lxran
95
96 RTE_LIBS = -L$(RTE_SDK)/$(RTE_TARGET)/lib -Wl,-lrte_flow_classify -Wl,--whole-archive -Wl,-lrte_pipeline -Wl,--no-whole-archive -Wl,--whole-archive -Wl,-lrte_table -Wl,--no-whole-archive -Wl,--whole-archive -Wl,-lrte_port -Wl,--no-whole-archive -Wl,-lrte_pdump -Wl,-lrte_distributor -Wl,-lrte_ip_frag -Wl,-lrte_meter -Wl,-lrte_lpm -Wl,--whole-archive -Wl,-lrte_acl -Wl,--no-whole-archive -Wl,-lrte_jobstats -Wl,-lrte_metrics -Wl,-lrte_bitratestats -Wl,-lrte_latencystats -Wl,-lrte_power -Wl,-lrte_efd -Wl,-lrte_bpf -Wl,--whole-archive -Wl,-lrte_cfgfile -Wl,-lrte_gro -Wl,-lrte_gso -Wl,-lrte_hash -Wl,-lrte_member -Wl,-lrte_vhost -Wl,-lrte_kvargs -Wl,-lrte_mbuf -Wl,-lrte_net -Wl,-lrte_ethdev -Wl,-lrte_bbdev -Wl,-lrte_cryptodev -Wl,-lrte_security -Wl,-lrte_compressdev -Wl,-lrte_eventdev -Wl,-lrte_rawdev -Wl,-lrte_timer -Wl,-lrte_mempool -Wl,-lrte_mempool_ring -Wl,-lrte_ring -Wl,-lrte_pci -Wl,-lrte_eal -Wl,-lrte_cmdline -Wl,-lrte_reorder -Wl,-lrte_sched -Wl,-lrte_kni -Wl,-lrte_common_octeontx -Wl,-lrte_bus_pci -Wl,-lrte_bus_vdev -Wl,-lrte_bus_dpaa -Wl,-lrte_bus_fslmc -Wl,-lrte_mempool_bucket -Wl,-lrte_mempool_stack -Wl,-lrte_mempool_dpaa -Wl,-lrte_mempool_dpaa2 -Wl,-lrte_pmd_af_packet -Wl,-lrte_pmd_ark -Wl,-lrte_pmd_avf -Wl,-lrte_pmd_avp -Wl,-lrte_pmd_axgbe -Wl,-lrte_pmd_bnxt -Wl,-lrte_pmd_bond -Wl,-lrte_pmd_cxgbe -Wl,-lrte_pmd_dpaa -Wl,-lrte_pmd_dpaa2 -Wl,-lrte_pmd_e1000 -Wl,-lrte_pmd_ena -Wl,-lrte_pmd_enic -Wl,-lrte_pmd_fm10k -Wl,-lrte_pmd_failsafe -Wl,-lrte_pmd_i40e -Wl,-lrte_pmd_ixgbe -Wl,-lrte_pmd_kni -Wl,-lrte_pmd_lio -Wl,-lrte_pmd_nfp -Wl,-lrte_pmd_null -Wl,-lrte_pmd_qede -Wl,-lrte_pmd_ring -Wl,-lrte_pmd_softnic -Wl,-lrte_pmd_tap -Wl,-lrte_pmd_thunderx_nicvf -Wl,-lrte_pmd_vdev_netvsc -Wl,-lrte_pmd_virtio -Wl,-lrte_pmd_vhost -Wl,-lrte_pmd_ifc -Wl,-lrte_pmd_vmxnet3_uio -Wl,-lrte_bus_vmbus -Wl,-lrte_pmd_netvsc -Wl,-lrte_pmd_bbdev_null -Wl,-lrte_pmd_null_crypto -Wl,-lrte_pmd_crypto_scheduler -Wl,-lrte_pmd_dpaa2_sec -Wl,-lrte_pmd_dpaa_sec -Wl,-lrte_pmd_virtio_crypto -Wl,-lrte_pmd_octeontx_zip -Wl,-lrte_pmd_qat -Wl,-lrte_pmd_skeleton_event -Wl,-lrte_pmd_sw_event -Wl,-lrte_pmd_octeontx_ssovf -Wl,-lrte_pmd_dpaa_event -Wl,-lrte_pmd_dpaa2_event -Wl,-lrte_mempool_octeontx -Wl,-lrte_pmd_octeontx -Wl,-lrte_pmd_opdl_event -Wl,-lrte_pmd_skeleton_rawdev -Wl,-lrte_pmd_dpaa2_cmdif -Wl,-lrte_pmd_dpaa2_qdma -Wl,-lrte_bus_ifpga -Wl,-lrte_pmd_ifpga_rawdev -Wl,--no-whole-archive -Wl,-lrt -Wl,-lm -Wl,-lnuma -Wl,-ldl -Wl,
97 LD_FLAGS += $(RTE_LIBS)
98
99 ifeq ($(MLOG),1)
100         LD_FLAGS +=  -L$(MLOG_DIR)/bin -lmlog
101 endif
102
103 AS_FLAGS :=
104 AR_FLAGS := rc
105
106 PROJECT_OBJ_DIR := build/obj
107
108 CC_OBJS := $(patsubst %.c,%.o,$(CC_SRC))
109 CPP_OBJS := $(patsubst %.cpp,%.o,$(CPP_SRC))
110 AS_OBJS := $(patsubst %.s,%.o,$(AS_SRC))
111 OBJS    := $(CC_OBJS) $(CPP_OBJS) $(AS_OBJS) $(LIBS)
112 DIRLIST := $(addprefix $(PROJECT_OBJ_DIR)/,$(sort $(dir $(OBJS))))
113
114 CC_OBJTARGETS := $(addprefix $(PROJECT_OBJ_DIR)/,$(CC_OBJS))
115 CPP_OBJTARGETS := $(addprefix $(PROJECT_OBJ_DIR)/,$(CPP_OBJS))
116
117 AS_OBJTARGETS := $(addprefix $(PROJECT_OBJ_DIR)/,$(AS_OBJS))
118
119 CC_FLAGS_FULL  := $(CC_FLAGS)  $(INC) $(DEF)
120 CPP_FLAGS_FULL := $(CPP_FLAGS) $(INC) $(DEF)
121
122 AS_FLAGS := $(AS_FLAGS) $(INC)
123
124 PROJECT_DEP_FILE := $(PROJECT_OBJ_DIR)/$(PROJECT_NAME).dep
125
126 ifeq ($(wildcard $(PROJECT_DEP_FILE)),$(PROJECT_DEP_FILE))
127 GENERATE_DEPS :=
128 else
129
130 CC_DEPS  := $(addprefix __dep__,$(subst ../,__up__,$(CC_SRC)))
131 CPP_DEPS  := $(addprefix __dep__,$(subst ../,__up__,$(CPP_SRC)))
132 GENERATE_DEPS := generate_deps
133 endif
134
135 all : welcome_line      $(PROJECT_BINARY)
136         @echo $(PROJECT_BINARY)
137
138 .PHONY : clear_dep
139 clear_dep:
140         @$(RM) $(PROJECT_DEP_FILE)
141         @echo [DEP]   $(subst $(PROJECT_OBJ_DIR)/,,$(PROJECT_DEP_FILE))
142
143 $(CC_DEPS) :
144         @$(CC) -MM $(subst __up__,../,$(subst __dep__,,$@)) -MT $(PROJECT_OBJ_DIR)/$(patsubst %.c,%.o,$(subst __up__,../,$(subst __dep__,,$@))) $(CC_FLAGS_FULL) >> $(PROJECT_DEP_FILE)
145
146 $(CPP_DEPS) :
147         @$(CPP) -MM $(subst __up__,../,$(subst __dep__,,$@)) -MT $(PROJECT_OBJ_DIR)/$(patsubst %.cpp,%.o,$(subst __up__,../,$(subst __dep__,,$@))) $(CPP_FLAGS_FULL) >> $(PROJECT_DEP_FILE)
148
149 .PHONY : generate_deps
150 generate_deps : clear_dep $(CC_DEPS) $(CPP_DEPS)
151
152
153 .PHONY : echo_start_build
154 echo_start_build :
155         @echo [BUILD] $(PROJECT_TYPE) : $(PROJECT_NAME)
156
157 $(DIRLIST) :
158         -@$(MD) $@
159
160 $(CC_OBJTARGETS) :
161         @echo [CC]    $(subst $(PROJECT_OBJ_DIR)/,,$@)
162         @$(CC) -c $(CC_FLAGS_FULL) -o"$@" $(patsubst %.o,%.c,$(subst $(PROJECT_OBJ_DIR)/,,$@))
163
164 $(CPP_OBJTARGETS) :
165         @echo [CPP]    $(subst $(PROJECT_OBJ_DIR)/,,$@)
166         @$(CPP) -c $(CPP_FLAGS_FULL) -o"$@" $(patsubst %.o,%.cpp,$(subst $(PROJECT_OBJ_DIR)/,,$@))
167
168 $(AS_OBJTARGETS) :
169         @echo [AS]    $(subst $(PROJECT_OBJ_DIR)/,,$@)
170         @$(AS) $(AS_FLAGS) -o"$@" $(patsubst %.o,%.s,$(subst $(PROJECT_OBJ_DIR)/,,$@))
171
172 ifeq ($(wildcard $(PROJECT_DEP_FILE)),$(PROJECT_DEP_FILE))
173
174 include $(PROJECT_DEP_FILE)
175
176 endif
177
178 .PHONY: clean xclean
179 clean:
180         @echo [CLEAN]  : $(PROJECT_NAME)
181         @$(RM) $(CC_OBJTARGETS) $(CPP_OBJTARGETS) $(AS_OBJTARGETS)
182
183 xclean: clean
184 ifneq ($(wildcard $(PROJECT_DIR)/$(PROJECT_MAKE)),)
185         @echo [XCLEAN] : $(PROJECT_NAME)
186         @$(RM) $(PROJECT_BINARY) $(PROJECT_BINARY_LIB) $(PROJECT_DEP_FILE)
187 endif
188
189 .PHONY : welcome_line
190 welcome_line :
191         @echo $(MYCUSTOMSPACE)
192         @echo Building  $(PROJECT_BINARY)
193         @echo $(MYCUSTOMTAB)RTE_TARGET           = $(RTE_TARGET)
194         @echo $(MYCUSTOMSPACE)
195
196
197 .PHONY : debug release
198
199 debug :  all
200 release :  all
201
202 $(PROJECT_BINARY): $(DIRLIST) echo_start_build $(GENERATE_DEPS) $(PRE_BUILD) $(CC_OBJTARGETS) $(CPP_OBJTARGETS) $(AS_OBJTARGETS)
203         @echo "[LD] $@ "
204         @$(LD) -o $@ $(CC_OBJTARGETS) $(CPP_OBJTARGETS) $(AS_OBJTARGETS) $(LD_FLAGS) -Wl,-L $(BUILDDIR) -lrt -lpthread
205
206 #@echo [APP]   $@
207 #@$(OBJDUMP) -d $(PROJECT_BINARY) > $(PROJECT_BINARY).asm