Makefile 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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_INSTROOT="$(TARGET_DIR)" \
  49. $(STAGING_DIR_HOST)/bin/opkg \
  50. -f $(TOPDIR)/repositories.conf \
  51. --force-depends \
  52. --force-overwrite \
  53. --force-postinstall \
  54. --cache $(DL_DIR) \
  55. --lists-dir $(LISTS_DIR) \
  56. --offline-root $(TARGET_DIR) \
  57. --add-dest root:/ \
  58. --add-arch all:100 \
  59. --add-arch $(ARCH_PACKAGES):200
  60. include $(INCLUDE_DIR)/target.mk
  61. -include .profiles.mk
  62. USER_PROFILE ?= $(firstword $(PROFILE_NAMES))
  63. PROFILE_LIST = $(foreach p,$(PROFILE_NAMES), \
  64. echo '$(patsubst DEVICE_%,%,$(p)):'; $(if $($(p)_NAME),echo ' $(subst ','"'"',$($(p)_NAME))'; ) echo ' Packages: $($(p)_PACKAGES)'; \
  65. )
  66. .profiles.mk: .targetinfo
  67. @$(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
  68. staging_dir/host/.prereq-build: include/prereq-build.mk
  69. mkdir -p tmp
  70. rm -f tmp/.host.mk
  71. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
  72. echo "Prerequisite check failed. Use FORCE=1 to override."; \
  73. false; \
  74. }
  75. ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
  76. @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
  77. echo "Preparation failed."; \
  78. false; \
  79. }
  80. endif
  81. touch $@
  82. _call_info: FORCE
  83. echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
  84. echo 'Default Packages: $(DEFAULT_PACKAGES)'
  85. echo 'Available Profiles:'
  86. echo; $(PROFILE_LIST)
  87. BUILD_PACKAGES:=$(USER_PACKAGES) $(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
  88. # "-pkgname" in the package list means remove "pkgname" from the package list
  89. BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
  90. PACKAGES:=
  91. _call_image: staging_dir/host/.prereq-build
  92. echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
  93. echo 'Packages: $(BUILD_PACKAGES)'
  94. echo
  95. rm -rf $(TARGET_DIR)
  96. mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
  97. $(MAKE) package_reload
  98. $(MAKE) package_install
  99. ifneq ($(USER_FILES),)
  100. $(MAKE) copy_files
  101. endif
  102. $(MAKE) -s package_postinst
  103. $(MAKE) -s build_image
  104. $(MAKE) -s checksum
  105. package_index: FORCE
  106. @echo >&2
  107. @echo Building package index... >&2
  108. @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
  109. (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
  110. gzip -9nc Packages > Packages.gz \
  111. ) >/dev/null 2>/dev/null
  112. $(OPKG) update >&2 || true
  113. package_reload:
  114. if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
  115. echo "Package list missing or not up-to-date, generating it." >&2 ;\
  116. $(MAKE) package_index; \
  117. else \
  118. mkdir -p $(TARGET_DIR)/tmp; \
  119. $(OPKG) update >&2 || true; \
  120. fi
  121. package_list: FORCE
  122. @$(MAKE) -s package_reload
  123. @$(OPKG) list --size 2>/dev/null
  124. package_install: FORCE
  125. @echo
  126. @echo Installing packages...
  127. $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
  128. $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
  129. $(OPKG) install $(BUILD_PACKAGES)
  130. rm -f $(TARGET_DIR)/usr/lib/opkg/lists/*
  131. copy_files: FORCE
  132. @echo
  133. @echo Copying extra files
  134. @$(call file_copy,$(USER_FILES)/*,$(TARGET_DIR)/)
  135. package_postinst: FORCE
  136. @echo
  137. @echo Cleaning up
  138. @rm -f $(TARGET_DIR)/tmp/opkg.lock
  139. @echo
  140. @echo Activating init scripts
  141. @mkdir -p $(TARGET_DIR)/etc/rc.d
  142. @( \
  143. cd $(TARGET_DIR); \
  144. for script in ./usr/lib/opkg/info/*.postinst; do \
  145. IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
  146. done || true \
  147. )
  148. rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
  149. $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
  150. build_image: FORCE
  151. @echo
  152. @echo Building images...
  153. $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
  154. $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
  155. checksum: FORCE
  156. @echo
  157. @echo Calculating checksums...
  158. @$(call sha256sums,$(BIN_DIR))
  159. clean:
  160. rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
  161. info:
  162. (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
  163. PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
  164. image:
  165. ifneq ($(PROFILE),)
  166. ifeq ($(PROFILE_FILTER),)
  167. @echo 'Profile "$(PROFILE)" does not exist!'
  168. @echo 'Use "make info" to get a list of available profile names.'
  169. @exit 1
  170. endif
  171. endif
  172. (unset PROFILE FILES PACKAGES MAKEFLAGS; \
  173. $(MAKE) -s _call_image \
  174. $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
  175. $(if $(FILES),USER_FILES="$(FILES)") \
  176. $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
  177. $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)"))
  178. .SILENT: help info image