package.mk 9.2 KB

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