3 # Copyright (C) 2007-2015 OpenWrt.org
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
12 export TOPDIR LC_ALL LANG
13 export OPENWRT_VERBOSE=s
16 include $(TOPDIR)/include/host.mk
18 ifneq ($(OPENWRT_BUILD),1)
19 override OPENWRT_BUILD=1
24 include $(INCLUDE_DIR)/debug.mk
25 include $(INCLUDE_DIR)/depends.mk
27 include $(INCLUDE_DIR)/version.mk
33 info: Show a list of available target profiles
34 clean: Remove images and temporary build files
35 image: Build an image (see below for more information).
38 By default 'make image' will create an image with the default
39 target profile and package set. You can use the following parameters
42 make image PROFILE="<profilename>" # override the default target profile
43 make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
44 make image FILES="<path>" # include extra files from <path>
45 make image BIN_DIR="<path>" # alternative output directory for the images
46 make image EXTRA_IMAGE_NAME="<string>" # Add this to the output image filename (sanitized)
48 $(eval $(call shexport,Helptext))
51 echo "$$$(call shvar,Helptext)"
54 # override variables from rules.mk
55 PACKAGE_DIR:=$(TOPDIR)/packages
56 LISTS_DIR:=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(TARGET_DIR))))$(DL_DIR)
59 IPKG_TMP="$(TMP_DIR)/ipkgtmp" \
60 IPKG_INSTROOT="$(TARGET_DIR)" \
61 IPKG_CONF_DIR="$(TMP_DIR)" \
62 IPKG_OFFLINE_ROOT="$(TARGET_DIR)" \
63 $(STAGING_DIR_HOST)/bin/opkg \
64 -f $(TOPDIR)/repositories.conf \
69 --lists-dir $(LISTS_DIR) \
70 --offline-root $(TARGET_DIR) \
73 --add-arch $(ARCH_PACKAGES):200
75 include $(INCLUDE_DIR)/target.mk
78 USER_PROFILE ?= $(firstword $(PROFILE_NAMES))
79 PROFILE_LIST = $(foreach p,$(PROFILE_NAMES), \
80 echo '$(p):'; $(if $($(p)_NAME),echo ' $($(p)_NAME)'; ) echo ' Packages: $($(p)_PACKAGES)'; \
83 .profiles.mk: .targetinfo
84 $(SCRIPT_DIR)/metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
86 staging_dir/host/.prereq-build: include/prereq-build.mk
89 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
90 echo "Prerequisite check failed. Use FORCE=1 to override."; \
93 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
94 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
95 echo "Preparation failed."; \
102 echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
103 echo 'Default Packages: $(DEFAULT_PACKAGES)'
104 echo 'Available Profiles:'
105 echo; $(PROFILE_LIST)
107 BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $(USER_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
108 # "-pkgname" in the package list means remove "pkgname" from the package list
109 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
112 _call_image: staging_dir/host/.prereq-build
113 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
114 echo 'Packages: $(BUILD_PACKAGES)'
117 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
118 if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
119 echo "Package list missing or not up-to-date, generating it.";\
120 $(MAKE) package_index; \
122 mkdir -p $(TARGET_DIR)/tmp; \
123 $(OPKG) update || true; \
125 $(MAKE) package_install
126 ifneq ($(USER_FILES),)
129 $(MAKE) package_postinst
134 @echo Building package index...
135 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
136 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
137 gzip -9nc Packages > Packages.gz \
138 ) >/dev/null 2>/dev/null
139 $(OPKG) update || true
141 package_install: FORCE
143 @echo Installing packages...
144 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
145 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
146 $(OPKG) install $(BUILD_PACKAGES)
147 rm -f $(TARGET_DIR)/usr/lib/opkg/lists/*
151 @echo Copying extra files
152 @$(call file_copy,$(USER_FILES)/*,$(TARGET_DIR)/)
154 package_postinst: FORCE
157 @rm -f $(TARGET_DIR)/tmp/opkg.lock
159 @echo Activating init scripts
160 @mkdir -p $(TARGET_DIR)/etc/rc.d
163 for script in ./usr/lib/opkg/info/*.postinst; do \
164 IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
167 rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
168 $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
172 @echo Building images...
173 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
174 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
177 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
181 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
185 ifeq ($(filter $(PROFILE),$(PROFILE_NAMES)),)
186 @echo 'Profile "$(PROFILE)" does not exist!'
187 @echo 'Use "make info" to get a list of available profile names.'
191 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
192 $(MAKE) _call_image \
193 $(if $(PROFILE),USER_PROFILE="$(PROFILE)") \
194 $(if $(FILES),USER_FILES="$(FILES)") \
195 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
196 $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)"))
198 .SILENT: help info image