1
0

Makefile 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #
  2. # Copyright (C) 2006-2015 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. include $(TOPDIR)/rules.mk
  8. include $(INCLUDE_DIR)/kernel.mk
  9. include $(INCLUDE_DIR)/version.mk
  10. include $(INCLUDE_DIR)/feeds.mk
  11. override MAKEFLAGS=
  12. IB_NAME:=$(VERSION_DIST_SANITIZED)-imagebuilder-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET)).$(HOST_OS)-$(HOST_ARCH)
  13. PKG_BUILD_DIR:=$(BUILD_DIR)/$(IB_NAME)
  14. IB_KDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(KERNEL_BUILD_DIR))
  15. IB_LDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(LINUX_DIR))
  16. IB_DTSDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(LINUX_DIR))/arch/$(LINUX_KARCH)/boot/dts/
  17. IB_IDIR:=$(patsubst $(TOPDIR)/%,$(PKG_BUILD_DIR)/%,$(STAGING_DIR_IMAGE))
  18. BUNDLER_PATH := $(subst $(space),:,$(filter-out $(TOPDIR)/%,$(subst :,$(space),$(PATH))))
  19. BUNDLER_COMMAND := PATH=$(BUNDLER_PATH) $(XARGS) $(SCRIPT_DIR)/bundle-libraries.sh $(PKG_BUILD_DIR)/staging_dir/host
  20. all: compile
  21. $(BIN_DIR)/$(IB_NAME).tar.xz: clean
  22. rm -rf $(PKG_BUILD_DIR)
  23. mkdir -p $(IB_KDIR) $(IB_LDIR) $(PKG_BUILD_DIR)/staging_dir/host/lib \
  24. $(PKG_BUILD_DIR)/target $(PKG_BUILD_DIR)/scripts $(IB_DTSDIR)
  25. -cp $(TOPDIR)/.config $(PKG_BUILD_DIR)/.config
  26. $(SED) 's/^CONFIG_BINARY_FOLDER=.*/# CONFIG_BINARY_FOLDER is not set/' $(PKG_BUILD_DIR)/.config
  27. $(SED) 's/^CONFIG_DOWNLOAD_FOLDER=.*/# CONFIG_DOWNLOAD_FOLDER is not set/' $(PKG_BUILD_DIR)/.config
  28. $(CP) -L \
  29. $(INCLUDE_DIR) $(SCRIPT_DIR) \
  30. $(TOPDIR)/rules.mk \
  31. ./files/Makefile \
  32. ./files/repositories.conf \
  33. $(TMP_DIR)/.targetinfo \
  34. $(TMP_DIR)/.packageinfo \
  35. $(PKG_BUILD_DIR)/
  36. ifeq ($(CONFIG_IB_STANDALONE),)
  37. echo '## Remote package repositories' >> $(PKG_BUILD_DIR)/repositories.conf
  38. $(call FeedSourcesAppend,$(PKG_BUILD_DIR)/repositories.conf)
  39. $(VERSION_SED_SCRIPT) $(PKG_BUILD_DIR)/repositories.conf
  40. endif
  41. $(INSTALL_DIR) $(PKG_BUILD_DIR)/packages
  42. # create an empty package index so `opkg` doesn't report an error
  43. touch $(PKG_BUILD_DIR)/packages/Packages
  44. $(INSTALL_DATA) ./files/README.md $(PKG_BUILD_DIR)/packages/
  45. echo '' >> $(PKG_BUILD_DIR)/repositories.conf
  46. echo '## This is the local package repository, do not remove!' >> $(PKG_BUILD_DIR)/repositories.conf
  47. echo 'src imagebuilder file:packages' >> $(PKG_BUILD_DIR)/repositories.conf
  48. ifeq ($(CONFIG_BUILDBOT),)
  49. ifeq ($(CONFIG_IB_STANDALONE),)
  50. $(FIND) $(call FeedPackageDir,libc) -type f \
  51. \( -name 'libc_*.ipk' -or -name 'kernel_*.ipk' -or -name 'kmod-*.ipk' \) \
  52. -exec $(CP) -t $(PKG_BUILD_DIR)/packages {} +
  53. else
  54. $(FIND) $(wildcard $(PACKAGE_SUBDIRS)) -type f -name '*.ipk' \
  55. -exec $(CP) -t $(PKG_BUILD_DIR)/packages/ {} +
  56. endif
  57. else
  58. $(FIND) $(call FeedPackageDir,libc) -type f \
  59. \( -name 'libc_*.ipk' -or -name 'kernel_*.ipk' \) \
  60. -exec $(CP) -t $(IB_LDIR)/ {} +
  61. endif
  62. ifneq ($(CONFIG_SIGNATURE_CHECK),)
  63. echo '' >> $(PKG_BUILD_DIR)/repositories.conf
  64. echo 'option check_signature' >> $(PKG_BUILD_DIR)/repositories.conf
  65. $(INSTALL_DIR) $(PKG_BUILD_DIR)/keys
  66. $(CP) -L $(STAGING_DIR_ROOT)/etc/opkg/keys/ $(PKG_BUILD_DIR)/
  67. $(CP) -L $(STAGING_DIR_ROOT)/usr/sbin/opkg-key $(PKG_BUILD_DIR)/scripts/
  68. endif
  69. $(CP) -L $(TOPDIR)/target/linux $(PKG_BUILD_DIR)/target/
  70. if [ -d $(TOPDIR)/staging_dir/host/lib/grub ]; then \
  71. $(CP) $(TOPDIR)/staging_dir/host/lib/grub/ $(PKG_BUILD_DIR)/staging_dir/host/lib; \
  72. fi
  73. rm -rf \
  74. $(PKG_BUILD_DIR)/target/linux/*/files{,-*} \
  75. $(PKG_BUILD_DIR)/target/linux/*/patches{,-*} \
  76. $(PKG_BUILD_DIR)/target/linux/generic/{pending,backport,hack}{,-*}
  77. -cp $(KERNEL_BUILD_DIR)/* $(IB_KDIR)/ # don't copy subdirectories here
  78. -cp $(LINUX_DIR)/.config $(IB_LDIR)/
  79. rm -f $(IB_KDIR)/root.*
  80. rm -f $(IB_KDIR)/vmlinux.debug
  81. if [ -x $(LINUX_DIR)/scripts/dtc/dtc ]; then \
  82. $(INSTALL_DIR) $(IB_LDIR)/scripts/dtc; \
  83. $(INSTALL_BIN) $(LINUX_DIR)/scripts/dtc/dtc $(IB_LDIR)/scripts/dtc/dtc; \
  84. fi
  85. if [ -d $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts ]; then \
  86. $(CP) -L $(LINUX_DIR)/arch/$(LINUX_KARCH)/boot/dts/* $(IB_DTSDIR); \
  87. fi
  88. $(SED) 's,^# REVISION:=.*,REVISION:=$(REVISION),g' $(PKG_BUILD_DIR)/include/version.mk
  89. $(SED) 's,^# SOURCE_DATE_EPOCH:=.*,SOURCE_DATE_EPOCH:=$(SOURCE_DATE_EPOCH),g' $(PKG_BUILD_DIR)/include/version.mk
  90. $(SED) '/LINUX_VERMAGIC:=/ { s,unknown,$(LINUX_VERMAGIC),g }' $(PKG_BUILD_DIR)/include/kernel.mk
  91. find $(PKG_BUILD_DIR) -name CVS -o -name .git -o -name .svn \
  92. | $(XARGS) rm -rf
  93. $(INSTALL_DIR) $(IB_IDIR)
  94. -$(CP) $(STAGING_DIR_IMAGE)/* $(IB_IDIR)/
  95. $(INSTALL_DIR) $(PKG_BUILD_DIR)/staging_dir/host/bin
  96. $(CP) $(STAGING_DIR_HOST)/bin/* $(PKG_BUILD_DIR)/staging_dir/host/bin/
  97. (cd $(PKG_BUILD_DIR); find staging_dir/host/bin/ $(IB_LDIR)/scripts/dtc/ -type f | \
  98. $(BUNDLER_COMMAND))
  99. $(CP) $(TOPDIR)/staging_dir/host/lib/libfakeroot* $(PKG_BUILD_DIR)/staging_dir/host/lib
  100. STRIP=$(STAGING_DIR_HOST)/bin/sstrip $(SCRIPT_DIR)/rstrip.sh $(PKG_BUILD_DIR)/staging_dir/host/bin/
  101. (cd $(BUILD_DIR); \
  102. tar -I '$(STAGING_DIR_HOST)/bin/xz -7e -T$(if $(filter 1,$(NPROC)),2,0)' -cf $@ $(IB_NAME) \
  103. --mtime="$(shell date --date=@$(SOURCE_DATE_EPOCH))"; \
  104. )
  105. download:
  106. prepare:
  107. compile: $(BIN_DIR)/$(IB_NAME).tar.xz
  108. install: compile
  109. clean: FORCE
  110. rm -rf $(PKG_BUILD_DIR) $(BIN_DIR)/$(IB_NAME).tar.xz