1 # SPDX-License-Identifier: BSD-3-Clause
2 # Copyright 2012-2013 6WIND S.A.
4 include $(RTE_SDK)/mk/internal/rte.compile-pre.mk
5 include $(RTE_SDK)/mk/internal/rte.install-pre.mk
6 include $(RTE_SDK)/mk/internal/rte.clean-pre.mk
7 include $(RTE_SDK)/mk/internal/rte.build-pre.mk
9 # VPATH contains at least SRCDIR
13 _INSTALL = $(INSTALL-FILES-y) $(SYMLINK-FILES-y) $(RTE_OUTPUT)/lib/$(SHARED)
16 # Set fPIC in CFLAGS for .so generation
23 install: build _postinstall
30 exe2cmd = $(strip $(call dotfile,$(patsubst %,%.cmd,$(1))))
32 ifeq ($(LINK_USING_CC),1)
33 override EXTRA_LDFLAGS := $(call linkerprefix,$(EXTRA_LDFLAGS))
34 O_TO_SO = $(CC) $(call linkerprefix,$(LDFLAGS)) $(LDFLAGS_$(@)) $(EXTRA_LDFLAGS) \
35 -shared -o $@ $(OBJS-y) $(call linkerprefix,$(LDLIBS))
37 O_TO_SO = $(LD) $(LDFLAGS) $(LDFLAGS_$(@)) $(EXTRA_LDFLAGS) \
38 -shared -o $@ $(OBJS-y) $(LDLIBS)
41 O_TO_SO_STR = $(subst ','\'',$(O_TO_SO)) #'# fix syntax highlight
42 O_TO_SO_DISP = $(if $(V),"$(O_TO_SO_STR)"," LD $(@)")
43 O_TO_SO_CMD = "cmd_$@ = $(O_TO_SO_STR)"
44 O_TO_SO_DO = @set -e; \
45 echo $(O_TO_SO_DISP); \
47 echo $(O_TO_SO_CMD) > $(call exe2cmd,$(@))
49 -include .$(SHARED).cmd
51 # path where libraries are retrieved
52 LDLIBS_PATH := $(subst -Wl$(comma)-L,,$(filter -Wl$(comma)-L%,$(LDLIBS)))
53 LDLIBS_PATH += $(subst -L,,$(filter -L%,$(LDLIBS)))
55 # list of .a files that are linked to this application
56 LDLIBS_NAMES := $(patsubst -l%,lib%.a,$(filter -l%,$(LDLIBS)))
57 LDLIBS_NAMES += $(patsubst -Wl$(comma)-l%,lib%.a,$(filter -Wl$(comma)-l%,$(LDLIBS)))
59 # list of found libraries files (useful for deps). If not found, the
60 # library is silently ignored and dep won't be checked
61 LDLIBS_FILES := $(sort $(wildcard $(foreach dir,$(LDLIBS_PATH),\
62 $(addprefix $(dir)/,$(LDLIBS_NAMES)))))
65 # Archive objects in .so file if needed
67 $(SHARED): $(OBJS-y) $(LDLIBS_FILES) $(DEP_$(SHARED)) FORCE
68 @[ -d $(dir $@) ] || mkdir -p $(dir $@)
70 @echo -n "$< -> $@ " ; \
71 echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
72 echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(O_TO_SO_STR))) " ; \
73 echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
74 echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
77 $(call cmdline_changed,$(O_TO_SO_STR)),\
83 # install lib in $(RTE_OUTPUT)/lib
85 $(RTE_OUTPUT)/lib/$(SHARED): $(SHARED)
86 @echo " INSTALL-SHARED $(SHARED)"
87 @[ -d $(RTE_OUTPUT)/lib ] || mkdir -p $(RTE_OUTPUT)/lib
88 $(Q)cp -f $(SHARED) $(RTE_OUTPUT)/lib
91 # Clean all generated files
98 $(Q)rm -rf $(SHARED) $(OBJS-all) $(DEPS-all) $(DEPSTMP-all) \
99 $(CMDS-all) $(INSTALL-FILES-all)
100 $(Q)rm -f $(_BUILD_TARGETS) $(_INSTALL_TARGETS) $(_CLEAN_TARGETS)
102 include $(RTE_SDK)/mk/internal/rte.compile-post.mk
103 include $(RTE_SDK)/mk/internal/rte.install-post.mk
104 include $(RTE_SDK)/mk/internal/rte.clean-post.mk
105 include $(RTE_SDK)/mk/internal/rte.build-post.mk