a974dc8bcc0341148b522dc168eb48ec5c221f33
[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_CMDLINE),y)
86 LDLIBS += -lrte_cmdline
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 ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
159 LDLIBS += -lrte_pmd_pcap -lpcap
160 endif
161
162 LDLIBS += $(EXECENV_LDLIBS)
163
164 LDLIBS += --end-group
165
166 endif # ifeq ($(NO_AUTOLIBS),)
167
168 LDLIBS += $(CPU_LDLIBS)
169
170 .PHONY: all
171 all: install
172
173 .PHONY: install
174 install: build _postinstall
175
176 _postinstall: build
177
178 .PHONY: build
179 build: _postbuild
180
181 exe2cmd = $(strip $(call dotfile,$(patsubst %,%.cmd,$(1))))
182
183 ifeq ($(RTE_BUILD_COMBINE_LIBS),y)
184 LDLIBS += -l$(RTE_LIBNAME)
185 endif
186
187 ifeq ($(LINK_USING_CC),1)
188 comma := ,
189 LDLIBS := $(addprefix -Wl$(comma),$(LDLIBS))
190 LDFLAGS := $(addprefix -Wl$(comma),$(LDFLAGS))
191 EXTRA_LDFLAGS := $(addprefix -Wl$(comma),$(EXTRA_LDFLAGS))
192 O_TO_EXE = $(CC) $(CFLAGS) $(LDFLAGS_$(@)) \
193         -Wl,-Map=$(@).map,--cref -o $@ $(OBJS-y) $(LDFLAGS) $(EXTRA_LDFLAGS) $(LDLIBS)
194 else
195 O_TO_EXE = $(LD) $(LDFLAGS) $(LDFLAGS_$(@)) $(EXTRA_LDFLAGS) \
196         -Map=$(@).map --cref -o $@ $(OBJS-y) $(LDLIBS)
197 endif
198 O_TO_EXE_STR = $(subst ','\'',$(O_TO_EXE)) #'# fix syntax highlight
199 O_TO_EXE_DISP = $(if $(V),"$(O_TO_EXE_STR)","  LD $(@)")
200 O_TO_EXE_CMD = "cmd_$@ = $(O_TO_EXE_STR)"
201 O_TO_EXE_DO = @set -e; \
202         echo $(O_TO_EXE_DISP); \
203         $(O_TO_EXE) && \
204         echo $(O_TO_EXE_CMD) > $(call exe2cmd,$(@))
205
206 -include .$(APP).cmd
207
208 # path where libraries are retrieved
209 LDLIBS_PATH := $(subst -Wl$(comma)-L,,$(filter -Wl$(comma)-L%,$(LDLIBS)))
210 LDLIBS_PATH += $(subst -L,,$(filter -L%,$(LDLIBS)))
211
212 # list of .a files that are linked to this application
213 LDLIBS_NAMES := $(patsubst -l%,lib%.a,$(filter -l%,$(LDLIBS)))
214 LDLIBS_NAMES += $(patsubst -Wl$(comma)-l%,lib%.a,$(filter -Wl$(comma)-l%,$(LDLIBS)))
215
216 # list of found libraries files (useful for deps). If not found, the
217 # library is silently ignored and dep won't be checked
218 LDLIBS_FILES := $(wildcard $(foreach dir,$(LDLIBS_PATH),\
219         $(addprefix $(dir)/,$(LDLIBS_NAMES))))
220
221 #
222 # Compile executable file if needed
223 #
224 $(APP): $(OBJS-y) $(LDLIBS_FILES) $(DEP_$(APP)) $(LDSCRIPT) FORCE
225         @[ -d $(dir $@) ] || mkdir -p $(dir $@)
226         $(if $(D),\
227                 @echo -n "$< -> $@ " ; \
228                 echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
229                 echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_EXE_STR))) " ; \
230                 echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
231                 echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
232         $(if $(or \
233                 $(file_missing),\
234                 $(call cmdline_changed,$(O_TO_EXE_STR)),\
235                 $(depfile_missing),\
236                 $(depfile_newer)),\
237                 $(O_TO_EXE_DO))
238
239 #
240 # install app in $(RTE_OUTPUT)/app
241 #
242 $(RTE_OUTPUT)/app/$(APP): $(APP)
243         @echo "  INSTALL-APP $(APP)"
244         @[ -d $(RTE_OUTPUT)/app ] || mkdir -p $(RTE_OUTPUT)/app
245         $(Q)cp -f $(APP) $(RTE_OUTPUT)/app
246
247 #
248 # install app map file in $(RTE_OUTPUT)/app
249 #
250 $(RTE_OUTPUT)/app/$(APP).map: $(APP)
251         @echo "  INSTALL-MAP $(APP).map"
252         @[ -d $(RTE_OUTPUT)/app ] || mkdir -p $(RTE_OUTPUT)/app
253         $(Q)cp -f $(APP).map $(RTE_OUTPUT)/app
254
255 #
256 # Clean all generated files
257 #
258 .PHONY: clean
259 clean: _postclean
260         $(Q)rm -f $(_BUILD_TARGETS) $(_INSTALL_TARGETS) $(_CLEAN_TARGETS)
261
262 .PHONY: doclean
263 doclean:
264         $(Q)rm -rf $(APP) $(OBJS-all) $(DEPS-all) $(DEPSTMP-all) \
265           $(CMDS-all) $(INSTALL-FILES-all) .$(APP).cmd
266
267
268 include $(RTE_SDK)/mk/internal/rte.compile-post.mk
269 include $(RTE_SDK)/mk/internal/rte.install-post.mk
270 include $(RTE_SDK)/mk/internal/rte.clean-post.mk
271 include $(RTE_SDK)/mk/internal/rte.build-post.mk
272 include $(RTE_SDK)/mk/internal/rte.depdirs-post.mk
273
274 ifneq ($(wildcard $(RTE_SDK)/mk/target/$(RTE_TARGET)/rte.app.mk),)
275 include $(RTE_SDK)/mk/target/$(RTE_TARGET)/rte.app.mk
276 else
277 include $(RTE_SDK)/mk/target/generic/rte.app.mk
278 endif
279
280 .PHONY: FORCE
281 FORCE: