eal: revert C++ app build fix
[dpdk.git] / mk / rte.app.mk
1 #   BSD LICENSE
2 #
3 #   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
4 #   Copyright(c) 2014-2015 6WIND S.A.
5 #   All rights reserved.
6 #
7 #   Redistribution and use in source and binary forms, with or without
8 #   modification, are permitted provided that the following conditions
9 #   are met:
10 #
11 #     * Redistributions of source code must retain the above copyright
12 #       notice, this list of conditions and the following disclaimer.
13 #     * Redistributions in binary form must reproduce the above copyright
14 #       notice, this list of conditions and the following disclaimer in
15 #       the documentation and/or other materials provided with the
16 #       distribution.
17 #     * Neither the name of Intel Corporation nor the names of its
18 #       contributors may be used to endorse or promote products derived
19 #       from this software without specific prior written permission.
20 #
21 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 include $(RTE_SDK)/mk/internal/rte.compile-pre.mk
34 include $(RTE_SDK)/mk/internal/rte.install-pre.mk
35 include $(RTE_SDK)/mk/internal/rte.clean-pre.mk
36 include $(RTE_SDK)/mk/internal/rte.build-pre.mk
37 include $(RTE_SDK)/mk/internal/rte.depdirs-pre.mk
38
39 # VPATH contains at least SRCDIR
40 VPATH += $(SRCDIR)
41
42 _BUILD = $(APP)
43 _INSTALL = $(INSTALL-FILES-y) $(SYMLINK-FILES-y)
44 _INSTALL += $(RTE_OUTPUT)/app/$(APP) $(RTE_OUTPUT)/app/$(APP).map
45 POSTINSTALL += target-appinstall
46 _CLEAN = doclean
47 POSTCLEAN += target-appclean
48
49 ifeq ($(NO_LDSCRIPT),)
50 LDSCRIPT = $(RTE_LDSCRIPT)
51 endif
52
53 # default path for libs
54 _LDLIBS-y += -L$(RTE_SDK_BIN)/lib
55
56 #
57 # Order is important: from higher level to lower level
58 #
59
60 _LDLIBS-y += --whole-archive
61
62 _LDLIBS-$(CONFIG_RTE_BUILD_COMBINE_LIBS)    += -l$(RTE_LIBNAME)
63
64 ifeq ($(CONFIG_RTE_BUILD_COMBINE_LIBS),n)
65
66 _LDLIBS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR)    += -lrte_distributor
67 _LDLIBS-$(CONFIG_RTE_LIBRTE_REORDER)        += -lrte_reorder
68
69 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
70 _LDLIBS-$(CONFIG_RTE_LIBRTE_KNI)            += -lrte_kni
71 _LDLIBS-$(CONFIG_RTE_LIBRTE_IVSHMEM)        += -lrte_ivshmem
72 endif
73
74 _LDLIBS-$(CONFIG_RTE_LIBRTE_PIPELINE)       += -lrte_pipeline
75 _LDLIBS-$(CONFIG_RTE_LIBRTE_TABLE)          += -lrte_table
76 _LDLIBS-$(CONFIG_RTE_LIBRTE_PORT)           += -lrte_port
77 _LDLIBS-$(CONFIG_RTE_LIBRTE_TIMER)          += -lrte_timer
78 _LDLIBS-$(CONFIG_RTE_LIBRTE_HASH)           += -lrte_hash
79 _LDLIBS-$(CONFIG_RTE_LIBRTE_JOBSTATS)       += -lrte_jobstats
80 _LDLIBS-$(CONFIG_RTE_LIBRTE_LPM)            += -lrte_lpm
81 _LDLIBS-$(CONFIG_RTE_LIBRTE_POWER)          += -lrte_power
82 _LDLIBS-$(CONFIG_RTE_LIBRTE_ACL)            += -lrte_acl
83 _LDLIBS-$(CONFIG_RTE_LIBRTE_METER)          += -lrte_meter
84
85 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrte_sched
86 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lm
87 _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED)          += -lrt
88
89 _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST)          += -lrte_vhost
90
91 endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS
92
93 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP)       += -lpcap
94
95 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SZEDATA2)   += -lsze2
96
97 ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y)
98 _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST)          += -lnuma
99 endif
100
101 ifeq ($(CONFIG_RTE_LIBRTE_VHOST_USER),n)
102 _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST)          += -lfuse
103 endif
104
105 ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),n)
106 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD)       += -libverbs
107 endif # ! CONFIG_RTE_BUILD_SHARED_LIBS
108
109 ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),n)
110 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD)       += -libverbs
111 endif # ! CONFIG_RTE_BUILD_SHARED_LIBS
112
113 _LDLIBS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD)      += -lz
114
115 _LDLIBS-y += --start-group
116
117 ifeq ($(CONFIG_RTE_BUILD_COMBINE_LIBS),n)
118
119 _LDLIBS-$(CONFIG_RTE_LIBRTE_KVARGS)         += -lrte_kvargs
120 _LDLIBS-$(CONFIG_RTE_LIBRTE_MBUF)           += -lrte_mbuf
121 _LDLIBS-$(CONFIG_RTE_LIBRTE_IP_FRAG)        += -lrte_ip_frag
122 _LDLIBS-$(CONFIG_RTE_LIBRTE_ETHER)          += -lethdev
123 _LDLIBS-$(CONFIG_RTE_LIBRTE_MEMPOOL)        += -lrte_mempool
124 _LDLIBS-$(CONFIG_RTE_LIBRTE_RING)           += -lrte_ring
125 _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL)            += -lrte_eal
126 _LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE)        += -lrte_cmdline
127 _LDLIBS-$(CONFIG_RTE_LIBRTE_CFGFILE)        += -lrte_cfgfile
128 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_BOND)       += -lrte_pmd_bond
129
130 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_XENVIRT)    += -lrte_pmd_xenvirt
131 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_XENVIRT)    += -lxenstore
132
133 ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),n)
134 # plugins (link only if static libraries)
135
136 _LDLIBS-$(CONFIG_RTE_LIBRTE_VMXNET3_PMD)    += -lrte_pmd_vmxnet3_uio
137 _LDLIBS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD)     += -lrte_pmd_virtio
138 _LDLIBS-$(CONFIG_RTE_LIBRTE_BNX2X_PMD)      += -lrte_pmd_bnx2x
139 _LDLIBS-$(CONFIG_RTE_LIBRTE_CXGBE_PMD)      += -lrte_pmd_cxgbe
140 _LDLIBS-$(CONFIG_RTE_LIBRTE_ENIC_PMD)       += -lrte_pmd_enic
141 _LDLIBS-$(CONFIG_RTE_LIBRTE_I40E_PMD)       += -lrte_pmd_i40e
142 _LDLIBS-$(CONFIG_RTE_LIBRTE_FM10K_PMD)      += -lrte_pmd_fm10k
143 _LDLIBS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD)      += -lrte_pmd_ixgbe
144 _LDLIBS-$(CONFIG_RTE_LIBRTE_E1000_PMD)      += -lrte_pmd_e1000
145 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX4_PMD)       += -lrte_pmd_mlx4
146 _LDLIBS-$(CONFIG_RTE_LIBRTE_MLX5_PMD)       += -lrte_pmd_mlx5
147 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_SZEDATA2)   += -lrte_pmd_szedata2
148 _LDLIBS-$(CONFIG_RTE_LIBRTE_MPIPE_PMD)      += -lrte_pmd_mpipe -lgxio
149 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_RING)       += -lrte_pmd_ring
150 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_PCAP)       += -lrte_pmd_pcap
151 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_AF_PACKET)  += -lrte_pmd_af_packet
152 _LDLIBS-$(CONFIG_RTE_LIBRTE_PMD_NULL)       += -lrte_pmd_null
153
154 endif # ! $(CONFIG_RTE_BUILD_SHARED_LIB)
155
156 endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS
157
158 _LDLIBS-y += $(EXECENV_LDLIBS)
159 _LDLIBS-y += --end-group
160 _LDLIBS-y += --no-whole-archive
161
162 LDLIBS += $(_LDLIBS-y) $(CPU_LDLIBS) $(EXTRA_LDLIBS)
163
164 .PHONY: all
165 all: install
166
167 .PHONY: install
168 install: build _postinstall
169
170 _postinstall: build
171
172 .PHONY: build
173 build: _postbuild
174
175 exe2cmd = $(strip $(call dotfile,$(patsubst %,%.cmd,$(1))))
176
177 ifeq ($(LINK_USING_CC),1)
178 override EXTRA_LDFLAGS := $(call linkerprefix,$(EXTRA_LDFLAGS))
179 O_TO_EXE = $(CC) $(CFLAGS) $(LDFLAGS_$(@)) \
180         -Wl,-Map=$(@).map,--cref -o $@ $(OBJS-y) $(call linkerprefix,$(LDFLAGS)) \
181         $(EXTRA_LDFLAGS) $(call linkerprefix,$(LDLIBS))
182 else
183 O_TO_EXE = $(LD) $(LDFLAGS) $(LDFLAGS_$(@)) $(EXTRA_LDFLAGS) \
184         -Map=$(@).map --cref -o $@ $(OBJS-y) $(LDLIBS)
185 endif
186 O_TO_EXE_STR = $(subst ','\'',$(O_TO_EXE)) #'# fix syntax highlight
187 O_TO_EXE_DISP = $(if $(V),"$(O_TO_EXE_STR)","  LD $(@)")
188 O_TO_EXE_CMD = "cmd_$@ = $(O_TO_EXE_STR)"
189 O_TO_EXE_DO = @set -e; \
190         echo $(O_TO_EXE_DISP); \
191         $(O_TO_EXE) && \
192         echo $(O_TO_EXE_CMD) > $(call exe2cmd,$(@))
193
194 -include .$(APP).cmd
195
196 # path where libraries are retrieved
197 LDLIBS_PATH := $(subst -Wl$(comma)-L,,$(filter -Wl$(comma)-L%,$(LDLIBS)))
198 LDLIBS_PATH += $(subst -L,,$(filter -L%,$(LDLIBS)))
199
200 # list of .a files that are linked to this application
201 LDLIBS_NAMES := $(patsubst -l%,lib%.a,$(filter -l%,$(LDLIBS)))
202 LDLIBS_NAMES += $(patsubst -Wl$(comma)-l%,lib%.a,$(filter -Wl$(comma)-l%,$(LDLIBS)))
203
204 # list of found libraries files (useful for deps). If not found, the
205 # library is silently ignored and dep won't be checked
206 LDLIBS_FILES := $(wildcard $(foreach dir,$(LDLIBS_PATH),\
207         $(addprefix $(dir)/,$(LDLIBS_NAMES))))
208
209 #
210 # Compile executable file if needed
211 #
212 $(APP): $(OBJS-y) $(LDLIBS_FILES) $(DEP_$(APP)) $(LDSCRIPT) FORCE
213         @[ -d $(dir $@) ] || mkdir -p $(dir $@)
214         $(if $(D),\
215                 @echo -n "$< -> $@ " ; \
216                 echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
217                 echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_EXE_STR))) " ; \
218                 echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
219                 echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
220         $(if $(or \
221                 $(file_missing),\
222                 $(call cmdline_changed,$(O_TO_EXE_STR)),\
223                 $(depfile_missing),\
224                 $(depfile_newer)),\
225                 $(O_TO_EXE_DO))
226
227 #
228 # install app in $(RTE_OUTPUT)/app
229 #
230 $(RTE_OUTPUT)/app/$(APP): $(APP)
231         @echo "  INSTALL-APP $(APP)"
232         @[ -d $(RTE_OUTPUT)/app ] || mkdir -p $(RTE_OUTPUT)/app
233         $(Q)cp -f $(APP) $(RTE_OUTPUT)/app
234
235 #
236 # install app map file in $(RTE_OUTPUT)/app
237 #
238 $(RTE_OUTPUT)/app/$(APP).map: $(APP)
239         @echo "  INSTALL-MAP $(APP).map"
240         @[ -d $(RTE_OUTPUT)/app ] || mkdir -p $(RTE_OUTPUT)/app
241         $(Q)cp -f $(APP).map $(RTE_OUTPUT)/app
242
243 #
244 # Clean all generated files
245 #
246 .PHONY: clean
247 clean: _postclean
248         $(Q)rm -f $(_BUILD_TARGETS) $(_INSTALL_TARGETS) $(_CLEAN_TARGETS)
249
250 .PHONY: doclean
251 doclean:
252         $(Q)rm -rf $(APP) $(OBJS-all) $(DEPS-all) $(DEPSTMP-all) \
253           $(CMDS-all) $(INSTALL-FILES-all) .$(APP).cmd
254
255
256 include $(RTE_SDK)/mk/internal/rte.compile-post.mk
257 include $(RTE_SDK)/mk/internal/rte.install-post.mk
258 include $(RTE_SDK)/mk/internal/rte.clean-post.mk
259 include $(RTE_SDK)/mk/internal/rte.build-post.mk
260 include $(RTE_SDK)/mk/internal/rte.depdirs-post.mk
261
262 ifneq ($(wildcard $(RTE_SDK)/mk/target/$(RTE_TARGET)/rte.app.mk),)
263 include $(RTE_SDK)/mk/target/$(RTE_TARGET)/rte.app.mk
264 else
265 include $(RTE_SDK)/mk/target/generic/rte.app.mk
266 endif
267
268 .PHONY: FORCE
269 FORCE: