app/test: new reorder unit test
[dpdk.git] / mk / rte.app.mk
1 #   BSD LICENSE
2 #
3 #   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
4 #   Copyright(c) 2014 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 += -L$(RTE_SDK_BIN)/lib
55
56 #
57 # Include libraries depending on config if NO_AUTOLIBS is not set
58 # Order is important: from higher level to lower level
59 #
60 ifeq ($(NO_AUTOLIBS),)
61
62 LDLIBS += --whole-archive
63
64 ifeq ($(CONFIG_RTE_BUILD_COMBINE_LIBS),y)
65 LDLIBS += -l$(RTE_LIBNAME)
66 endif
67
68 ifeq ($(CONFIG_RTE_BUILD_COMBINE_LIBS),n)
69
70 ifeq ($(CONFIG_RTE_LIBRTE_DISTRIBUTOR),y)
71 LDLIBS += -lrte_distributor
72 endif
73
74 ifeq ($(CONFIG_RTE_LIBRTE_REORDER),y)
75 LDLIBS += -lrte_reorder
76 endif
77
78 ifeq ($(CONFIG_RTE_LIBRTE_KNI),y)
79 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
80 LDLIBS += -lrte_kni
81 endif
82 endif
83
84 ifeq ($(CONFIG_RTE_LIBRTE_IVSHMEM),y)
85 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
86 LDLIBS += -lrte_ivshmem
87 endif
88 endif
89
90 ifeq ($(CONFIG_RTE_LIBRTE_PIPELINE),y)
91 LDLIBS += -lrte_pipeline
92 endif
93
94 ifeq ($(CONFIG_RTE_LIBRTE_TABLE),y)
95 LDLIBS += -lrte_table
96 endif
97
98 ifeq ($(CONFIG_RTE_LIBRTE_PORT),y)
99 LDLIBS += -lrte_port
100 endif
101
102 ifeq ($(CONFIG_RTE_LIBRTE_TIMER),y)
103 LDLIBS += -lrte_timer
104 endif
105
106 ifeq ($(CONFIG_RTE_LIBRTE_HASH),y)
107 LDLIBS += -lrte_hash
108 endif
109
110 ifeq ($(CONFIG_RTE_LIBRTE_LPM),y)
111 LDLIBS += -lrte_lpm
112 endif
113
114 ifeq ($(CONFIG_RTE_LIBRTE_POWER),y)
115 LDLIBS += -lrte_power
116 endif
117
118 ifeq ($(CONFIG_RTE_LIBRTE_ACL),y)
119 LDLIBS += -lrte_acl
120 endif
121
122 ifeq ($(CONFIG_RTE_LIBRTE_METER),y)
123 LDLIBS += -lrte_meter
124 endif
125
126 ifeq ($(CONFIG_RTE_LIBRTE_SCHED),y)
127 LDLIBS += -lrte_sched
128 LDLIBS += -lm
129 LDLIBS += -lrt
130 endif
131
132 ifeq ($(CONFIG_RTE_LIBRTE_VHOST), y)
133 LDLIBS += -lrte_vhost
134 endif
135
136 endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS
137
138 ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
139 LDLIBS += -lpcap
140 endif
141
142 ifeq ($(CONFIG_RTE_LIBRTE_VHOST),y)
143 LDLIBS += -lfuse
144 endif
145
146 LDLIBS += --start-group
147
148 ifeq ($(CONFIG_RTE_BUILD_COMBINE_LIBS),n)
149
150 ifeq ($(CONFIG_RTE_LIBRTE_KVARGS),y)
151 LDLIBS += -lrte_kvargs
152 endif
153
154 ifeq ($(CONFIG_RTE_LIBRTE_MBUF),y)
155 LDLIBS += -lrte_mbuf
156 endif
157
158 ifeq ($(CONFIG_RTE_LIBRTE_IP_FRAG),y)
159 LDLIBS += -lrte_ip_frag
160 endif
161
162 ifeq ($(CONFIG_RTE_LIBRTE_ETHER),y)
163 LDLIBS += -lethdev
164 endif
165
166 ifeq ($(CONFIG_RTE_LIBRTE_MALLOC),y)
167 LDLIBS += -lrte_malloc
168 endif
169
170 ifeq ($(CONFIG_RTE_LIBRTE_MEMPOOL),y)
171 LDLIBS += -lrte_mempool
172 endif
173
174 ifeq ($(CONFIG_RTE_LIBRTE_RING),y)
175 LDLIBS += -lrte_ring
176 endif
177
178 ifeq ($(CONFIG_RTE_LIBRTE_EAL),y)
179 LDLIBS += -lrte_eal
180 endif
181
182 ifeq ($(CONFIG_RTE_LIBRTE_CMDLINE),y)
183 LDLIBS += -lrte_cmdline
184 endif
185
186 ifeq ($(CONFIG_RTE_LIBRTE_CFGFILE),y)
187 LDLIBS += -lrte_cfgfile
188 endif
189
190 ifeq ($(CONFIG_RTE_LIBRTE_PMD_BOND),y)
191 LDLIBS += -lrte_pmd_bond
192 endif
193
194 ifeq ($(CONFIG_RTE_LIBRTE_PMD_XENVIRT),y)
195 LDLIBS += -lrte_pmd_xenvirt
196 LDLIBS += -lxenstore
197 endif
198
199 ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),n)
200 # plugins (link only if static libraries)
201
202 ifeq ($(CONFIG_RTE_LIBRTE_VMXNET3_PMD),y)
203 LDLIBS += -lrte_pmd_vmxnet3_uio
204 endif
205
206 ifeq ($(CONFIG_RTE_LIBRTE_VIRTIO_PMD),y)
207 LDLIBS += -lrte_pmd_virtio_uio
208 endif
209
210 ifeq ($(CONFIG_RTE_LIBRTE_ENIC_PMD),y)
211 LDLIBS += -lrte_pmd_enic
212 endif
213
214 ifeq ($(CONFIG_RTE_LIBRTE_I40E_PMD),y)
215 LDLIBS += -lrte_pmd_i40e
216 endif
217
218 ifeq ($(CONFIG_RTE_LIBRTE_FM10K_PMD),y)
219 LDLIBS += -lrte_pmd_fm10k
220 endif
221
222 ifeq ($(CONFIG_RTE_LIBRTE_IXGBE_PMD),y)
223 LDLIBS += -lrte_pmd_ixgbe
224 endif
225
226 ifeq ($(CONFIG_RTE_LIBRTE_E1000_PMD),y)
227 LDLIBS += -lrte_pmd_e1000
228 endif
229
230 ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y)
231 LDLIBS += -lrte_pmd_ring
232 endif
233
234 ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
235 LDLIBS += -lrte_pmd_pcap
236 endif
237
238 ifeq ($(CONFIG_RTE_LIBRTE_PMD_AF_PACKET),y)
239 LDLIBS += -lrte_pmd_af_packet
240 endif
241
242 endif # plugins
243
244 endif # ! CONFIG_RTE_BUILD_COMBINE_LIBS
245
246 LDLIBS += $(EXECENV_LDLIBS)
247
248 LDLIBS += --end-group
249
250 LDLIBS += --no-whole-archive
251
252 endif # ifeq ($(NO_AUTOLIBS),)
253
254 LDLIBS += $(CPU_LDLIBS)
255
256 .PHONY: all
257 all: install
258
259 .PHONY: install
260 install: build _postinstall
261
262 _postinstall: build
263
264 .PHONY: build
265 build: _postbuild
266
267 exe2cmd = $(strip $(call dotfile,$(patsubst %,%.cmd,$(1))))
268
269 ifeq ($(LINK_USING_CC),1)
270 override EXTRA_LDFLAGS := $(call linkerprefix,$(EXTRA_LDFLAGS))
271 O_TO_EXE = $(CC) $(CFLAGS) $(LDFLAGS_$(@)) \
272         -Wl,-Map=$(@).map,--cref -o $@ $(OBJS-y) $(call linkerprefix,$(LDFLAGS)) \
273         $(EXTRA_LDFLAGS) $(call linkerprefix,$(LDLIBS))
274 else
275 O_TO_EXE = $(LD) $(LDFLAGS) $(LDFLAGS_$(@)) $(EXTRA_LDFLAGS) \
276         -Map=$(@).map --cref -o $@ $(OBJS-y) $(LDLIBS)
277 endif
278 O_TO_EXE_STR = $(subst ','\'',$(O_TO_EXE)) #'# fix syntax highlight
279 O_TO_EXE_DISP = $(if $(V),"$(O_TO_EXE_STR)","  LD $(@)")
280 O_TO_EXE_CMD = "cmd_$@ = $(O_TO_EXE_STR)"
281 O_TO_EXE_DO = @set -e; \
282         echo $(O_TO_EXE_DISP); \
283         $(O_TO_EXE) && \
284         echo $(O_TO_EXE_CMD) > $(call exe2cmd,$(@))
285
286 -include .$(APP).cmd
287
288 # path where libraries are retrieved
289 LDLIBS_PATH := $(subst -Wl$(comma)-L,,$(filter -Wl$(comma)-L%,$(LDLIBS)))
290 LDLIBS_PATH += $(subst -L,,$(filter -L%,$(LDLIBS)))
291
292 # list of .a files that are linked to this application
293 LDLIBS_NAMES := $(patsubst -l%,lib%.a,$(filter -l%,$(LDLIBS)))
294 LDLIBS_NAMES += $(patsubst -Wl$(comma)-l%,lib%.a,$(filter -Wl$(comma)-l%,$(LDLIBS)))
295
296 # list of found libraries files (useful for deps). If not found, the
297 # library is silently ignored and dep won't be checked
298 LDLIBS_FILES := $(wildcard $(foreach dir,$(LDLIBS_PATH),\
299         $(addprefix $(dir)/,$(LDLIBS_NAMES))))
300
301 #
302 # Compile executable file if needed
303 #
304 $(APP): $(OBJS-y) $(LDLIBS_FILES) $(DEP_$(APP)) $(LDSCRIPT) FORCE
305         @[ -d $(dir $@) ] || mkdir -p $(dir $@)
306         $(if $(D),\
307                 @echo -n "$< -> $@ " ; \
308                 echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
309                 echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_EXE_STR))) " ; \
310                 echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
311                 echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
312         $(if $(or \
313                 $(file_missing),\
314                 $(call cmdline_changed,$(O_TO_EXE_STR)),\
315                 $(depfile_missing),\
316                 $(depfile_newer)),\
317                 $(O_TO_EXE_DO))
318
319 #
320 # install app in $(RTE_OUTPUT)/app
321 #
322 $(RTE_OUTPUT)/app/$(APP): $(APP)
323         @echo "  INSTALL-APP $(APP)"
324         @[ -d $(RTE_OUTPUT)/app ] || mkdir -p $(RTE_OUTPUT)/app
325         $(Q)cp -f $(APP) $(RTE_OUTPUT)/app
326
327 #
328 # install app map file in $(RTE_OUTPUT)/app
329 #
330 $(RTE_OUTPUT)/app/$(APP).map: $(APP)
331         @echo "  INSTALL-MAP $(APP).map"
332         @[ -d $(RTE_OUTPUT)/app ] || mkdir -p $(RTE_OUTPUT)/app
333         $(Q)cp -f $(APP).map $(RTE_OUTPUT)/app
334
335 #
336 # Clean all generated files
337 #
338 .PHONY: clean
339 clean: _postclean
340         $(Q)rm -f $(_BUILD_TARGETS) $(_INSTALL_TARGETS) $(_CLEAN_TARGETS)
341
342 .PHONY: doclean
343 doclean:
344         $(Q)rm -rf $(APP) $(OBJS-all) $(DEPS-all) $(DEPSTMP-all) \
345           $(CMDS-all) $(INSTALL-FILES-all) .$(APP).cmd
346
347
348 include $(RTE_SDK)/mk/internal/rte.compile-post.mk
349 include $(RTE_SDK)/mk/internal/rte.install-post.mk
350 include $(RTE_SDK)/mk/internal/rte.clean-post.mk
351 include $(RTE_SDK)/mk/internal/rte.build-post.mk
352 include $(RTE_SDK)/mk/internal/rte.depdirs-post.mk
353
354 ifneq ($(wildcard $(RTE_SDK)/mk/target/$(RTE_TARGET)/rte.app.mk),)
355 include $(RTE_SDK)/mk/target/$(RTE_TARGET)/rte.app.mk
356 else
357 include $(RTE_SDK)/mk/target/generic/rte.app.mk
358 endif
359
360 .PHONY: FORCE
361 FORCE: