package.mk 8.6 KB

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