1
0

Makefile 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
  98. echo "Package list missing or not up-to-date, generating it.";\
  99. $(MAKE) package_index; \
  100. else \
  101. mkdir -p $(TARGET_DIR)/tmp; \
  102. $(OPKG) update || true; \
  103. fi
  104. $(MAKE) package_install
  105. ifneq ($(USER_FILES),)
  106. $(MAKE) copy_files
  107. endif
  108. $(MAKE) package_postinst
  109. $(MAKE) build_image
  110. $(MAKE) checksum
  111. package_index: FORCE
  112. @echo
  113. @echo Building package index...
  114. @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
  115. (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
  116. gzip -9nc Packages > Packages.gz \
  117. ) >/dev/null 2>/dev/null
  118. $(OPKG) update || true
  119. package_install: FORCE
  120. @echo
  121. @echo Installing packages...
  122. $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
  123. $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
  124. $(OPKG) install $(BUILD_PACKAGES)
  125. rm -f $(TARGET_DIR)/usr/lib/opkg/lists/*
  126. copy_files: FORCE
  127. @echo
  128. @echo Copying extra files
  129. @$(call file_copy,$(USER_FILES)/*,$(TARGET_DIR)/)
  130. package_postinst: FORCE
  131. @echo
  132. @echo Cleaning up
  133. @rm -f $(TARGET_DIR)/tmp/opkg.lock
  134. @echo
  135. @echo Activating init scripts
  136. @mkdir -p $(TARGET_DIR)/etc/rc.d
  137. @( \
  138. cd $(TARGET_DIR); \
  139. for script in ./usr/lib/opkg/info/*.postinst; do \
  140. IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
  141. done || true \
  142. )
  143. rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
  144. $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
  145. build_image: FORCE
  146. @echo
  147. @echo Building images...
  148. $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
  149. $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
  150. checksum: FORCE
  151. @echo
  152. @echo Calculating checksums...
  153. @$(call sha256sums,$(BIN_DIR))
  154. clean:
  155. rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
  156. info:
  157. (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
  158. PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
  159. image:
  160. ifneq ($(PROFILE),)
  161. ifeq ($(PROFILE_FILTER),)
  162. @echo 'Profile "$(PROFILE)" does not exist!'
  163. @echo 'Use "make info" to get a list of available profile names.'
  164. @exit 1
  165. endif
  166. endif
  167. (unset PROFILE FILES PACKAGES MAKEFLAGS; \
  168. $(MAKE) _call_image \
  169. $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
  170. $(if $(FILES),USER_FILES="$(FILES)") \
  171. $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
  172. $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)"))
  173. .SILENT: help info image