1
0

package.mk 11 KB

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