5b72475d23cbb0995234703ddfa03203e5c16fc6
[dpdk.git] / mk / rte.lib.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 EXTLIB_BUILD ?= n
39
40 # VPATH contains at least SRCDIR
41 VPATH += $(SRCDIR)
42
43 ifneq ($(CONFIG_RTE_MAJOR_ABI),)
44 ifneq ($(LIBABIVER),)
45 LIBABIVER := $(CONFIG_RTE_MAJOR_ABI)
46 endif
47 endif
48
49 ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y)
50 LIB := $(patsubst %.a,%.so.$(LIBABIVER),$(LIB))
51 ifeq ($(EXTLIB_BUILD),n)
52 ifeq ($(CONFIG_RTE_MAJOR_ABI),)
53 ifeq ($(CONFIG_RTE_NEXT_ABI),y)
54 LIB := $(LIB).1
55 endif
56 endif
57 CPU_LDFLAGS += --version-script=$(SRCDIR)/$(EXPORT_MAP)
58 endif
59 endif
60
61
62 _BUILD = $(LIB)
63 _INSTALL = $(INSTALL-FILES-y) $(SYMLINK-FILES-y) $(RTE_OUTPUT)/lib/$(LIB)
64 _CLEAN = doclean
65
66 .PHONY: all
67 all: install
68
69 .PHONY: install
70 install: build _postinstall
71
72 _postinstall: build
73
74 .PHONY: build
75 build: _postbuild
76
77 exe2cmd = $(strip $(call dotfile,$(patsubst %,%.cmd,$(1))))
78
79 ifeq ($(LINK_USING_CC),1)
80 # Override the definition of LD here, since we're linking with CC
81 LD := $(CC) $(CPU_CFLAGS)
82 _CPU_LDFLAGS := $(call linkerprefix,$(CPU_LDFLAGS))
83 override EXTRA_LDFLAGS := $(call linkerprefix,$(EXTRA_LDFLAGS))
84 else
85 _CPU_LDFLAGS := $(CPU_LDFLAGS)
86 endif
87
88 # Translate DEPDIRS-y into LDLIBS
89 # Ignore (sub)directory dependencies which do not provide an actual library
90 _IGNORE_DIRS = lib/librte_eal/% lib/librte_compat
91 _DEPDIRS = $(filter-out $(_IGNORE_DIRS),$(DEPDIRS-y))
92 _LDDIRS = $(subst librte_ether,librte_ethdev,$(_DEPDIRS))
93 LDLIBS += $(subst lib/lib,-l,$(_LDDIRS))
94
95 O_TO_A = $(AR) crDs $(LIB) $(OBJS-y)
96 O_TO_A_STR = $(subst ','\'',$(O_TO_A)) #'# fix syntax highlight
97 O_TO_A_DISP = $(if $(V),"$(O_TO_A_STR)","  AR $(@)")
98 O_TO_A_CMD = "cmd_$@ = $(O_TO_A_STR)"
99 O_TO_A_DO = @set -e; \
100         echo $(O_TO_A_DISP); \
101         $(O_TO_A) && \
102         echo $(O_TO_A_CMD) > $(call exe2cmd,$(@))
103
104 ifneq ($(CC_SUPPORTS_Z),false)
105 NO_UNDEFINED := -z defs
106 endif
107
108 O_TO_S = $(LD) -L$(RTE_SDK_BIN)/lib $(_CPU_LDFLAGS) $(EXTRA_LDFLAGS) \
109           -shared $(OBJS-y) $(NO_UNDEFINED) $(LDLIBS) -Wl,-soname,$(LIB) -o $(LIB)
110 O_TO_S_STR = $(subst ','\'',$(O_TO_S)) #'# fix syntax highlight
111 O_TO_S_DISP = $(if $(V),"$(O_TO_S_STR)","  LD $(@)")
112 O_TO_S_DO = @set -e; \
113         echo $(O_TO_S_DISP); \
114         $(O_TO_S) && \
115         echo $(O_TO_S_CMD) > $(call exe2cmd,$(@))
116
117 -include .$(LIB).cmd
118
119 #
120 # Archive objects in .a file if needed
121 #
122 ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y)
123 $(LIB): $(OBJS-y) $(DEP_$(LIB)) FORCE
124 ifeq ($(LIBABIVER),)
125         @echo "Must Specify a $(LIB) ABI version"
126         @false
127 endif
128         @[ -d $(dir $@) ] || mkdir -p $(dir $@)
129         $(if $(D),\
130                 @echo -n "$< -> $@ " ; \
131                 echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
132                 echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_S_STR))) " ; \
133                 echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
134                 echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
135         $(if $(or \
136                 $(file_missing),\
137                 $(call cmdline_changed,$(O_TO_S_STR)),\
138                 $(depfile_missing),\
139                 $(depfile_newer)),\
140                 $(O_TO_S_DO))
141
142 else
143 $(LIB): $(OBJS-y) $(DEP_$(LIB)) FORCE
144         @[ -d $(dir $@) ] || mkdir -p $(dir $@)
145         $(if $(D),\
146             @echo -n "$< -> $@ " ; \
147             echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
148             echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_A_STR))) " ; \
149             echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
150             echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
151         $(if $(or \
152             $(file_missing),\
153             $(call cmdline_changed,$(O_TO_A_STR)),\
154             $(depfile_missing),\
155             $(depfile_newer)),\
156             $(O_TO_A_DO))
157 endif
158
159 #
160 # install lib in $(RTE_OUTPUT)/lib
161 #
162 $(RTE_OUTPUT)/lib/$(LIB): $(LIB)
163         @echo "  INSTALL-LIB $(LIB)"
164         @[ -d $(RTE_OUTPUT)/lib ] || mkdir -p $(RTE_OUTPUT)/lib
165         $(Q)cp -f $(LIB) $(RTE_OUTPUT)/lib
166 ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y)
167         $(Q)ln -s -f $< $(shell echo $@ | sed 's/\.so.*/.so/')
168 endif
169
170 #
171 # Clean all generated files
172 #
173 .PHONY: clean
174 clean: _postclean
175
176 .PHONY: doclean
177 doclean:
178         $(Q)rm -rf $(LIB) $(OBJS-all) $(DEPS-all) $(DEPSTMP-all) \
179           $(CMDS-all) .$(LIB).cmd $(INSTALL-FILES-all) *.pmd.c *.pmd.o
180         $(Q)rm -f $(_BUILD_TARGETS) $(_INSTALL_TARGETS) $(_CLEAN_TARGETS)
181
182 include $(RTE_SDK)/mk/internal/rte.compile-post.mk
183 include $(RTE_SDK)/mk/internal/rte.install-post.mk
184 include $(RTE_SDK)/mk/internal/rte.clean-post.mk
185 include $(RTE_SDK)/mk/internal/rte.build-post.mk
186 include $(RTE_SDK)/mk/internal/rte.depdirs-post.mk
187
188 .PHONY: FORCE
189 FORCE: