Makefile 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #
  2. # Copyright (C) 2006-2010 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. curdir:=package
  8. include $(INCLUDE_DIR)/feeds.mk
  9. -include $(TMP_DIR)/.packagedeps
  10. $(curdir)/builddirs:=$(sort $(package-) $(package-y) $(package-m))
  11. $(curdir)/builddirs-install:=.
  12. $(curdir)/builddirs-default:=. $(sort $(package-y) $(package-m))
  13. $(curdir)/builddirs-prereq:=. $(sort $(prereq-y) $(prereq-m))
  14. ifneq ($(IGNORE_ERRORS),)
  15. package-y-filter := $(package-y)
  16. package-m-filter := $(filter-out $(package-y),$(package-m))
  17. package-n-filter := $(filter-out $(package-y) $(package-m),$(package-))
  18. package-ignore-errors := $(filter n m y,$(IGNORE_ERRORS))
  19. package-ignore-errors := $(if $(package-ignore-errors),$(package-ignore-errors),n m)
  20. $(curdir)/builddirs-ignore-download := $(foreach m,$(package-ignore-errors),$(package-$(m)-filter))
  21. $(curdir)/builddirs-ignore-compile := $(foreach m,$(package-ignore-errors),$(package-$(m)-filter))
  22. endif
  23. ifdef CONFIG_USE_MKLIBS
  24. define mklibs
  25. rm -rf $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-out
  26. # first find all programs and add them to the mklibs list
  27. find $(STAGING_DIR_ROOT) -type f -perm /100 -exec \
  28. file -r -N -F '' {} + | \
  29. awk ' /executable.*dynamically/ { print $$1 }' > $(TMP_DIR)/mklibs-progs
  30. # find all loadable objects that are not regular libraries and add them to the list as well
  31. find $(STAGING_DIR_ROOT) -type f -name \*.so\* -exec \
  32. file -r -N -F '' {} + | \
  33. awk ' /shared object/ { print $$1 }' > $(TMP_DIR)/mklibs-libs
  34. mkdir -p $(TMP_DIR)/mklibs-out
  35. $(STAGING_DIR_HOST)/bin/mklibs -D \
  36. -d $(TMP_DIR)/mklibs-out \
  37. --sysroot $(STAGING_DIR_ROOT) \
  38. `cat $(TMP_DIR)/mklibs-libs | sed 's:/*[^/]\+/*$$::' | uniq | sed 's:^$(STAGING_DIR_ROOT):-L :'` \
  39. --ldlib $(patsubst $(STAGING_DIR_ROOT)/%,/%,$(firstword $(wildcard \
  40. $(foreach name,ld-uClibc.so.* ld-linux.so.* ld-*.so, \
  41. $(STAGING_DIR_ROOT)/lib/$(name) \
  42. )))) \
  43. --target $(REAL_GNU_TARGET_NAME) \
  44. `cat $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-libs` 2>&1
  45. $(RSTRIP) $(TMP_DIR)/mklibs-out
  46. for lib in `ls $(TMP_DIR)/mklibs-out/*.so.* 2>/dev/null`; do \
  47. LIB="$${lib##*/}"; \
  48. DEST="`ls "$(TARGET_DIR)/lib/$$LIB" "$(TARGET_DIR)/usr/lib/$$LIB" 2>/dev/null`"; \
  49. [ -n "$$DEST" ] || continue; \
  50. echo "Copying stripped library $$lib to $$DEST"; \
  51. cp "$$lib" "$$DEST" || exit 1; \
  52. done
  53. endef
  54. endif
  55. # where to build (and put) .ipk packages
  56. OPKG:= \
  57. IPKG_NO_SCRIPT=1 \
  58. IPKG_TMP=$(TMP_DIR)/ipkg \
  59. IPKG_INSTROOT=$(TARGET_DIR) \
  60. IPKG_CONF_DIR=$(STAGING_DIR)/etc \
  61. IPKG_OFFLINE_ROOT=$(TARGET_DIR) \
  62. $(XARGS) $(STAGING_DIR_HOST)/bin/opkg \
  63. --offline-root $(TARGET_DIR) \
  64. --force-depends \
  65. --force-overwrite \
  66. --force-postinstall \
  67. --force-maintainer \
  68. --add-dest root:/ \
  69. --add-arch all:100 \
  70. --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
  71. PACKAGE_INSTALL_FILES:= \
  72. $(foreach pkg,$(sort $(package-y)), \
  73. $(foreach variant, \
  74. $(if $(strip $(package/$(pkg)/variants)), \
  75. $(package/$(pkg)/variants), \
  76. $(if $(package/$(pkg)/default-variant), \
  77. $(package/$(pkg)/default-variant), \
  78. default \
  79. ) \
  80. ), \
  81. $(PKG_INFO_DIR)/$(lastword $(subst /,$(space),$(pkg))).$(variant).install \
  82. ) \
  83. )
  84. $(curdir)/cleanup: $(TMP_DIR)/.build
  85. rm -rf $(STAGING_DIR_ROOT)
  86. $(curdir)/install: $(TMP_DIR)/.build
  87. - find $(STAGING_DIR_ROOT) -type d | $(XARGS) chmod 0755
  88. rm -rf $(TARGET_DIR)
  89. [ -d $(TARGET_DIR)/tmp ] || mkdir -p $(TARGET_DIR)/tmp
  90. @$(FIND) `sed -e 's|.*|$(PACKAGE_DIR)$(if $(CONFIG_PER_FEED_REPO),/*)/&_*.ipk|' $(PACKAGE_INSTALL_FILES)` | sort -u | $(OPKG) install
  91. @for file in $(PACKAGE_INSTALL_FILES); do \
  92. [ -s $$file.flags ] || continue; \
  93. for flag in `cat $$file.flags`; do \
  94. $(OPKG) flag $$flag < $$file; \
  95. done; \
  96. done || true
  97. @-$(MAKE) package/preconfig
  98. @if [ -d $(TOPDIR)/files ]; then \
  99. $(call file_copy,$(TOPDIR)/files/.,$(TARGET_DIR)); \
  100. fi
  101. @mkdir -p $(TARGET_DIR)/etc/rc.d
  102. @( \
  103. cd $(TARGET_DIR); \
  104. for script in ./usr/lib/opkg/info/*.postinst; do \
  105. IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
  106. done; \
  107. for script in ./etc/init.d/*; do \
  108. grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
  109. IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) ./etc/rc.common $$script enable; \
  110. done || true \
  111. )
  112. @-find $(TARGET_DIR) -name CVS | $(XARGS) rm -rf
  113. @-find $(TARGET_DIR) -name .svn | $(XARGS) rm -rf
  114. @-find $(TARGET_DIR) -name '.#*' | $(XARGS) rm -f
  115. rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst*
  116. rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.prerm*
  117. $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
  118. $(call mklibs)
  119. PASSOPT=""
  120. PASSARG=""
  121. ifndef CONFIG_OPKGSMIME_PASSPHRASE
  122. ifneq ($(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE)),)
  123. PASSOPT="-passin"
  124. PASSARG="file:$(call qstrip,$(CONFIG_OPKGSMIME_PASSFILE))"
  125. endif
  126. endif
  127. PACKAGE_SUBDIRS=.
  128. ifneq ($(CONFIG_PER_FEED_REPO),)
  129. ifneq ($(CONFIG_PER_FEED_REPO_ADD_DISABLED),)
  130. PACKAGE_SUBDIRS=base $(FEEDS_AVAILABLE)
  131. else
  132. PACKAGE_SUBDIRS=base $(FEEDS_ENABLED)
  133. endif
  134. endif
  135. $(curdir)/index: FORCE
  136. @echo Generating package index...
  137. @for d in $(PACKAGE_SUBDIRS); do ( \
  138. mkdir -p $(PACKAGE_DIR)/$$d; \
  139. cd $(PACKAGE_DIR)/$$d || continue; \
  140. $(SCRIPT_DIR)/ipkg-make-index.sh . 2>&1 > Packages && \
  141. gzip -9c Packages > Packages.gz; \
  142. ); done
  143. ifdef CONFIG_SIGNED_PACKAGES
  144. @echo Signing package index...
  145. @for d in $(PACKAGE_SUBDIRS); do ( \
  146. [ -d $(PACKAGE_DIR)/$$d ] && \
  147. cd $(PACKAGE_DIR)/$$d || continue; \
  148. $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY); \
  149. ); done
  150. else
  151. ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_KEY)),)
  152. @echo Signing key has not been configured
  153. else
  154. ifeq ($(call qstrip,$(CONFIG_OPKGSMIME_CERT)),)
  155. @echo Certificate has not been configured
  156. else
  157. @echo Signing package index...
  158. @for d in $(PACKAGE_SUBDIRS); do ( \
  159. [ -d $(PACKAGE_DIR)/$$d ] && \
  160. cd $(PACKAGE_DIR)/$$d || continue; \
  161. openssl smime -binary -in Packages.gz \
  162. -out Packages.sig -outform PEM -sign \
  163. -signer $(CONFIG_OPKGSMIME_CERT) \
  164. -inkey $(CONFIG_OPKGSMIME_KEY) \
  165. $(PASSOPT) $(PASSARG); \
  166. ); done
  167. endif
  168. endif
  169. endif
  170. $(curdir)/preconfig:
  171. $(curdir)/flags-install:= -j1
  172. $(eval $(call stampfile,$(curdir),package,prereq,.config))
  173. $(eval $(call stampfile,$(curdir),package,cleanup,$(TMP_DIR)/.build))
  174. $(eval $(call stampfile,$(curdir),package,compile,$(TMP_DIR)/.build))
  175. $(eval $(call stampfile,$(curdir),package,install,$(TMP_DIR)/.build))
  176. $(eval $(call subdir,$(curdir)))