Makefile 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # Makefile for OpenWrt
  2. #
  3. # Copyright (C) 2007-2010 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 KBUILD_VERBOSE=99
  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. endef
  38. $(eval $(call shexport,Helptext))
  39. help: FORCE
  40. echo "$$$(call shvar,Helptext)"
  41. # override variables from rules.mk
  42. PACKAGE_DIR:=$(TOPDIR)/packages
  43. OPKG:= \
  44. IPKG_TMP="$(TOPDIR)/tmp/ipkgtmp" \
  45. IPKG_INSTROOT="$(TARGET_DIR)" \
  46. IPKG_CONF_DIR="$(TOPDIR)/tmp" \
  47. IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
  48. $(STAGING_DIR_HOST)/bin/opkg \
  49. -f $(TOPDIR)/repositories.conf \
  50. --force-depends \
  51. --force-overwrite \
  52. --force-postinstall \
  53. --cache $(TOPDIR)/dl \
  54. --offline-root $(TARGET_DIR) \
  55. --add-dest root:/ \
  56. --add-arch all:100 \
  57. --add-arch $(ARCH_PACKAGES):200
  58. define Profile
  59. $(eval $(call Profile/Default))
  60. $(eval $(call Profile/$(1)))
  61. ifeq ($(USER_PROFILE),)
  62. USER_PROFILE:=$(1)
  63. endif
  64. $(1)_NAME:=$(NAME)
  65. $(1)_PACKAGES:=$(PACKAGES)
  66. PROFILE_LIST += \
  67. echo '$(1):'; [ -z '$(NAME)' ] || echo ' $(NAME)'; echo ' Packages: $(PACKAGES)';
  68. endef
  69. include $(INCLUDE_DIR)/target.mk
  70. _call_info: FORCE
  71. echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
  72. echo 'Default Packages: $(DEFAULT_PACKAGES)'
  73. echo 'Available Profiles:'
  74. echo; $(PROFILE_LIST)
  75. BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(USER_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
  76. # "-pkgname" in the package list means remove "pkgname" from the package list
  77. BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
  78. PACKAGES:=
  79. _call_image:
  80. echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
  81. echo 'Packages: $(BUILD_PACKAGES)'
  82. echo
  83. rm -rf $(TARGET_DIR)
  84. mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR)
  85. $(MAKE) package_index
  86. $(MAKE) package_install
  87. ifneq ($(USER_FILES),)
  88. $(MAKE) copy_files
  89. endif
  90. $(MAKE) package_postinst
  91. $(MAKE) build_image
  92. package_index: FORCE
  93. @echo
  94. @echo Building package index...
  95. @mkdir -p $(TOPDIR)/tmp $(TOPDIR)/dl $(TARGET_DIR)/tmp
  96. (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
  97. gzip -9c Packages > Packages.gz \
  98. ) >/dev/null 2>/dev/null
  99. $(OPKG) update
  100. package_install: FORCE
  101. @echo
  102. @echo Installing packages...
  103. $(OPKG) install $(BUILD_PACKAGES)
  104. copy_files: FORCE
  105. @echo
  106. @echo Copying extra files
  107. $(CP) $(USER_FILES)/* $(TARGET_DIR)/
  108. package_postinst: FORCE
  109. @echo
  110. @echo Cleaning up
  111. @rm -f $(TARGET_DIR)/tmp/opkg.lock
  112. @echo
  113. @echo Activating init scripts
  114. @( \
  115. cd $(TARGET_DIR); \
  116. for script in ./etc/init.d/*; do \
  117. grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
  118. IPKG_INSTROOT=$(TARGET_DIR) $(which bash) ./etc/rc.common $$script enable; \
  119. done || true; \
  120. )
  121. build_image: FORCE
  122. @echo
  123. @echo Building images...
  124. $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1
  125. clean:
  126. rm -rf $(TOPDIR)/tmp $(TOPDIR)/dl $(TARGET_DIR) $(BIN_DIR)
  127. info:
  128. (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
  129. image:
  130. (unset PROFILE FILES PACKAGES MAKEFLAGS; \
  131. $(MAKE) _call_image \
  132. $(if $(PROFILE),USER_PROFILE="$(PROFILE)") \
  133. $(if $(FILES),USER_FILES="$(FILES)") \
  134. $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)"))
  135. .SILENT: help info image