Replay/CatmullRomInterpolator: add header guards
[xcsoar.git] / build / link.mk
blob4280e9a3a1cc4ae3407f776e816d4ac314577be3
1 LINK = $(CXX)
3 ld-flags = $(ALL_LDFLAGS) $(TARGET_ARCH)
4 ld-libs = $(ALL_LDLIBS)
6 # Generates a program linking rule.
8 # Example: $(eval $(call link-program,Foo,FOO))
10 # Arguments: NAME, PREFIX
12 # NAME is the name of the program binary, without the path and without
13 # the suffix (.exe).
15 # PREFIX is a prefix for variables that will hold detailed information
16 # about what is linked, and now. These must be set before this
17 # generator function is called. The following variables will be used:
19 # _SOURCES: a list of source files
21 # _CPPFLAGS: preprocessor flags for the compiler
23 # _LDADD: a list of static libraries that will be linked into the binary
25 # _LDFLAGS: linker flags
27 # _DEPENDS: a list of library names this executable depends on; it
28 # will use its CPPFLAGS, LDADD and LDFLAGS
30 # _STRIP: if "y", then the program will be stripped
32 define link-program
34 $(2)_BIN = $$(TARGET_BIN_DIR)/$(1)$$(TARGET_EXEEXT)
36 # Disabline stripping on WINE, because winegcc generates a wrapper
37 # script that cannot be stripped, and since WINE is just an
38 # experimental target and no binaries will ever be distributed, it
39 # doesn't matter anyway.
40 ifeq ($$(TARGET),WINE)
41 $(2)_STRIP := n
42 endif
44 # Disable stripping on UNIX, because that should usually be done
45 # during installation (the Debian package is explicitly stripped), and
46 # we often need the debug symbols while developing.
47 ifeq ($$(TARGET),UNIX)
48 $(2)_STRIP := n
49 endif
51 ifeq ($$($(2)_STRIP),y)
52 $(2)_NOSTRIP = $$(TARGET_BIN_DIR)/$(1)-ns$$(TARGET_EXEEXT)
53 else
54 $(2)_NOSTRIP = $$($(2)_BIN)
55 endif
57 $(2)_LDADD += $(patsubst %,$$(%_LDADD),$($(2)_DEPENDS))
58 $(2)_LDLIBS += $(patsubst %,$$(%_LDLIBS),$($(2)_DEPENDS))
60 # Compile
61 $(2)_OBJS = $$(call SRC_TO_OBJ,$$($(2)_SOURCES))
62 $$($(2)_OBJS): CPPFLAGS += $$($(2)_CPPFLAGS)
63 $$($(2)_OBJS): CPPFLAGS += $(patsubst %,$$(%_CPPFLAGS),$($(2)_DEPENDS))
65 ifeq ($$(LLVM),y)
67 # Link all LLVM bitcode files together
68 $$($(2)_NOSTRIP).bc: $$($(2)_OBJS) $$($(2)_LDADD) | $$(TARGET_BIN_DIR)/dirstamp
69 @$$(NQ)echo " LINK $$@"
70 $$(Q)llvm-link -o $$@ $$^
72 # Optimise the large bitcode file
73 $$($(2)_NOSTRIP)-opt.bc: $$($(2)_NOSTRIP).bc
74 @$$(NQ)echo " OPT $$@"
75 $$(Q)opt -o $$@ $$^ -std-compile-opts -std-link-opts -O2 $(TARGET_LLVM_FLAGS)
77 # Compile to native CPU assembly
78 $$($(2)_NOSTRIP).s: $$($(2)_NOSTRIP)-opt.bc
79 @$$(NQ)echo " LLC $$@"
80 $$(Q)llc -o $$@ $$^ -O2 $(TARGET_LLVM_FLAGS)
82 # Assemble to native CPU object
83 $$($(2)_NOSTRIP).o: $$($(2)_NOSTRIP).s
84 @$$(NQ)echo " AS $$@"
85 $$(Q)$(AS) -o $$@ $$^
87 # Link the unstripped binary
88 $$($(2)_NOSTRIP): $$($(2)_NOSTRIP).o $$(TARGET_LDADD)
89 @$$(NQ)echo " CLANG $$@"
90 $$(Q)$$(LINK) $$(ld-flags) -o $$@ $$^ $$(ld-libs) $$($(2)_LDLIBS)
91 else
93 # Link the unstripped binary
94 $$($(2)_NOSTRIP): $$($(2)_OBJS) $$($(2)_LDADD) $$(TARGET_LDADD) | $$(TARGET_BIN_DIR)/dirstamp
95 @$$(NQ)echo " LINK $$@"
96 $$(Q)$$(LINK) $$(ld-flags) -o $$@ $$^ $$(ld-libs) $$($(2)_LDLIBS)
98 endif
100 # Strip the binary (optional)
101 ifeq ($$($(2)_STRIP),y)
102 $$($(2)_BIN): $$($(2)_NOSTRIP)
103 @$$(NQ)echo " STRIP $$@"
104 $$(Q)$$(STRIP) $$< -o $$@
105 endif
107 endef
111 # Generates a shared library linking rule.
113 # Example: $(eval $(call link-shared-library,Foo,FOO))
115 # Arguments: NAME, PREFIX
117 # NAME is the name of the library binary, without the path, without
118 # the prefix (lib) and without the suffix (.exe).
120 # PREFIX is a prefix for variables that will hold detailed information
121 # about what is linked, and now. These must be set before this
122 # generator function is called. The following variables will be used:
124 # _SOURCES: a list of source files
126 # _CPPFLAGS: preprocessor flags for the compiler
128 # _LDADD: a list of static libraries that will be linked into the binary
130 # _LDFLAGS: linker flags
132 # _DEPENDS: a list of library names this executable depends on; it
133 # will use its CPPFLAGS, LDADD and LDFLAGS
135 # _STRIP: if "y", then the library will be stripped
137 define link-shared-library
139 $(2)_BIN = $$(TARGET_BIN_DIR)/lib$(1).so
141 ifeq ($$($(2)_STRIP),y)
142 $(2)_NOSTRIP = $$(TARGET_BIN_DIR)/lib$(1)-ns.so
143 else
144 $(2)_NOSTRIP = $$($(2)_BIN)
145 endif
147 $(2)_LDADD += $(patsubst %,$$(%_LDADD),$($(2)_DEPENDS))
148 $(2)_LDLIBS += $(patsubst %,$$(%_LDLIBS),$($(2)_DEPENDS))
150 # Compile
151 $(2)_OBJS = $$(call SRC_TO_OBJ,$$($(2)_SOURCES))
152 $$($(2)_OBJS): CPPFLAGS += $$($(2)_CPPFLAGS)
153 $$($(2)_OBJS): CPPFLAGS += $(patsubst %,$$(%_CPPFLAGS),$($(2)_DEPENDS))
155 # Link the unstripped binary
156 $$($(2)_NOSTRIP): LDFLAGS += -Wl,-shared,-Bsymbolic
157 ifeq ($$(TARGET),ANDROID)
158 $$($(2)_NOSTRIP): LDFLAGS += -nostdlib
159 endif
160 $$($(2)_NOSTRIP): $$($(2)_OBJS) $$($(2)_LDADD) $$(TARGET_LDADD) | $$(TARGET_BIN_DIR)/dirstamp
161 @$$(NQ)echo " LINK $$@"
162 $$(Q)$$(LINK) $$(ld-flags) -o $$@ $$^ $$(ld-libs) $$($(2)_LDLIBS)
164 # Strip the binary (optional)
165 ifeq ($$($(2)_STRIP),y)
166 $$($(2)_BIN): $$($(2)_NOSTRIP)
167 @$$(NQ)echo " STRIP $$@"
168 $$(Q)$$(STRIP) $$< -o $$@
169 endif
171 endef
174 # Generates a static library linking rule.
176 # Example: $(eval $(call link-library,foo,FOO))
178 # Arguments: NAME, PREFIX
179 define link-library
181 ifeq ($$(LLVM),y)
182 $(2)_BIN = $$(TARGET_OUTPUT_DIR)/$(1).bc
183 else
184 $(2)_BIN = $$(TARGET_OUTPUT_DIR)/$(1).a
185 endif
187 # Compile
188 $(2)_OBJS = $$(call SRC_TO_OBJ,$$($(2)_SOURCES))
189 $$($(2)_OBJS): CFLAGS += $$($(2)_CFLAGS) $$($(2)_CFLAGS_INTERNAL)
190 $$($(2)_OBJS): CXXFLAGS += $$($(2)_CXXFLAGS) $$($(2)_CXXFLAGS_INTERNAL)
191 $$($(2)_OBJS): CPPFLAGS += $$($(2)_CPPFLAGS) $$($(2)_CPPFLAGS_INTERNAL)
192 $$($(2)_OBJS): CPPFLAGS += $(patsubst %,$$(%_CPPFLAGS),$($(2)_DEPENDS))
194 # Link
195 $$($(2)_BIN): $$($(2)_OBJS)
196 ifeq ($$(LLVM),y)
197 @$$(NQ)echo " LINK $$@"
198 $$(Q)llvm-link -o $$@ $$^
199 else
200 @$$(NQ)echo " AR $$@"
201 $$(Q)$$(AR) $$(ARFLAGS) $$@ $$^
202 endif
204 $(2)_LIBS = $$($(2)_BIN)
205 $(2)_LDADD = $$($(2)_BIN)
207 endef