package.mk 7.5 KB

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