compat: add infrastructure to support symbol versioning
[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 # VPATH contains at least SRCDIR
39 VPATH += $(SRCDIR)
40
41 ifeq ($(RTE_BUILD_SHARED_LIB),y)
42 LIB := $(patsubst %.a,%.so,$(LIB))
43
44 CPU_LDFLAGS += --version-script=$(SRCDIR)/$(EXPORT_MAP)
45
46 endif
47
48
49 _BUILD = $(LIB)
50 _INSTALL = $(INSTALL-FILES-y) $(SYMLINK-FILES-y) $(RTE_OUTPUT)/lib/$(LIB)
51 _CLEAN = doclean
52
53 .PHONY: all
54 all: install
55
56 .PHONY: install
57 install: build _postinstall
58
59 _postinstall: build
60
61 .PHONY: build
62 build: _postbuild
63
64 exe2cmd = $(strip $(call dotfile,$(patsubst %,%.cmd,$(1))))
65
66 ifeq ($(LINK_USING_CC),1)
67 # Override the definition of LD here, since we're linking with CC
68 LD := $(CC) $(CPU_CFLAGS)
69 _CPU_LDFLAGS := $(call linkerprefix,$(CPU_LDFLAGS))
70 else
71 _CPU_LDFLAGS := $(CPU_LDFLAGS)
72 endif
73
74 O_TO_A = $(AR) crus $(LIB) $(OBJS-y)
75 O_TO_A_STR = $(subst ','\'',$(O_TO_A)) #'# fix syntax highlight
76 O_TO_A_DISP = $(if $(V),"$(O_TO_A_STR)","  AR $(@)")
77 O_TO_A_CMD = "cmd_$@ = $(O_TO_A_STR)"
78 O_TO_A_DO = @set -e; \
79         echo $(O_TO_A_DISP); \
80         $(O_TO_A) && \
81         echo $(O_TO_A_CMD) > $(call exe2cmd,$(@))
82
83 O_TO_S = $(LD) $(_CPU_LDFLAGS) -shared $(OBJS-y) -o $(LIB)
84 O_TO_S_STR = $(subst ','\'',$(O_TO_S)) #'# fix syntax highlight
85 O_TO_S_DISP = $(if $(V),"$(O_TO_S_STR)","  LD $(@)")
86 O_TO_S_DO = @set -e; \
87         echo $(O_TO_S_DISP); \
88         $(O_TO_S) && \
89         echo $(O_TO_S_CMD) > $(call exe2cmd,$(@))
90
91 ifeq ($(RTE_BUILD_SHARED_LIB),n)
92 O_TO_C = $(AR) crus $(LIB_ONE) $(OBJS-y)
93 O_TO_C_STR = $(subst ','\'',$(O_TO_C)) #'# fix syntax highlight
94 O_TO_C_DISP = $(if $(V),"$(O_TO_C_STR)","  AR_C $(@)")
95 O_TO_C_DO = @set -e; \
96         $(lib_dir) \
97         $(copy_obj)
98 else
99 O_TO_C = $(LD) -shared $(OBJS-y) -o $(LIB_ONE)
100 O_TO_C_STR = $(subst ','\'',$(O_TO_C)) #'# fix syntax highlight
101 O_TO_C_DISP = $(if $(V),"$(O_TO_C_STR)","  LD_C $(@)")
102 O_TO_C_DO = @set -e; \
103         $(lib_dir) \
104         $(copy_obj)
105 endif
106
107 copy_obj = cp -f $(OBJS-y) $(RTE_OUTPUT)/build/lib;
108 lib_dir = [ -d $(RTE_OUTPUT)/lib ] || mkdir -p $(RTE_OUTPUT)/lib;
109 -include .$(LIB).cmd
110
111 #
112 # Archive objects in .a file if needed
113 #
114 ifeq ($(RTE_BUILD_SHARED_LIB),y)
115 $(LIB): $(OBJS-y) $(DEP_$(LIB)) FORCE
116         @[ -d $(dir $@) ] || mkdir -p $(dir $@)
117         $(if $(D),\
118                 @echo -n "$< -> $@ " ; \
119                 echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
120                 echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_S_STR))) " ; \
121                 echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
122                 echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
123         $(if $(or \
124                 $(file_missing),\
125                 $(call cmdline_changed,$(O_TO_S_STR)),\
126                 $(depfile_missing),\
127                 $(depfile_newer)),\
128                 $(O_TO_S_DO))
129 ifeq ($(RTE_BUILD_COMBINE_LIBS),y)
130         $(if $(or \
131         $(file_missing),\
132         $(call cmdline_changed,$(O_TO_C_STR)),\
133         $(depfile_missing),\
134         $(depfile_newer)),\
135         $(O_TO_C_DO))
136 endif
137 else
138 $(LIB): $(OBJS-y) $(DEP_$(LIB)) FORCE
139         @[ -d $(dir $@) ] || mkdir -p $(dir $@)
140         $(if $(D),\
141             @echo -n "$< -> $@ " ; \
142             echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
143             echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_A_STR))) " ; \
144             echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
145             echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
146         $(if $(or \
147             $(file_missing),\
148             $(call cmdline_changed,$(O_TO_A_STR)),\
149             $(depfile_missing),\
150             $(depfile_newer)),\
151             $(O_TO_A_DO))
152 ifeq ($(RTE_BUILD_COMBINE_LIBS),y)
153         $(if $(or \
154         $(file_missing),\
155         $(call cmdline_changed,$(O_TO_C_STR)),\
156         $(depfile_missing),\
157         $(depfile_newer)),\
158         $(O_TO_C_DO))
159 endif
160 endif
161
162 #
163 # install lib in $(RTE_OUTPUT)/lib
164 #
165 $(RTE_OUTPUT)/lib/$(LIB): $(LIB)
166         @echo "  INSTALL-LIB $(LIB)"
167         @[ -d $(RTE_OUTPUT)/lib ] || mkdir -p $(RTE_OUTPUT)/lib
168         $(Q)cp -f $(LIB) $(RTE_OUTPUT)/lib
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) $(INSTALL-FILES-all)
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: