rootfs.mk 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. include $(INCLUDE_DIR)/feeds.mk
  2. ifdef CONFIG_USE_MKLIBS
  3. define mklibs
  4. rm -rf $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-out
  5. # first find all programs and add them to the mklibs list
  6. find $(STAGING_DIR_ROOT) -type f -perm /100 -exec \
  7. file -r -N -F '' {} + | \
  8. awk ' /executable.*dynamically/ { print $$1 }' > $(TMP_DIR)/mklibs-progs
  9. # find all loadable objects that are not regular libraries and add them to the list as well
  10. find $(STAGING_DIR_ROOT) -type f -name \*.so\* -exec \
  11. file -r -N -F '' {} + | \
  12. awk ' /shared object/ { print $$1 }' > $(TMP_DIR)/mklibs-libs
  13. mkdir -p $(TMP_DIR)/mklibs-out
  14. $(STAGING_DIR_HOST)/bin/mklibs -D \
  15. -d $(TMP_DIR)/mklibs-out \
  16. --sysroot $(STAGING_DIR_ROOT) \
  17. `cat $(TMP_DIR)/mklibs-libs | sed 's:/*[^/]\+/*$$::' | uniq | sed 's:^$(STAGING_DIR_ROOT):-L :'` \
  18. --ldlib $(patsubst $(STAGING_DIR_ROOT)/%,/%,$(firstword $(wildcard \
  19. $(foreach name,ld-uClibc.so.* ld-linux.so.* ld-*.so ld-musl-*.so.*, \
  20. $(STAGING_DIR_ROOT)/lib/$(name) \
  21. )))) \
  22. --target $(REAL_GNU_TARGET_NAME) \
  23. `cat $(TMP_DIR)/mklibs-progs $(TMP_DIR)/mklibs-libs` 2>&1
  24. $(RSTRIP) $(TMP_DIR)/mklibs-out
  25. for lib in `ls $(TMP_DIR)/mklibs-out/*.so.* 2>/dev/null`; do \
  26. LIB="$${lib##*/}"; \
  27. DEST="`ls "$(1)/lib/$$LIB" "$(1)/usr/lib/$$LIB" 2>/dev/null`"; \
  28. [ -n "$$DEST" ] || continue; \
  29. echo "Copying stripped library $$lib to $$DEST"; \
  30. cp "$$lib" "$$DEST" || exit 1; \
  31. done
  32. endef
  33. endif
  34. # where to build (and put) .ipk packages
  35. opkg = \
  36. IPKG_NO_SCRIPT=1 \
  37. IPKG_INSTROOT=$(1) \
  38. TMPDIR=$(1)/tmp \
  39. $(STAGING_DIR_HOST)/bin/opkg \
  40. --offline-root $(1) \
  41. --force-postinstall \
  42. --add-dest root:/ \
  43. --add-arch all:100 \
  44. --add-arch $(if $(ARCH_PACKAGES),$(ARCH_PACKAGES),$(BOARD)):200
  45. TARGET_DIR_ORIG := $(TARGET_ROOTFS_DIR)/root.orig-$(BOARD)
  46. ifdef CONFIG_CLEAN_IPKG
  47. define clean_ipkg
  48. -find $(1)/usr/lib/opkg -type f -and -not -name '*.control' | $(XARGS) rm -rf
  49. -sed -i -ne '/^Require-User: /p' $(1)/usr/lib/opkg/info/*.control
  50. -find $(1)/usr/lib/opkg -empty | $(XARGS) rm -rf
  51. endef
  52. endif
  53. define prepare_rootfs
  54. @if [ -d $(TOPDIR)/files ]; then \
  55. $(call file_copy,$(TOPDIR)/files/.,$(1)); \
  56. fi
  57. @mkdir -p $(1)/etc/rc.d
  58. @( \
  59. cd $(1); \
  60. for script in ./usr/lib/opkg/info/*.postinst; do \
  61. IPKG_INSTROOT=$(1) $$(which bash) $$script; \
  62. ret=$$?; \
  63. if [ $$ret -ne 0 ]; then \
  64. echo "postinst script $$script has failed with exit code $$ret" >&2; \
  65. exit 1; \
  66. fi; \
  67. done; \
  68. for script in ./etc/init.d/*; do \
  69. grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
  70. IPKG_INSTROOT=$(1) $$(which bash) ./etc/rc.common $$script enable; \
  71. done || true \
  72. )
  73. $(if $(SOURCE_DATE_EPOCH),sed -i "s/Installed-Time: .*/Installed-Time: $(SOURCE_DATE_EPOCH)/" $(1)/usr/lib/opkg/status)
  74. @-find $(1) -name CVS | $(XARGS) rm -rf
  75. @-find $(1) -name .svn | $(XARGS) rm -rf
  76. @-find $(1) -name .git | $(XARGS) rm -rf
  77. @-find $(1) -name '.#*' | $(XARGS) rm -f
  78. rm -f $(1)/usr/lib/opkg/lists/*
  79. rm -f $(1)/usr/lib/opkg/info/*.postinst*
  80. rm -f $(1)/usr/lib/opkg/info/*.prerm*
  81. $(call clean_ipkg,$(1))
  82. $(call mklibs,$(1))
  83. endef