Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. # "-pkgname" in the package list means remove "pkgname" from the package list
  74. BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
  75. image:
  76. if [ -z "$($(PROFILE)_NAME)" ]; then \
  77. echo Profile $(PROFILE) not found.; \
  78. echo 'Use "make info" to get a list of available target profiles'; \
  79. false; \
  80. fi
  81. echo 'Building images for $(BOARDNAME) - $($(PROFILE)_NAME)'
  82. echo 'Packages: $(BUILD_PACKAGES)'
  83. echo
  84. rm -rf $(TARGET_DIR)
  85. mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR)
  86. $(MAKE) package_index
  87. $(MAKE) package_install
  88. ifneq ($(FILES),)
  89. $(MAKE) copy_files
  90. endif
  91. $(MAKE) package_postinst
  92. $(MAKE) build_image
  93. package_index: $(TOPDIR)/tmp/ipkg.conf FORCE
  94. @echo
  95. @echo Building package index...
  96. (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages) >/dev/null 2>/dev/null
  97. $(IPKG) update
  98. package_install: FORCE
  99. @echo
  100. @echo Installing packages...
  101. $(IPKG) install $(BUILD_PACKAGES)
  102. copy_files: FORCE
  103. @echo
  104. @echo Copying extra files
  105. $(CP) $(FILES)/* $(TARGET_DIR)/
  106. package_postinst: FORCE
  107. @echo
  108. @echo Activating init scripts
  109. ( \
  110. cd $(BUILD_DIR)/root; \
  111. for script in ./etc/init.d/*; do \
  112. grep '#!/bin/sh /etc/rc.common' $$script >/dev/null || continue; \
  113. IPKG_INSTROOT=$(BUILD_DIR)/root $(which bash) ./etc/rc.common $$script enable; \
  114. done; \
  115. )
  116. build_image: FORCE
  117. @echo
  118. @echo Building images...
  119. $(NO_TRACE_MAKE) -C target/linux/$(BOARD)-$(KERNEL)/image install IB=1
  120. clean:
  121. rm -rf tmp $(TARGET_DIR) $(BIN_DIR)
  122. .PHONY: FORCE
  123. .SILENT: help info image
  124. %: ;