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