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