Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. KCONFIG:=
  31. PACKAGES:=
  32. endef
  33. define AddProfile
  34. $(eval $(call Profile/Default))
  35. $(eval $(call Profile/$(1)))
  36. ifneq ($(ID),)
  37. ifeq ($(PROFILE),)
  38. PROFILE:=$(ID)
  39. endif
  40. $(ID)_NAME:=$(NAME)
  41. $(ID)_PACKAGES:=$(PACKAGES)
  42. ifneq ($(KCONFIG),)
  43. PROFILE_LIST += \
  44. echo '$(ID):'; [ -z '$(NAME)' ] || echo ' $(NAME)'; echo ' Packages: $(PACKAGES)';
  45. endif
  46. endif
  47. endef
  48. include .target.mk
  49. define Helptext
  50. Available Commands:
  51. help: This help text
  52. info: Show a list of available target profiles
  53. clean: Remove images and temporary build files
  54. image: Build an image (see below for more information).
  55. Building images:
  56. By default 'make image' will create an image with the default
  57. target profile and package set. You can use the following parameters
  58. to change that:
  59. make image PROFILE="<profilename>" # override the default target profile
  60. make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
  61. make image FILES="<path>" # include extra files from <path>
  62. endef
  63. $(eval $(call shexport,Helptext))
  64. help: FORCE
  65. echo "$$$(call shvar,Helptext)"
  66. info: FORCE
  67. echo 'Current Target: "$(BOARDNAME)"'
  68. echo 'Available Profiles:'
  69. echo; $(PROFILE_LIST)
  70. $(TOPDIR)/tmp/ipkg.conf: FORCE
  71. @mkdir -p $(TOPDIR)/tmp
  72. @echo 'dest root /' > $@
  73. @echo 'src packages file:$(TOPDIR)/packages' >> $@
  74. BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(PACKAGES) $($(PROFILE)_PACKAGES) kernel)
  75. BUILD_PACKAGES:=$(patsubst base-files,base-files-$(BOARD)-$(KERNEL),$(BUILD_PACKAGES))
  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. image:
  79. if [ -z "$($(PROFILE)_NAME)" ]; then \
  80. echo Profile $(PROFILE) not found.; \
  81. echo 'Use "make info" to get a list of available target profiles'; \
  82. false; \
  83. fi
  84. echo 'Building images for $(BOARDNAME) - $($(PROFILE)_NAME)'
  85. echo 'Packages: $(BUILD_PACKAGES)'
  86. echo
  87. rm -rf $(TARGET_DIR)
  88. mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR)
  89. $(MAKE) package_index
  90. $(MAKE) package_install
  91. ifneq ($(FILES),)
  92. $(MAKE) copy_files
  93. endif
  94. $(MAKE) package_postinst
  95. $(MAKE) build_image
  96. package_index: $(TOPDIR)/tmp/ipkg.conf FORCE
  97. @echo
  98. @echo Building package index...
  99. (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages) >/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; \
  118. )
  119. build_image: FORCE
  120. @echo
  121. @echo Building images...
  122. $(NO_TRACE_MAKE) -C target/linux/$(BOARD)-$(KERNEL)/image install IB=1
  123. clean:
  124. rm -rf tmp $(TARGET_DIR) $(BIN_DIR)
  125. .PHONY: FORCE
  126. .SILENT: help info image
  127. %: ;