Makefile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # Makefile for OpenWrt
  2. #
  3. # Copyright (C) 2007-2008 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. define Helptext
  23. Available Commands:
  24. help: This help text
  25. info: Show a list of available target profiles
  26. clean: Remove images and temporary build files
  27. image: Build an image (see below for more information).
  28. Building images:
  29. By default 'make image' will create an image with the default
  30. target profile and package set. You can use the following parameters
  31. to change that:
  32. make image PROFILE="<profilename>" # override the default target profile
  33. make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
  34. make image FILES="<path>" # include extra files from <path>
  35. endef
  36. $(eval $(call shexport,Helptext))
  37. help: FORCE
  38. echo "$$$(call shvar,Helptext)"
  39. # override variables from rules.mk
  40. PACKAGE_DIR:=$(TOPDIR)/packages
  41. IPKG:= \
  42. IPKG_TMP="$(TOPDIR)/tmp/ipkgtmp" \
  43. IPKG_INSTROOT="$(TARGET_DIR)" \
  44. IPKG_CONF_DIR="$(TOPDIR)/tmp" \
  45. IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
  46. $(SCRIPT_DIR)/ipkg -force-defaults
  47. define Profile
  48. $(eval $(call Profile/Default))
  49. $(eval $(call Profile/$(1)))
  50. ifeq ($(PROFILE),)
  51. PROFILE:=$(1)
  52. endif
  53. $(1)_NAME:=$(NAME)
  54. $(1)_PACKAGES:=$(PACKAGES)
  55. PROFILE_LIST += \
  56. echo '$(1):'; [ -z '$(NAME)' ] || echo ' $(NAME)'; echo ' Packages: $(PACKAGES)';
  57. endef
  58. include $(INCLUDE_DIR)/target.mk
  59. info: FORCE
  60. echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
  61. echo 'Default Packages: $(DEFAULT_PACKAGES)'
  62. echo 'Available Profiles:'
  63. echo; $(PROFILE_LIST)
  64. $(TOPDIR)/tmp/ipkg.conf: FORCE
  65. @mkdir -p $(TOPDIR)/tmp
  66. @echo 'dest root /' > $@
  67. @echo 'src packages file:$(PACKAGE_DIR)' >> $@
  68. BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(PACKAGES) $($(PROFILE)_PACKAGES) kernel)
  69. ifeq ($(KERNEL),2.4)
  70. BUILD_PACKAGES:=$(patsubst base-files,base-files-$(BOARD)-$(KERNEL),$(BUILD_PACKAGES))
  71. else
  72. BUILD_PACKAGES:=$(patsubst base-files,base-files-$(BOARD),$(BUILD_PACKAGES))
  73. endif
  74. # "-pkgname" in the package list means remove "pkgname" from the package list
  75. BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
  76. image:
  77. if [ -z "$($(PROFILE)_NAME)" ]; then \
  78. echo Profile $(PROFILE) not found.; \
  79. echo 'Use "make info" to get a list of available target profiles'; \
  80. false; \
  81. fi
  82. echo 'Building images for $(BOARD) - $($(PROFILE)_NAME)'
  83. echo 'Packages: $(BUILD_PACKAGES)'
  84. echo
  85. rm -rf $(TARGET_DIR)
  86. mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR)
  87. $(MAKE) package_index
  88. $(MAKE) package_install
  89. ifneq ($(FILES),)
  90. $(MAKE) copy_files
  91. endif
  92. $(MAKE) package_postinst
  93. $(MAKE) build_image
  94. package_index: $(TOPDIR)/tmp/ipkg.conf FORCE
  95. @echo
  96. @echo Building package index...
  97. (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
  98. gzip -9c Packages > Packages.gz \
  99. ) >/dev/null 2>/dev/null
  100. $(IPKG) update
  101. package_install: FORCE
  102. @echo
  103. @echo Installing packages...
  104. $(IPKG) install $(BUILD_PACKAGES)
  105. copy_files: FORCE
  106. @echo
  107. @echo Copying extra files
  108. $(CP) $(FILES)/* $(TARGET_DIR)/
  109. package_postinst: FORCE
  110. @echo
  111. @echo Activating init scripts
  112. @( \
  113. cd $(BUILD_DIR)/root; \
  114. for script in ./etc/init.d/*; do \
  115. grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
  116. IPKG_INSTROOT=$(BUILD_DIR)/root $(which bash) ./etc/rc.common $$script enable; \
  117. done || true; \
  118. )
  119. build_image: FORCE
  120. @echo
  121. @echo Building images...
  122. $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1
  123. clean:
  124. rm -rf tmp $(TARGET_DIR) $(BIN_DIR)
  125. .SILENT: help info image