package.mk 8.7 KB

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