Makefile 3.5 KB

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