8c054f0cbff76b90de77d0a4cb3799328b3fa886
[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_KNI),y)
65 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
66 LDLIBS += -lrte_kni
67 endif
68 endif
69
70 ifeq ($(CONFIG_RTE_LIBRTE_IVSHMEM),y)
71 ifeq ($(CONFIG_RTE_EXEC_ENV_LINUXAPP),y)
72 LDLIBS += -lrte_ivshmem
73 endif
74 endif
75
76 ifeq ($(CONFIG_RTE_LIBRTE_E1000_PMD),y)
77 LDLIBS += -lrte_pmd_e1000
78 endif
79
80 ifeq ($(CONFIG_RTE_LIBRTE_IXGBE_PMD),y)
81 LDLIBS += -lrte_pmd_ixgbe
82 endif
83
84 ifeq ($(CONFIG_RTE_LIBRTE_VIRTIO_PMD),y)
85 LDLIBS += -lrte_pmd_virtio_uio
86 endif
87
88 ifeq ($(CONFIG_RTE_LIBRTE_VMXNET3_PMD),y)
89 LDLIBS += -lrte_pmd_vmxnet3_uio
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 LDLIBS += --start-group
123
124 ifeq ($(CONFIG_RTE_LIBRTE_KVARGS),y)
125 LDLIBS += -lrte_kvargs
126 endif
127
128 ifeq ($(CONFIG_RTE_LIBRTE_MBUF),y)
129 LDLIBS += -lrte_mbuf
130 endif
131
132 ifeq ($(CONFIG_RTE_LIBRTE_ETHER),y)
133 LDLIBS += -lethdev
134 endif
135
136 ifeq ($(CONFIG_RTE_LIBRTE_PMD_RING),y)
137 LDLIBS += -lrte_pmd_ring
138 endif
139
140 ifeq ($(CONFIG_RTE_LIBRTE_MALLOC),y)
141 LDLIBS += -lrte_malloc
142 endif
143
144 ifeq ($(CONFIG_RTE_LIBRTE_MEMPOOL),y)
145 LDLIBS += -lrte_mempool
146 endif
147
148 ifeq ($(CONFIG_RTE_LIBRTE_RING),y)
149 LDLIBS += -lrte_ring
150 endif
151
152 ifeq ($(CONFIG_RTE_LIBC),y)
153 LDLIBS += -lc
154 LDLIBS += -lm
155 endif
156
157 ifeq ($(CONFIG_RTE_LIBGLOSS),y)
158 LDLIBS += -lgloss
159 endif
160
161 ifeq ($(CONFIG_RTE_LIBRTE_EAL),y)
162 LDLIBS += -lrte_eal
163 endif
164
165
166 ifeq ($(CONFIG_RTE_LIBRTE_PMD_XENVIRT),y)
167 LDLIBS += -lrte_pmd_xenvirt
168 LDLIBS += -lxenstore
169 endif
170
171 ifeq ($(CONFIG_RTE_LIBRTE_CMDLINE),y)
172 LDLIBS += -lrte_cmdline
173 endif
174
175 ifeq ($(RTE_BUILD_SHARED_LIB),n)
176 ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
177 LDLIBS += -lrte_pmd_pcap -lpcap
178 endif
179 endif
180
181 LDLIBS += $(EXECENV_LDLIBS)
182
183 LDLIBS += --end-group
184
185 LDLIBS += --no-whole-archive
186
187 endif # ifeq ($(NO_AUTOLIBS),)
188
189 LDLIBS += $(CPU_LDLIBS)
190
191 .PHONY: all
192 all: install
193
194 .PHONY: install
195 install: build _postinstall
196
197 _postinstall: build
198
199 .PHONY: build
200 build: _postbuild
201
202 exe2cmd = $(strip $(call dotfile,$(patsubst %,%.cmd,$(1))))
203
204 ifeq ($(RTE_BUILD_COMBINE_LIBS),y)
205 LDLIBS += -l$(RTE_LIBNAME)
206 endif
207
208 ifeq ($(LINK_USING_CC),1)
209 LDLIBS := $(call linkerprefix,$(LDLIBS))
210 LDFLAGS := $(call linkerprefix,$(LDFLAGS))
211 override EXTRA_LDFLAGS := $(call linkerprefix,$(EXTRA_LDFLAGS))
212 O_TO_EXE = $(CC) $(CFLAGS) $(LDFLAGS_$(@)) \
213         -Wl,-Map=$(@).map,--cref -o $@ $(OBJS-y) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDLIBS)
214 else
215 O_TO_EXE = $(LD) $(LDFLAGS) $(LDFLAGS_$(@)) $(EXTRA_LDFLAGS) \
216         -Map=$(@).map --cref -o $@ $(OBJS-y) $(LDLIBS)
217 endif
218 O_TO_EXE_STR = $(subst ','\'',$(O_TO_EXE)) #'# fix syntax highlight
219 O_TO_EXE_DISP = $(if $(V),"$(O_TO_EXE_STR)","  LD $(@)")
220 O_TO_EXE_CMD = "cmd_$@ = $(O_TO_EXE_STR)"
221 O_TO_EXE_DO = @set -e; \
222         echo $(O_TO_EXE_DISP); \
223         $(O_TO_EXE) && \
224         echo $(O_TO_EXE_CMD) > $(call exe2cmd,$(@))
225
226 -include .$(APP).cmd
227
228 # path where libraries are retrieved
229 LDLIBS_PATH := $(subst -Wl$(comma)-L,,$(filter -Wl$(comma)-L%,$(LDLIBS)))
230 LDLIBS_PATH += $(subst -L,,$(filter -L%,$(LDLIBS)))
231
232 # list of .a files that are linked to this application
233 LDLIBS_NAMES := $(patsubst -l%,lib%.a,$(filter -l%,$(LDLIBS)))
234 LDLIBS_NAMES += $(patsubst -Wl$(comma)-l%,lib%.a,$(filter -Wl$(comma)-l%,$(LDLIBS)))
235
236 # list of found libraries files (useful for deps). If not found, the
237 # library is silently ignored and dep won't be checked
238 LDLIBS_FILES := $(wildcard $(foreach dir,$(LDLIBS_PATH),\
239         $(addprefix $(dir)/,$(LDLIBS_NAMES))))
240
241 #
242 # Compile executable file if needed
243 #
244 $(APP): $(OBJS-y) $(LDLIBS_FILES) $(DEP_$(APP)) $(LDSCRIPT) FORCE
245         @[ -d $(dir $@) ] || mkdir -p $(dir $@)
246         $(if $(D),\
247                 @echo -n "$< -> $@ " ; \
248                 echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
249                 echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_EXE_STR))) " ; \
250                 echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
251                 echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
252         $(if $(or \
253                 $(file_missing),\
254                 $(call cmdline_changed,$(O_TO_EXE_STR)),\
255                 $(depfile_missing),\
256                 $(depfile_newer)),\
257                 $(O_TO_EXE_DO))
258
259 #
260 # install app in $(RTE_OUTPUT)/app
261 #
262 $(RTE_OUTPUT)/app/$(APP): $(APP)
263         @echo "  INSTALL-APP $(APP)"
264         @[ -d $(RTE_OUTPUT)/app ] || mkdir -p $(RTE_OUTPUT)/app
265         $(Q)cp -f $(APP) $(RTE_OUTPUT)/app
266
267 #
268 # install app map file in $(RTE_OUTPUT)/app
269 #
270 $(RTE_OUTPUT)/app/$(APP).map: $(APP)
271         @echo "  INSTALL-MAP $(APP).map"
272         @[ -d $(RTE_OUTPUT)/app ] || mkdir -p $(RTE_OUTPUT)/app
273         $(Q)cp -f $(APP).map $(RTE_OUTPUT)/app
274
275 #
276 # Clean all generated files
277 #
278 .PHONY: clean
279 clean: _postclean
280         $(Q)rm -f $(_BUILD_TARGETS) $(_INSTALL_TARGETS) $(_CLEAN_TARGETS)
281
282 .PHONY: doclean
283 doclean:
284         $(Q)rm -rf $(APP) $(OBJS-all) $(DEPS-all) $(DEPSTMP-all) \
285           $(CMDS-all) $(INSTALL-FILES-all) .$(APP).cmd
286
287
288 include $(RTE_SDK)/mk/internal/rte.compile-post.mk
289 include $(RTE_SDK)/mk/internal/rte.install-post.mk
290 include $(RTE_SDK)/mk/internal/rte.clean-post.mk
291 include $(RTE_SDK)/mk/internal/rte.build-post.mk
292 include $(RTE_SDK)/mk/internal/rte.depdirs-post.mk
293
294 ifneq ($(wildcard $(RTE_SDK)/mk/target/$(RTE_TARGET)/rte.app.mk),)
295 include $(RTE_SDK)/mk/target/$(RTE_TARGET)/rte.app.mk
296 else
297 include $(RTE_SDK)/mk/target/generic/rte.app.mk
298 endif
299
300 .PHONY: FORCE
301 FORCE: