Makefile 3.9 KB

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