package.mk 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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_TARGET_DIR}/usr/lib \
  9. -L${STAGING_TARGET_DIR}/lib -L${STAGING_TARGET_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_TARGET_DIR}/usr/lib \
  16. -L${STAGING_TARGET_DIR}/lib -L${STAGING_TARGET_DIR}/usr/lib \
  17. -static
  18. endif
  19. ifeq ($(ADK_NATIVE),y)
  20. TCFLAGS:= $(TARGET_CFLAGS_ARCH) $(TARGET_DEBUGGING) -fwrapv
  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_TARGET_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+= PKG_CONFIG_LIBDIR='${STAGING_TARGET_DIR}/usr/lib/pkgconfig'
  65. ifeq ($(ADK_NATIVE),)
  66. MAKE_ENV+= PATH='${TARGET_PATH}' \
  67. ${HOST_CONFIGURE_OPTS} \
  68. CC='${TARGET_CC}' \
  69. CXX='${TARGET_CXX}' \
  70. AR='${TARGET_CROSS}ar' \
  71. RANLIB='${TARGET_CROSS}ranlib' \
  72. NM='${TARGET_CROSS}nm' \
  73. STRIP='${TARGET_CROSS}strip' \
  74. CROSS="$(TARGET_CROSS)"
  75. endif
  76. MAKE_FLAGS+= ${XAKE_FLAGS} V=1
  77. FAKE_FLAGS+= ${XAKE_FLAGS}
  78. ifeq ($(strip ${WRKDIR_BSD}),)
  79. WRKDIR_BASE:= ${BUILD_DIR}
  80. else
  81. WRKDIR_BASE:= $(shell pwd)
  82. endif
  83. _EXTRACT_COOKIE= ${WRKDIST}/.extract_done
  84. _PATCH_COOKIE= ${WRKDIST}/.prepared
  85. _CONFIGURE_COOKIE= ${WRKBUILD}/.configure_done
  86. _BUILD_COOKIE= ${WRKBUILD}/.build_done
  87. _FAKE_COOKIE= ${WRKINST}/.fake_done
  88. _IPKGS_COOKIE= ${PACKAGE_DIR}/.stamps/${PKG_NAME}${PKG_VERSION}-${PKG_RELEASE}
  89. _IN_PACKAGE:= 1
  90. include ${TOPDIR}/mk/buildhlp.mk
  91. # defined in buildhlp.mk ('extract' can fail, use 'patch' then)
  92. extract: ${_EXTRACT_COOKIE}
  93. patch: ${_PATCH_COOKIE}
  94. # defined below (will be moved to pkg-bottom.mk!)
  95. configure: ${_CONFIGURE_COOKIE}
  96. build: ${_BUILD_COOKIE}
  97. fake: ${_FAKE_COOKIE}
  98. rebuild:
  99. @if [ -f ${TOPDIR}/.rebuild.${PKG_NAME} ];then \
  100. $(MAKE) clean; \
  101. rm -f ${TOPDIR}/.rebuild.${PKG_NAME}; \
  102. fi
  103. # our recursive build entry point
  104. build-all-pkgs: ${_IPKGS_COOKIE}
  105. # there are some parameters to the PKG_template function
  106. # 1.) Config.in identifier ADK_PACKAGE_$(1)
  107. # 2.) name of the package, for single package mostly $(PKG_NAME)
  108. # 3.) package version (upstream version) and package release (adk version),
  109. # always $(PKG_VERSION)-$(PKG_RELEASE)
  110. # 4.) dependencies to other packages, $(PKG_DEPENDS)
  111. # 5.) description for the package, $(PKG_DESCR)
  112. # 6.) section of the package, $(PKG_SECTION)
  113. # 7.) special package options
  114. # noscripts -> do not install scripts to $(STAGING_TARGET_DIR)/target/scripts
  115. # (needed for example for autoconf/automake)
  116. # noremove -> do not remove files from $(STAGING_TARGET_DIR)/target while
  117. # cleaning (needed for toolchain packages like glibc/eglibc)
  118. # should be package format independent and modular in the future
  119. define PKG_template
  120. ALL_PKGOPTS+= $(1)
  121. PKGNAME_$(1)= $(2)
  122. PKGDEPS_$(1)= $(4)
  123. PKGDESC_$(1)= $(5)
  124. PKGSECT_$(1)= $(6)
  125. IPKG_$(1)= $(PACKAGE_DIR)/$(2)_$(3)_${CPU_ARCH}.${PKG_SUFFIX}
  126. IDIR_$(1)= $(WRKDIR)/fake-${CPU_ARCH}/pkg-$(2)
  127. ifneq (${ADK_PACKAGE_$(1)}${DEVELOPER},)
  128. ALL_IPKGS+= $$(IPKG_$(1))
  129. ALL_IDIRS+= $${IDIR_$(1)}
  130. endif
  131. INFO_$(1)= $(PKG_STATE_DIR)/info/$(2).list
  132. ifeq ($(ADK_PACKAGE_$(1)),y)
  133. install-targets: $$(INFO_$(1))
  134. endif
  135. IDEPEND_$(1):= $$(strip $(4))
  136. _ALL_CONTROLS+= $$(IDIR_$(1))/CONTROL/control
  137. ICONTROL_$(1)?= $(WRKDIR)/.$(2).control
  138. $$(IDIR_$(1))/CONTROL/control: ${_PATCH_COOKIE}
  139. @echo "Package: $$(shell echo $(2) | tr '_' '-')" > $(WRKDIR)/.$(2).control
  140. @echo "Section: $(6)" >> $(WRKDIR)/.$(2).control
  141. @echo "Description: $(5)" >> $(WRKDIR)/.$(2).control
  142. ${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh $${IDIR_$(1)} $${ICONTROL_$(1)} $(3) ${CPU_ARCH}
  143. @adeps='$$(strip $${IDEPEND_$(1)})'; if [[ -n $$$$adeps ]]; then \
  144. comma=; \
  145. deps=; \
  146. last=; \
  147. for dep in $$$$adeps; do \
  148. if [[ $$$$last = kernel && $$$$dep = \(* ]]; then \
  149. deps="$$$$deps $$$$dep"; \
  150. else \
  151. deps="$$$$deps$$$$comma$$$$dep"; \
  152. fi; \
  153. comma=", "; \
  154. last=$$$$dep; \
  155. done; \
  156. echo "Depends: $$$$deps" | tr '_' '-' >>$${IDIR_$(1)}/CONTROL/control; \
  157. fi
  158. @for file in conffiles preinst postinst prerm postrm; do \
  159. [ ! -f ./files/$(2).$$$$file ] || cp ./files/$(2).$$$$file $$(IDIR_$(1))/CONTROL/$$$$file; \
  160. done
  161. $$(IPKG_$(1)): $$(IDIR_$(1))/CONTROL/control $${_FAKE_COOKIE}
  162. ifeq ($(ADK_DEBUG),)
  163. $${RSTRIP} $${IDIR_$(1)} $(MAKE_TRACE)
  164. endif
  165. @for file in $$$$(ls ./files/*.init 2>/dev/null); do \
  166. fname=$$$$(echo $$$$file| sed -e "s#.*/##" -e "s#.init##"); \
  167. check=$$$$(grep PKG $$$$file|cut -d ' ' -f 2); \
  168. if [ "$$$$check" == $(2) ];then \
  169. mkdir -p $$(IDIR_$(1))/etc/init.d && cp $$$$file $$(IDIR_$(1))/etc/init.d/$$$$fname; \
  170. fi; \
  171. done
  172. @cd $${IDIR_$(1)}; for script in etc/init.d/*; do \
  173. [[ -e $$$$script ]] || continue; \
  174. chmod 0755 "$$$$script"; \
  175. done
  176. @mkdir -p $${PACKAGE_DIR} '$${STAGING_PKG_DIR}' \
  177. '$${STAGING_TARGET_DIR}/scripts'
  178. ifeq (,$(filter noremove,$(7)))
  179. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  180. cd '$${STAGING_TARGET_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" ];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 -v -e '^usr/share' -e '^usr/man' -e '^usr/info' -e '^usr/lib/libc.so' | \
  199. tee '$${STAGING_PKG_DIR}/$(1)' | \
  200. $(TOPDIR)/bin/tools/cpio -padlmu '$${STAGING_TARGET_DIR}'
  201. @cd '$${STAGING_TARGET_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. $${PKG_BUILD} $${IDIR_$(1)} $${PACKAGE_DIR} $(MAKE_TRACE)
  220. endif
  221. endif
  222. clean-targets: clean-dev-$(1)
  223. clean-dev-$(1):
  224. ifeq (,$(filter noremove,$(7)))
  225. @if test -s '$${STAGING_PKG_DIR}/$(1)'; then \
  226. cd '$${STAGING_TARGET_DIR}'; \
  227. while read fn; do \
  228. rm -f "$$$$fn"; \
  229. done <'$${STAGING_PKG_DIR}/$(1)'; \
  230. fi
  231. endif
  232. @rm -f '$${STAGING_PKG_DIR}/$(1)'
  233. $$(INFO_$(1)): $$(IPKG_$(1))
  234. $(PKG_INSTALL) $$(IPKG_$(1))
  235. endef
  236. install-targets:
  237. install:
  238. @$(CMD_TRACE) "installing... "
  239. @$(MAKE) install-targets $(MAKE_TRACE)
  240. clean-targets:
  241. clean:
  242. @$(CMD_TRACE) "cleaning... "
  243. @$(MAKE) clean-targets $(MAKE_TRACE)
  244. rm -rf ${WRKDIR} ${ALL_IPKGS} ${PACKAGE_DIR}/.stamps/${PKG_NAME}*
  245. distclean: clean
  246. rm -f ${FULLDISTFILES}
  247. .PHONY: all refetch extract patch configure \
  248. build rebuild fake package install clean build-all-pkgs