package.mk 8.6 KB

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