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
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
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
)
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
)
51 ifeq ($$($(2)_STRIP
),y
)
52 $(2)_NOSTRIP
= $$(TARGET_BIN_DIR
)/$(1)-ns
$$(TARGET_EXEEXT
)
54 $(2)_NOSTRIP
= $$($(2)_BIN
)
57 $(2)_LDADD
+= $(patsubst %,$$(%_LDADD
),$($(2)_DEPENDS
))
58 $(2)_LDLIBS
+= $(patsubst %,$$(%_LDLIBS
),$($(2)_DEPENDS
))
61 $(2)_OBJS
= $$(call SRC_TO_OBJ
,$$($(2)_SOURCES
))
62 $$($(2)_OBJS
): CPPFLAGS
+= $$($(2)_CPPFLAGS
)
63 $$($(2)_OBJS
): CPPFLAGS
+= $(patsubst %,$$(%_CPPFLAGS
),$($(2)_DEPENDS
))
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
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
)
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
)
100 # Strip the binary (optional)
101 ifeq ($$($(2)_STRIP
),y
)
102 $$($(2)_BIN
): $$($(2)_NOSTRIP
)
103 @
$$(NQ
)echo
" STRIP $$@"
104 $$(Q
)$$(STRIP
) $$< -o
$$@
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
144 $(2)_NOSTRIP
= $$($(2)_BIN
)
147 $(2)_LDADD
+= $(patsubst %,$$(%_LDADD
),$($(2)_DEPENDS
))
148 $(2)_LDLIBS
+= $(patsubst %,$$(%_LDLIBS
),$($(2)_DEPENDS
))
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
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
$$@
174 # Generates a static library linking rule.
176 # Example: $(eval $(call link-library,foo,FOO))
178 # Arguments: NAME, PREFIX
182 $(2)_BIN
= $$(TARGET_OUTPUT_DIR
)/$(1).bc
184 $(2)_BIN
= $$(TARGET_OUTPUT_DIR
)/$(1).a
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
))
195 $$($(2)_BIN
): $$($(2)_OBJS
)
197 @
$$(NQ
)echo
" LINK $$@"
198 $$(Q
)llvm-link
-o
$$@
$$^
200 @
$$(NQ
)echo
" AR $$@"
201 $$(Q
)$$(AR
) $$(ARFLAGS
) $$@
$$^
204 $(2)_LIBS
= $$($(2)_BIN
)
205 $(2)_LDADD
= $$($(2)_BIN
)