package.mk 7.5 KB

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