1
0

package.mk 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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
  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. # should be package format independent and modular in the future
  94. define PKG_template
  95. ALL_PKGOPTS+= $(1)
  96. PKGNAME_$(1)= $(2)
  97. PKGDEPS_$(1)= $(4)
  98. PKGDESC_$(1)= $(5)
  99. PKGSECT_$(1)= $(6)
  100. IPKG_$(1)= $(PACKAGE_DIR)/$(2)_$(3)_${CPU_ARCH}.${PKG_SUFFIX}
  101. IDIR_$(1)= $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(2)
  102. ifneq (${ADK_PACKAGE_$(1)},)
  103. ALL_IPKGS+= $$(IPKG_$(1))
  104. ALL_IDIRS+= $${IDIR_$(1)}
  105. ALL_POSTINST+= $(2)-install
  106. $(2)-install:
  107. endif
  108. INFO_$(1)= $(PKG_STATE_DIR)/info/$(2).list
  109. ifeq ($(ADK_PACKAGE_$(1)),y)
  110. install-targets: $$(INFO_$(1))
  111. endif
  112. IDEPEND_$(1):= $$(strip $(4))
  113. _ALL_CONTROLS+= $$(IDIR_$(1))/CONTROL/control
  114. ICONTROL_$(1)?= $(WRKDIR)/.$(2).control
  115. $$(IDIR_$(1))/CONTROL/control: ${_PATCH_COOKIE}
  116. @echo "Package: $$(shell echo $(2) | tr '_' '-')" > $(WRKDIR)/.$(2).control
  117. @echo "Section: $(6)" >> $(WRKDIR)/.$(2).control
  118. @echo "Description: $(5)" >> $(WRKDIR)/.$(2).control
  119. ${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)} $${ICONTROL_$(1)} $(3) ${CPU_ARCH}
  120. @adeps='$$(strip $${IDEPEND_$(1)})'; if [[ -n $$$$adeps ]]; then \
  121. comma=; \
  122. deps=; \
  123. last=; \
  124. for dep in $$$$adeps; do \
  125. if [[ $$$$last = kernel && $$$$dep = \(* ]]; then \
  126. deps="$$$$deps $$$$dep"; \
  127. else \
  128. deps="$$$$deps$$$$comma$$$$dep"; \
  129. fi; \
  130. comma=", "; \
  131. last=$$$$dep; \
  132. done; \
  133. echo "Depends: $$$$deps" | tr '_' '-' >>$${IDIR_$(1)}/CONTROL/control; \
  134. fi
  135. @for file in conffiles preinst postinst prerm postrm; do \
  136. [ ! -f ./files/$(2).$$$$file ] || cp ./files/$(2).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file; \
  137. done
  138. $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $${_FAKE_COOKIE}
  139. ifeq ($(ADK_DEBUG),)
  140. $${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
  141. endif
  142. ifeq ($(ADK_DEBUG_STRIP),y)
  143. $${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
  144. endif
  145. ifeq (${ADK_LEAVE_ETC_ALONE}$(filter force_etc,$(7)),y)
  146. -rm -rf $${IDIR_$(1)}/etc
  147. else
  148. ifeq (${ADK_INSTALL_PACKAGE_INIT_SCRIPTS},y)
  149. @for file in $$$$(ls ./files/*.init 2>/dev/null); do \
  150. fname=$$$$(echo $$$$file| sed -e "s#.*/##" -e "s#.init##"); \
  151. check=$$$$(grep PKG $$$$file|cut -d ' ' -f 2); \
  152. if [ "$$$$check" == $(2) ];then \
  153. mkdir -p $$(IDIR_$(1))/etc/init.d && cp $$$$file $$(IDIR_$(1))/etc/init.d/$$$$fname; \
  154. fi; \
  155. done
  156. @cd $${IDIR_$(1)}; for script in etc/init.d/*; do \
  157. [[ -e $$$$script ]] || continue; \
  158. chmod 0755 "$$$$script"; \
  159. done
  160. endif
  161. ifneq (${ADK_INSTALL_PACKAGE_NETWORK_SCRIPTS},y)
  162. -rm -rf $${IDIR_$(1)}/etc/network
  163. endif
  164. endif
  165. @mkdir -p $${PACKAGE_DIR} '$${STAGING_PKG_DIR}' \
  166. '$${STAGING_DIR}/scripts'
  167. ifeq (,$(filter noremove,$(7)))
  168. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  169. cd '$${STAGING_DIR}'; \
  170. while read fn; do \
  171. rm -f "$$$$fn"; \
  172. done <'$${STAGING_PKG_DIR}/$(1)'; \
  173. fi
  174. endif
  175. @rm -f '$${STAGING_PKG_DIR}/$(1)'
  176. -@cd $${IDIR_$(1)}; \
  177. x=$$$$(find tmp var -mindepth 1 2>/dev/null); if [[ -n $$$$x ]]; then \
  178. echo 'WARNING: $${IPKG_$(1)} installs files into a' \
  179. 'ramdisk location:' >&2; \
  180. echo "$$$$x" | sed 's/^/- /' >&2; \
  181. fi; \
  182. 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" ];then \
  183. find lib \( -name lib\*.so\* -o -name lib\*.a \) \
  184. -exec echo 'WARNING: $${IPKG_$(1)} installs files in /lib -' \
  185. ' fix this!' >&2 \; -quit 2>/dev/null; fi; \
  186. find usr ! -type d 2>/dev/null | \
  187. 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' | \
  188. tee '$${STAGING_PKG_DIR}/$(1)' | \
  189. $(TOOLS_DIR)/cpio -padlmu '$${STAGING_DIR}'
  190. @cd '$${STAGING_DIR}'; grep 'usr/lib/.*\.la$$$$' \
  191. '$${STAGING_PKG_DIR}/$(1)' | while read fn; do \
  192. chmod u+w $$$$fn; \
  193. $(SED) "s,\(^libdir='\| \|-L\|^dependency_libs='\)/usr/lib,\1$(STAGING_TARGET_DIR)/usr/lib,g" $$$$fn; \
  194. done
  195. ifeq (,$(filter noscripts,$(7)))
  196. @cd '$${STAGING_TARGET_DIR}'; grep 'usr/s*bin/' \
  197. '$${STAGING_PKG_DIR}/$(1)' | \
  198. while read fn; do \
  199. b="$$$$(dd if="$$$$fn" bs=2 count=1 2>/dev/null)"; \
  200. [[ $$$$b = '#!' ]] || continue; \
  201. cp "$$$$fn" scripts/; \
  202. echo "scripts/$$$$(basename "$$$$fn")" \
  203. >>'$${STAGING_PKG_DIR}/$(1)'; \
  204. done
  205. endif
  206. ifeq (,$(filter libmix,$(7)))
  207. ifeq (,$(filter libonly,$(7)))
  208. $${PKG_BUILD} $${IDIR_$(1)} $${PACKAGE_DIR} $(MAKE_TRACE)
  209. endif
  210. endif
  211. clean-targets: clean-dev-$(1)
  212. clean-dev-$(1):
  213. ifeq (,$(filter noremove,$(7)))
  214. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  215. cd '$${STAGING_DIR}'; \
  216. while read fn; do \
  217. rm -f "$$$$fn"; \
  218. done <'$${STAGING_PKG_DIR}/$(1)'; \
  219. fi
  220. endif
  221. rm -f '$${STAGING_PKG_DIR}/$(1)'
  222. $$(INFO_$(1)): $$(IPKG_$(1))
  223. $(PKG_INSTALL) $$(IPKG_$(1))
  224. endef
  225. install-targets:
  226. install:
  227. @$(CMD_TRACE) "installing... "
  228. @$(MAKE) install-targets $(MAKE_TRACE)
  229. clean-targets:
  230. clean:
  231. @$(CMD_TRACE) "cleaning... "
  232. @$(MAKE) clean-targets $(MAKE_TRACE)
  233. rm -rf ${WRKDIR} ${ALL_IPKGS} ${PACKAGE_DIR}/.stamps/${PKG_NAME}*
  234. distclean: clean
  235. rm -f ${FULLDISTFILES}
  236. .PHONY: all refetch extract patch configure \
  237. build rebuild fake package install clean build-all-pkgs