Makefile 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. endef
  39. $(eval $(call shexport,Helptext))
  40. help: FORCE
  41. echo "$$$(call shvar,Helptext)"
  42. # override variables from rules.mk
  43. PACKAGE_DIR:=$(TOPDIR)/packages
  44. OPKG:= \
  45. IPKG_NO_SCRIPT=1 \
  46. IPKG_TMP="$(TMP_DIR)/ipkgtmp" \
  47. IPKG_INSTROOT="$(TARGET_DIR)" \
  48. IPKG_CONF_DIR="$(TMP_DIR)" \
  49. IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
  50. $(STAGING_DIR_HOST)/bin/opkg \
  51. -f $(TOPDIR)/repositories.conf \
  52. --force-depends \
  53. --force-overwrite \
  54. --force-postinstall \
  55. --cache $(DL_DIR) \
  56. --offline-root $(TARGET_DIR) \
  57. --add-dest root:/ \
  58. --add-arch all:100 \
  59. --add-arch $(ARCH_PACKAGES):200
  60. define Profile
  61. $(eval $(call Profile/Default))
  62. $(eval $(call Profile/$(1)))
  63. ifeq ($(USER_PROFILE),)
  64. USER_PROFILE:=$(1)
  65. endif
  66. $(1)_NAME:=$(NAME)
  67. $(1)_PACKAGES:=$(PACKAGES)
  68. PROFILE_NAMES += $(1)
  69. PROFILE_LIST += \
  70. echo '$(1):'; [ -z '$(NAME)' ] || echo ' $(NAME)'; echo ' Packages: $(PACKAGES)';
  71. endef
  72. include $(INCLUDE_DIR)/target.mk
  73. _call_info: FORCE
  74. echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
  75. echo 'Default Packages: $(DEFAULT_PACKAGES)'
  76. echo 'Available Profiles:'
  77. echo; $(PROFILE_LIST)
  78. BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(USER_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
  79. # "-pkgname" in the package list means remove "pkgname" from the package list
  80. BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
  81. PACKAGES:=
  82. _call_image:
  83. echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
  84. echo 'Packages: $(BUILD_PACKAGES)'
  85. echo
  86. rm -rf $(TARGET_DIR)
  87. mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
  88. if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
  89. echo "Package list missing or not up-to-date, generating it.";\
  90. $(MAKE) package_index; \
  91. else \
  92. mkdir -p $(TARGET_DIR)/tmp; \
  93. $(OPKG) update || true; \
  94. fi
  95. $(MAKE) package_install
  96. ifneq ($(USER_FILES),)
  97. $(MAKE) copy_files
  98. endif
  99. $(MAKE) package_postinst
  100. $(MAKE) build_image
  101. package_index: FORCE
  102. @echo
  103. @echo Building package index...
  104. @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
  105. (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
  106. gzip -9c Packages > Packages.gz \
  107. ) >/dev/null 2>/dev/null
  108. $(OPKG) update || true
  109. package_install: FORCE
  110. @echo
  111. @echo Installing packages...
  112. $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
  113. $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
  114. $(OPKG) install $(BUILD_PACKAGES)
  115. rm -f $(TARGET_DIR)/usr/lib/opkg/lists/*
  116. copy_files: FORCE
  117. @echo
  118. @echo Copying extra files
  119. @$(call file_copy,$(USER_FILES)/*,$(TARGET_DIR)/)
  120. package_postinst: FORCE
  121. @echo
  122. @echo Cleaning up
  123. @rm -f $(TARGET_DIR)/tmp/opkg.lock
  124. @echo
  125. @echo Activating init scripts
  126. @mkdir -p $(TARGET_DIR)/etc/rc.d
  127. @( \
  128. cd $(TARGET_DIR); \
  129. for script in ./usr/lib/opkg/info/*.postinst; do \
  130. IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
  131. done || true \
  132. )
  133. rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
  134. $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
  135. build_image: FORCE
  136. @echo
  137. @echo Building images...
  138. $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 \
  139. $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
  140. clean:
  141. rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
  142. info:
  143. (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
  144. image:
  145. ifneq ($(PROFILE),)
  146. ifeq ($(filter $(PROFILE),$(PROFILE_NAMES)),)
  147. @echo 'Profile "$(PROFILE)" does not exist!'
  148. @echo 'Use "make info" to get a list of available profile names.'
  149. @exit 1
  150. endif
  151. endif
  152. (unset PROFILE FILES PACKAGES MAKEFLAGS; \
  153. $(MAKE) _call_image \
  154. $(if $(PROFILE),USER_PROFILE="$(PROFILE)") \
  155. $(if $(FILES),USER_FILES="$(FILES)") \
  156. $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
  157. $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)"))
  158. .SILENT: help info image