musl: update to 1.1.18
[openadk.git] / mk / package.mk
blob88dcaadb7bafbc9a7b7d56cf764486f6b330524c
1 # This file is part of the OpenADK project. OpenADK is copyrighted
2 # material, please see the LICENCE file in the top-level directory.
4 all: build-all-pkgs
6 # does not change CONFIGURE_ARGS in minimal mode
7 ifeq ($(filter minimal,${CONFIG_STYLE}),)
8 ifneq ($(ADK_DEBUG),)
9 CONFIGURE_ARGS+= --enable-debug
10 endif
11 endif
13 AUTOTOOL_ENV+= PATH='${HOST_PATH}' \
14 PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig:${STAGING_TARGET_DIR}/usr/share/pkgconfig' \
15 PKG_CONFIG_SYSROOT_DIR='${STAGING_TARGET_DIR}' \
16 ${COMMON_ENV}
18 CONFIGURE_ENV+= PATH='${TARGET_PATH}' \
19 ${COMMON_ENV} \
20 ${TARGET_ENV} \
21 PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig:${STAGING_TARGET_DIR}/usr/share/pkgconfig' \
22 PKG_CONFIG_SYSROOT_DIR='${STAGING_TARGET_DIR}' \
23 cross_compiling=yes
25 CONFIGURE_PROG?= configure
26 MAKE_FILE?= Makefile
27 # this is environment for 'make all' and 'make install'
28 MAKE_ENV?=
29 # this is arguments for 'make all' and 'make install'
30 XAKE_FLAGS?=
31 # this is arguments for 'make all' ONLY
32 MAKE_FLAGS?=
33 # this is arguments for 'make install' ONLY
34 FAKE_FLAGS?=
35 ALL_TARGET?= all
36 INSTALL_TARGET?= install
38 MAKE_ENV+= PATH='${TARGET_PATH}' \
39 ${COMMON_ENV} \
40 ${TARGET_ENV} \
41 PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig:${STAGING_TARGET_DIR}/usr/share/pkgconfig' \
42 PKG_CONFIG_SYSROOT_DIR='${STAGING_TARGET_DIR}' \
43 WRKDIR='${WRKDIR}' WRKDIST='${WRKDIST}' \
44 WRKSRC='${WRKSRC}' WRKBUILD='${WRKBUILD}'
46 MAKE_FLAGS+= ${XAKE_FLAGS}
47 FAKE_FLAGS+= ${XAKE_FLAGS}
49 ifeq ($(strip ${WRKDIR_BSD}),)
50 WRKDIR_BASE:= ${BUILD_DIR}
51 else
52 WRKDIR_BASE:= $(shell pwd)
53 endif
55 _EXTRACT_COOKIE= ${WRKDIST}/.extract_done
56 _PATCH_COOKIE= ${WRKDIST}/.prepared
57 _CONFIGURE_COOKIE= ${WRKBUILD}/.configure_done
58 _BUILD_COOKIE= ${WRKBUILD}/.build_done
59 _FAKE_COOKIE= ${WRKINST}/.fake_done
60 _IPKGS_COOKIE= ${STAGING_PKG_DIR}/stamps/${PKG_NAME}\x01${PKG_VERSION}-${PKG_RELEASE}
62 _IN_PACKAGE:= 1
63 include ${ADK_TOPDIR}/mk/buildhlp.mk
65 # defined in buildhlp.mk ('extract' can fail, use 'patch' then)
66 extract: ${_EXTRACT_COOKIE}
67 patch: ${_PATCH_COOKIE}
69 # defined below (will be moved to pkg-bottom.mk!)
70 configure: ${_CONFIGURE_COOKIE}
71 build: ${_BUILD_COOKIE}
72 fake: ${_FAKE_COOKIE}
74 # our recursive build entry point
75 build-all-pkgs: ${_IPKGS_COOKIE}
77 # there are some parameters to the PKG_template function
78 # 1.) Config.in identifier ADK_PACKAGE_$(1)
79 # 2.) name of the package, for single package mostly $(PKG_NAME)
80 # 3.) package version (upstream version) and package release (adk version),
81 # always $(PKG_VERSION)-$(PKG_RELEASE)
82 # 4.) dependencies to other packages, $(PKG_DEPENDS)
83 # 5.) description for the package, $(PKG_DESCR)
84 # 6.) section of the package, $(PKG_SECTION)
85 # 7.) special package options $(PKG_OPTS)
86 # noscripts -> do not install scripts to $(STAGING_TARGET_DIR)/scripts
87 # (needed for example for autoconf/automake)
88 # noremove -> do not remove files from $(STAGING_TARGET_DIR) while
89 # cleaning (needed for toolchain packages like glibc)
90 # nostaging -> do not install files to $(STAGING_TARGET_DIR)
91 # nostrip -> do not strip files
92 # dev -> create a development subpackage with headers and pkg-config files
93 # devonly -> create a development package only
94 # should be package format independent and modular in the future
95 define PKG_template
96 ALL_PKGOPTS+= $(1)
97 PKGNAME_$(1)= $(2)
98 PKGDEPS_$(1)= $(4)
99 PKGDESC_$(1)= $(5)
100 PKGSECT_$(1)= $(6)
101 IPKG_$(1)= $(PACKAGE_DIR)/$(2)_$(3)_${ADK_TARGET_CPU_ARCH}.${PKG_SUFFIX}
102 IPKG_$(1)_DEV= $(PACKAGE_DIR)/$(2)-dev_$(3)_${ADK_TARGET_CPU_ARCH}.${PKG_SUFFIX}
103 IPKG_$(1)_DBG= $(PACKAGE_DIR)/$(2)-dbg_$(3)_${ADK_TARGET_CPU_ARCH}.${PKG_SUFFIX}
104 IDIR_$(1)= $(WRKDIR)/fake-${ADK_TARGET_CPU_ARCH}/pkg-$(2)
105 IDIR_$(1)_DEV= $(WRKDIR)/fake-${ADK_TARGET_CPU_ARCH}/pkg-$(2)-dev
106 IDIR_$(1)_DBG= $(WRKDIR)/fake-${ADK_TARGET_CPU_ARCH}/pkg-$(2)-dbg
107 ifneq (${ADK_PACKAGE_$(1)}${DEVELOPER},)
108 ifneq (,$(filter dev,$(7)))
109 ifneq ($(ADK_TARGET_USE_STATIC_LIBS_ONLY),y)
110 ifneq ($(ADK_TARGET_BINFMT_FLAT),y)
111 ALL_IPKGS+= $$(IPKG_$(1))
112 ALL_IDIRS+= $${IDIR_$(1)}
113 ALL_POSTINST+= $(2)-install
114 $(2)-install:
115 endif
116 endif
117 else
118 ALL_IPKGS+= $$(IPKG_$(1))
119 ALL_IDIRS+= $${IDIR_$(1)}
120 ALL_POSTINST+= $(2)-install
121 $(2)-install:
122 endif
123 endif
124 INFO_$(1)= $(PKG_STATE_DIR)/info/$(2).list
125 INFO_$(1)_DEV= $(PKG_STATE_DIR)/info/$(2)-dev.list
126 INFO_$(1)_DBG= $(PKG_STATE_DIR)/info/$(2)-dbg.list
128 ifeq ($(ADK_PACKAGE_$(1)),y)
130 ifeq (,$(filter devonly,$(7)))
131 ifeq ($(ADK_PACKAGE_$(1)_DBG),y)
132 install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DBG)
133 ifeq ($(ADK_PACKAGE_$(1)_DEV),y)
134 install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DBG) $$(INFO_$(1)_DEV)
135 else
136 install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DBG)
137 endif
138 else
139 ifeq ($(ADK_PACKAGE_$(1)_DEV),y)
140 install-targets: $$(INFO_$(1)) $$(INFO_$(1)_DEV)
141 else
142 install-targets: $$(INFO_$(1))
143 endif
144 endif
145 else
146 install-targets: $$(INFO_$(1))
147 endif
149 endif
151 IDEPEND_$(1):= $$(strip $(4))
153 _ALL_CONTROLS+= $$(IDIR_$(1))/CONTROL/control
154 ICONTROL_$(1)?= $(WRKDIR)/.$(2).control
155 ICONTROL_$(1)_DEV?= $(WRKDIR)/.$(2)-dev.control
156 ICONTROL_$(1)_DBG?= $(WRKDIR)/.$(2)-dbg.control
157 $$(IDIR_$(1))/CONTROL/control: ${_PATCH_COOKIE}
158 @echo "Package: $$(shell echo $(2) | tr '_' '-')" > $(WRKDIR)/.$(2).control
159 @echo "Section: $(6)" >> $(WRKDIR)/.$(2).control
160 @echo "Description: $(5)" >> $(WRKDIR)/.$(2).control
161 @${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)} $${ICONTROL_$(1)} $(3) ${ADK_TARGET_CPU_ARCH}
162 @adeps='$$(strip $${IDEPEND_$(1)})'; if [[ -n $$$$adeps ]]; then \
163 comma=; \
164 deps=; \
165 last=; \
166 for dep in $$$$adeps; do \
167 if [[ $$$$last = kernel && $$$$dep = \(* ]]; then \
168 deps="$$$$deps $$$$dep"; \
169 else \
170 deps="$$$$deps$$$$comma$$$$dep"; \
171 fi; \
172 comma=", "; \
173 last=$$$$dep; \
174 done; \
175 echo "Depends: $$$$deps" | tr '_' '-' >>$${IDIR_$(1)}/CONTROL/control; \
177 @for file in conffiles preinst postinst prerm postrm; do \
178 [ ! -f ./files/$(2).$$$$file ] || cp ./files/$(2).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file; \
179 done
180 ifeq ($(ADK_BUILD_WITH_DEBUG),y)
181 @echo "Package: $$(shell echo $(2) | tr '_' '-')-dbg" > $(WRKDIR)/.$(2)-dbg.control
182 @echo "Section: debug" >> $(WRKDIR)/.$(2)-dbg.control
183 @echo "Description: debugging symbols for $(2)" >> $(WRKDIR)/.$(2)-dbg.control
184 @${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)_DBG} $${ICONTROL_$(1)_DBG} $(3) ${ADK_TARGET_CPU_ARCH}
185 @echo "Depends: $$(shell echo $(2) | tr '_' '-')" >> $${IDIR_$(1)_DBG}/CONTROL/control
186 endif
187 ifneq (,$(filter dev,$(7)))
188 @echo "Package: $$(shell echo $(2) | tr '_' '-')-dev" > $(WRKDIR)/.$(2)-dev.control
189 @echo "Section: devel" >> $(WRKDIR)/.$(2)-dev.control
190 @echo "Description: development files for $(2)" >> $(WRKDIR)/.$(2)-dev.control
191 @${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)_DEV} $${ICONTROL_$(1)_DEV} $(3) ${ADK_TARGET_CPU_ARCH}
192 @echo "Depends: $$(shell echo $(2) | tr '_' '-')" >> $${IDIR_$(1)_DEV}/CONTROL/control
193 endif
195 $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $${_FAKE_COOKIE}
196 ifeq (,$(filter nostrip,$(7)))
197 ifeq ($(ADK_DEBUG),)
198 @$${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
199 endif
200 ifeq ($(ADK_DEBUG_STRIP),y)
201 @$${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
202 endif
203 endif
204 ifeq (${ADK_LEAVE_ETC_ALONE}$(filter force_etc,$(7)),y)
205 -rm -rf $${IDIR_$(1)}/etc
206 else
207 ifeq (${ADK_INSTALL_PACKAGE_INIT_SCRIPTS},y)
208 @for file in $$$$(ls ./files/*.init 2>/dev/null); do \
209 fname=$$$$(echo $$$$file| sed -e "s#.*/##" -e "s#.init##"); \
210 check=$$$$(grep PKG $$$$file|cut -d ' ' -f 2); \
211 if [ "$$$$check" == $(2) ];then \
212 mkdir -p $$(IDIR_$(1))/etc/init.d && cp $$$$file $$(IDIR_$(1))/etc/init.d/$$$$fname; \
213 fi; \
214 done
215 @cd $${IDIR_$(1)}; for script in etc/init.d/*; do \
216 [[ -e $$$$script ]] || continue; \
217 chmod 0755 "$$$$script"; \
218 done
219 endif
220 ifneq (${ADK_INSTALL_PACKAGE_NETWORK_SCRIPTS},y)
221 -@rm -rf $${IDIR_$(1)}/etc/network
222 endif
223 ifeq (${ADK_RUNTIME_INIT_SYSTEMD},y)
224 @for file in $$$$(ls ./files/*.service 2>/dev/null); do \
225 fname=$$$$(echo $$$$file| sed -e "s#.*/##"); \
226 mkdir -p $$(IDIR_$(1))/usr/lib/systemd/system && cp $$$$file $$(IDIR_$(1))/usr/lib/systemd/system/$$$$fname; \
227 mkdir -p $$(IDIR_$(1))/etc/systemd/system/multi-user.target.wants; \
228 ln -sf ../../../../usr/lib/systemd/system/$$$$fname \
229 $$(IDIR_$(1))/etc/systemd/system/multi-user.target.wants; \
230 done
231 endif
232 endif
233 @mkdir -p $${PACKAGE_DIR} '$${STAGING_PKG_DIR}/stamps' \
234 '$${STAGING_TARGET_DIR}/scripts'
235 @for file in $$$$(ls ./files/*.perm 2>/dev/null); do \
236 cat $$$$file >> $${STAGING_TARGET_DIR}/scripts/permissions.sh; \
237 done
238 ifeq (,$(filter noremove,$(7)))
239 @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
240 cd '$${STAGING_TARGET_DIR}'; \
241 while read fn; do \
242 rm -f "$$$$fn"; \
243 done <'$${STAGING_PKG_DIR}/$(1)'; \
245 endif
246 @rm -f '$${STAGING_PKG_DIR}/$(1)'
247 ifeq (,$(filter nostaging,$(7)))
248 @-cd $${IDIR_$(1)}; \
249 x=$$$$(find tmp run -mindepth 1 2>/dev/null); if [[ -n $$$$x ]]; then \
250 echo 'WARNING: $${IPKG_$(1)} installs files into a' \
251 'ramdisk location:' >&2; \
252 echo "$$$$x" | sed 's/^/- /' >&2; \
253 fi; \
254 find usr ! -type d 2>/dev/null | \
255 grep -E -v -e '^usr/lib/pkgconfig' -e '^usr/share' -e '^usr/doc' -e '^usr/src' -e '^usr/man' \
256 -e '^usr/info' -e '^usr/lib/libc.so' -e '^usr/bin/[a-z0-9-]+-config' -e '^usr/lib/.*\.la$$$$' | \
257 tee '$${STAGING_PKG_DIR}/$(1)' | \
258 $(CPIO) -padlmu --quiet '$${STAGING_TARGET_DIR}'
259 endif
260 ifeq (,$(filter noscripts,$(7)))
261 @cd '$${STAGING_TARGET_DIR}'; grep 'usr/s*bin/' \
262 '$${STAGING_PKG_DIR}/$(1)' | \
263 while read fn; do \
264 b="$$$$(dd if="$$$$fn" bs=2 count=1 2>/dev/null)"; \
265 [[ $$$$b = '#!' ]] || continue; \
266 cp "$$$$fn" scripts/; \
267 echo "scripts/$$$$(basename "$$$$fn")" \
268 >>'$${STAGING_PKG_DIR}/$(1)'; \
269 done
270 endif
272 ifeq (,$(filter devonly,$(7)))
273 PATH='$(HOST_PATH)' $${PKG_BUILD} $${IDIR_$(1)} $${PACKAGE_DIR} $(MAKE_TRACE)
274 ifneq ($(ADK_BUILD_WITH_DEBUG),)
275 PATH='$(HOST_PATH)' $${PKG_BUILD} $${IDIR_$(1)_DBG} $${PACKAGE_DIR} $(MAKE_TRACE)
276 endif
277 endif
278 ifneq (,$(filter dev,$(7)))
279 PATH='$(HOST_PATH)' $${PKG_BUILD} $${IDIR_$(1)_DEV} $${PACKAGE_DIR} $(MAKE_TRACE)
280 endif
282 clean-targets: clean-dev-$(1)
284 clean-dev-$(1):
285 ifeq (,$(filter noremove,$(7)))
286 @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
287 cd '$${STAGING_TARGET_DIR}'; \
288 while read fn; do \
289 rm -f "$$$$fn"; \
290 done <'$${STAGING_PKG_DIR}/$(1)'; \
292 endif
293 @rm -f '$${STAGING_PKG_DIR}/$(1)'
295 $$(INFO_$(1)): $$(IPKG_$(1))
296 $(PKG_INSTALL) $$(IPKG_$(1))
298 $$(INFO_$(1)_DBG): $$(IPKG_$(1)_DBG)
299 $(PKG_INSTALL) $$(IPKG_$(1)_DBG)
301 ifneq ($(1),UCLIBC_NG)
302 ifneq ($(1),GLIBC)
303 ifneq ($(1),MUSL)
304 $$(INFO_$(1)_DEV): $$(IPKG_$(1)_DEV)
305 $(PKG_INSTALL) $$(IPKG_$(1)_DEV)
306 endif
307 endif
308 endif
310 endef
312 install-targets:
313 install:
314 @$(CMD_TRACE) "installing.. "
315 @$(MAKE) install-targets $(MAKE_TRACE)
317 clean-targets:
318 clean:
319 @printf " ---> cleaning package build directories and files.. "
320 @$(MAKE) clean-targets $(MAKE_TRACE)
321 rm -rf ${WRKDIR} ${ALL_IPKGS} ${_IPKGS_COOKIE}
322 @printf " done\n"
324 distclean: clean
325 rm -f ${FULLDISTFILES}
327 .PHONY: all refetch extract patch configure \
328 build fake package install clean build-all-pkgs