Makefile 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. # Makefile for OpenWrt
  2. #
  3. # Copyright (C) 2007-2015 OpenWrt.org
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. TOPDIR:=${CURDIR}
  9. LC_ALL:=C
  10. LANG:=C
  11. export TOPDIR LC_ALL LANG
  12. export OPENWRT_VERBOSE=s
  13. all: help
  14. include $(TOPDIR)/include/host.mk
  15. ifneq ($(OPENWRT_BUILD),1)
  16. override OPENWRT_BUILD=1
  17. export OPENWRT_BUILD
  18. endif
  19. include rules.mk
  20. include $(INCLUDE_DIR)/debug.mk
  21. include $(INCLUDE_DIR)/depends.mk
  22. include $(INCLUDE_DIR)/version.mk
  23. export REVISION
  24. define Helptext
  25. Available Commands:
  26. help: This help text
  27. info: Show a list of available target profiles
  28. clean: Remove images and temporary build files
  29. image: Build an image (see below for more information).
  30. Building images:
  31. By default 'make image' will create an image with the default
  32. target profile and package set. You can use the following parameters
  33. to change that:
  34. make image PROFILE="<profilename>" # override the default target profile
  35. make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
  36. make image FILES="<path>" # include extra files from <path>
  37. make image BIN_DIR="<path>" # alternative output directory for the images
  38. make image EXTRA_IMAGE_NAME="<string>" # Add this to the output image filename (sanitized)
  39. endef
  40. $(eval $(call shexport,Helptext))
  41. help: FORCE
  42. echo "$$$(call shvar,Helptext)"
  43. # override variables from rules.mk
  44. PACKAGE_DIR:=$(TOPDIR)/packages
  45. LISTS_DIR:=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(TARGET_DIR))))$(DL_DIR)
  46. OPKG:= \
  47. IPKG_NO_SCRIPT=1 \
  48. IPKG_TMP="$(TMP_DIR)/ipkgtmp" \
  49. IPKG_INSTROOT="$(TARGET_DIR)" \
  50. IPKG_CONF_DIR="$(TMP_DIR)" \
  51. IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
  52. $(STAGING_DIR_HOST)/bin/opkg \
  53. -f $(TOPDIR)/repositories.conf \
  54. --force-depends \
  55. --force-overwrite \
  56. --force-postinstall \
  57. --cache $(DL_DIR) \
  58. --lists-dir $(LISTS_DIR) \
  59. --offline-root $(TARGET_DIR) \
  60. --add-dest root:/ \
  61. --add-arch all:100 \
  62. --add-arch $(ARCH_PACKAGES):200
  63. define Profile
  64. $(eval $(call Profile/Default))
  65. $(eval $(call Profile/$(1)))
  66. ifeq ($(USER_PROFILE),)
  67. USER_PROFILE:=$(1)
  68. endif
  69. $(1)_NAME:=$(NAME)
  70. $(1)_PACKAGES:=$(PACKAGES)
  71. PROFILE_NAMES += $(1)
  72. PROFILE_LIST += \
  73. echo '$(1):'; [ -z '$(NAME)' ] || echo ' $(NAME)'; echo ' Packages: $(PACKAGES)';
  74. endef
  75. include $(INCLUDE_DIR)/target.mk
  76. staging_dir/host/.prereq-build: include/prereq-build.mk
  77. mkdir -p tmp
  78. rm -f tmp/.host.mk
  79. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
  80. echo "Prerequisite check failed. Use FORCE=1 to override."; \
  81. false; \
  82. }
  83. ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
  84. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
  85. echo "Preparation failed."; \
  86. false; \
  87. }
  88. endif
  89. touch $@
  90. _call_info: FORCE
  91. echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
  92. echo 'Default Packages: $(DEFAULT_PACKAGES)'
  93. echo 'Available Profiles:'
  94. echo; $(PROFILE_LIST)
  95. BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(USER_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
  96. # "-pkgname" in the package list means remove "pkgname" from the package list
  97. BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
  98. PACKAGES:=
  99. _call_image: staging_dir/host/.prereq-build
  100. echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
  101. echo 'Packages: $(BUILD_PACKAGES)'
  102. echo
  103. rm -rf $(TARGET_DIR)
  104. mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
  105. if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
  106. echo "Package list missing or not up-to-date, generating it.";\
  107. $(MAKE) package_index; \
  108. else \
  109. mkdir -p $(TARGET_DIR)/tmp; \
  110. $(OPKG) update || true; \
  111. fi
  112. $(MAKE) package_install
  113. ifneq ($(USER_FILES),)
  114. $(MAKE) copy_files
  115. endif
  116. $(MAKE) package_postinst
  117. $(MAKE) build_image
  118. package_index: FORCE
  119. @echo
  120. @echo Building package index...
  121. @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
  122. (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
  123. gzip -9nc Packages > Packages.gz \
  124. ) >/dev/null 2>/dev/null
  125. $(OPKG) update || true
  126. package_install: FORCE
  127. @echo
  128. @echo Installing packages...
  129. $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
  130. $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
  131. $(OPKG) install $(BUILD_PACKAGES)
  132. rm -f $(TARGET_DIR)/usr/lib/opkg/lists/*
  133. copy_files: FORCE
  134. @echo
  135. @echo Copying extra files
  136. @$(call file_copy,$(USER_FILES)/*,$(TARGET_DIR)/)
  137. package_postinst: FORCE
  138. @echo
  139. @echo Cleaning up
  140. @rm -f $(TARGET_DIR)/tmp/opkg.lock
  141. @echo
  142. @echo Activating init scripts
  143. @mkdir -p $(TARGET_DIR)/etc/rc.d
  144. @( \
  145. cd $(TARGET_DIR); \
  146. for script in ./usr/lib/opkg/info/*.postinst; do \
  147. IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
  148. done || true \
  149. )
  150. rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
  151. $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
  152. build_image: FORCE
  153. @echo
  154. @echo Building images...
  155. $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
  156. $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
  157. clean:
  158. rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
  159. info:
  160. (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
  161. image:
  162. ifneq ($(PROFILE),)
  163. ifeq ($(filter $(PROFILE),$(PROFILE_NAMES)),)
  164. @echo 'Profile "$(PROFILE)" does not exist!'
  165. @echo 'Use "make info" to get a list of available profile names.'
  166. @exit 1
  167. endif
  168. endif
  169. (unset PROFILE FILES PACKAGES MAKEFLAGS; \
  170. $(MAKE) _call_image \
  171. $(if $(PROFILE),USER_PROFILE="$(PROFILE)") \
  172. $(if $(FILES),USER_FILES="$(FILES)") \
  173. $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
  174. $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)"))
  175. .SILENT: help info image