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