GlueMapWindowOverlays: adjust ThermalBand and FinalGlideBar sizing
[xcsoar.git] / build / link.mk
blobe213514a181a009bea390cf1a5f6544b1bda3cf6
1 LINK = $(CXX)
3 # Generates a program linking rule.
5 # Example: $(eval $(call link-program,Foo,FOO))
7 # Arguments: NAME, PREFIX
9 # NAME is the name of the program binary, without the path and without
10 # the suffix (.exe).
12 # PREFIX is a prefix for variables that will hold detailed information
13 # about what is linked, and now. These must be set before this
14 # generator function is called. The following variables will be used:
16 # _SOURCES: a list of source files
18 # _CPPFLAGS: preprocessor flags for the compiler
20 # _LDADD: a list of static libraries that will be linked into the binary
22 # _LDFLAGS: linker flags
24 # _DEPENDS: a list of library names this executable depends on; it
25 # will use its CPPFLAGS, LDADD and LDFLAGS
27 # _STRIP: if "y", then the program will be stripped
29 define link-program
31 $(2)_BIN = $$(TARGET_BIN_DIR)/$(1)$$(TARGET_EXEEXT)
33 # Disabline stripping on WINE, because winegcc generates a wrapper
34 # script that cannot be stripped, and since WINE is just an
35 # experimental target and no binaries will ever be distributed, it
36 # doesn't matter anyway.
37 ifeq ($$(TARGET),WINE)
38 $(2)_STRIP := n
39 endif
41 # Disable stripping on UNIX, because that should usually be done
42 # during installation (the Debian package is explicitly stripped), and
43 # we often need the debug symbols while developing.
44 ifeq ($$(TARGET),UNIX)
45 $(2)_STRIP := n
46 endif
48 ifeq ($$($(2)_STRIP),y)
49 $(2)_NOSTRIP = $$(TARGET_BIN_DIR)/$(1)-ns$$(TARGET_EXEEXT)
50 else
51 $(2)_NOSTRIP = $$($(2)_BIN)
52 endif
54 $(2)_LDADD += $(patsubst %,$$(%_LDADD),$($(2)_DEPENDS))
55 $(2)_LDLIBS += $(patsubst %,$$(%_LDLIBS),$($(2)_DEPENDS))
57 # Compile
58 $(2)_OBJS = $$(call SRC_TO_OBJ,$$($(2)_SOURCES))
59 $$($(2)_OBJS): CPPFLAGS += $$($(2)_CPPFLAGS)
60 $$($(2)_OBJS): CPPFLAGS += $(patsubst %,$$(%_CPPFLAGS),$($(2)_DEPENDS))
62 ifeq ($$(LLVM),y)
64 # Link all LLVM bitcode files together
65 $$($(2)_NOSTRIP).bc: $$($(2)_OBJS) $$($(2)_LDADD) | $$(TARGET_BIN_DIR)/dirstamp
66 @$$(NQ)echo " LINK $$@"
67 $$(Q)llvm-link -o $$@ $$^
69 # Optimise the large bitcode file
70 $$($(2)_NOSTRIP)-opt.bc: $$($(2)_NOSTRIP).bc
71 @$$(NQ)echo " OPT $$@"
72 $$(Q)opt -o $$@ $$^ -std-compile-opts -std-link-opts -O2
74 # Compile to native CPU assembly
75 $$($(2)_NOSTRIP).s: $$($(2)_NOSTRIP)-opt.bc
76 @$$(NQ)echo " LLC $$@"
77 $$(Q)llc -o $$@ $$^ -O2
79 # Link the unstripped binary
80 $$($(2)_NOSTRIP): $$($(2)_NOSTRIP).s $$(TARGET_LDADD)
81 @$$(NQ)echo " CLANG $$@"
82 $$(Q)$$(LINK) $$(LDFLAGS) -o $$@ $$^ $$(LDLIBS) $$($(2)_LDLIBS)
83 else
85 # Link the unstripped binary
86 $$($(2)_NOSTRIP): $$($(2)_OBJS) $$($(2)_LDADD) $$(TARGET_LDADD) | $$(TARGET_BIN_DIR)/dirstamp
87 @$$(NQ)echo " LINK $$@"
88 $$(Q)$$(LINK) $$(LDFLAGS) $$(TARGET_ARCH) -o $$@ $$^ $$(LDLIBS) $$($(2)_LDLIBS)
90 endif
92 # Strip the binary (optional)
93 ifeq ($$($(2)_STRIP),y)
94 $$($(2)_BIN): $$($(2)_NOSTRIP)
95 @$$(NQ)echo " STRIP $$@"
96 $$(Q)$$(STRIP) $$< -o $$@
97 endif
99 endef
103 # Generates a shared library linking rule.
105 # Example: $(eval $(call link-shared-library,Foo,FOO))
107 # Arguments: NAME, PREFIX
109 # NAME is the name of the library binary, without the path, without
110 # the prefix (lib) and without the suffix (.exe).
112 # PREFIX is a prefix for variables that will hold detailed information
113 # about what is linked, and now. These must be set before this
114 # generator function is called. The following variables will be used:
116 # _SOURCES: a list of source files
118 # _CPPFLAGS: preprocessor flags for the compiler
120 # _LDADD: a list of static libraries that will be linked into the binary
122 # _LDFLAGS: linker flags
124 # _DEPENDS: a list of library names this executable depends on; it
125 # will use its CPPFLAGS, LDADD and LDFLAGS
127 # _STRIP: if "y", then the library will be stripped
129 define link-shared-library
131 $(2)_BIN = $$(TARGET_BIN_DIR)/lib$(1).so
133 ifeq ($$($(2)_STRIP),y)
134 $(2)_NOSTRIP = $$(TARGET_BIN_DIR)/lib$(1)-ns.so
135 else
136 $(2)_NOSTRIP = $$($(2)_BIN)
137 endif
139 $(2)_LDADD += $(patsubst %,$$(%_LDADD),$($(2)_DEPENDS))
140 $(2)_LDLIBS += $(patsubst %,$$(%_LDLIBS),$($(2)_DEPENDS))
142 # Compile
143 $(2)_OBJS = $$(call SRC_TO_OBJ,$$($(2)_SOURCES))
144 $$($(2)_OBJS): CPPFLAGS += $$($(2)_CPPFLAGS)
145 $$($(2)_OBJS): CPPFLAGS += $(patsubst %,$$(%_CPPFLAGS),$($(2)_DEPENDS))
147 # Link the unstripped binary
148 $$($(2)_NOSTRIP): LDFLAGS += -Wl,-shared,-Bsymbolic
149 ifeq ($$(TARGET),ANDROID)
150 $$($(2)_NOSTRIP): LDFLAGS += -nostdlib
151 endif
152 $$($(2)_NOSTRIP): $$($(2)_OBJS) $$($(2)_LDADD) $$(TARGET_LDADD) | $$(TARGET_BIN_DIR)/dirstamp
153 @$$(NQ)echo " LINK $$@"
154 $$(Q)$$(LINK) $$(LDFLAGS) $$(TARGET_ARCH) -o $$@ $$^ $$(LDLIBS) $$($(2)_LDLIBS)
156 # Strip the binary (optional)
157 ifeq ($$($(2)_STRIP),y)
158 $$($(2)_BIN): $$($(2)_NOSTRIP)
159 @$$(NQ)echo " STRIP $$@"
160 $$(Q)$$(STRIP) $$< -o $$@
161 endif
163 endef
166 # Generates a static library linking rule.
168 # Example: $(eval $(call link-library,foo,FOO))
170 # Arguments: NAME, PREFIX
171 define link-library
173 ifeq ($$(LLVM),y)
174 $(2)_BIN = $$(TARGET_OUTPUT_DIR)/$(1).bc
175 else
176 $(2)_BIN = $$(TARGET_OUTPUT_DIR)/$(1).a
177 endif
179 # Compile
180 $(2)_OBJS = $$(call SRC_TO_OBJ,$$($(2)_SOURCES))
181 $$($(2)_OBJS): CFLAGS += $$($(2)_CFLAGS)
182 $$($(2)_OBJS): CXXFLAGS += $$($(2)_CXXFLAGS)
183 $$($(2)_OBJS): CPPFLAGS += $$($(2)_CPPFLAGS) $$($(2)_CPPFLAGS_INTERNAL)
184 $$($(2)_OBJS): CPPFLAGS += $(patsubst %,$$(%_CPPFLAGS),$($(2)_DEPENDS))
186 # Link
187 $$($(2)_BIN): $$($(2)_OBJS)
188 ifeq ($$(LLVM),y)
189 @$$(NQ)echo " LINK $$@"
190 $$(Q)llvm-link -o $$@ $$^
191 else
192 @$$(NQ)echo " AR $$@"
193 $$(Q)$$(AR) $$(ARFLAGS) $$@ $$^
194 endif
196 $(2)_LIBS = $$($(2)_BIN)
197 $(2)_LDADD = $$($(2)_BIN)
199 endef