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 export PATH:=$(TOPDIR)/staging_dir/host/bin:$(PATH)
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_INSTROOT="$(TARGET_DIR)" \
60 $(STAGING_DIR_HOST)/bin/opkg \
61 -f $(TOPDIR)/repositories.conf \
66 --lists-dir $(LISTS_DIR) \
67 --offline-root $(TARGET_DIR) \
70 --add-arch $(ARCH_PACKAGES):200
72 include $(INCLUDE_DIR)/target.mk
75 USER_PROFILE ?= $(firstword $(PROFILE_NAMES))
76 PROFILE_LIST = $(foreach p,$(PROFILE_NAMES), \
77 echo '$(patsubst DEVICE_%,%,$(p)):'; $(if $($(p)_NAME),echo ' $(subst ','"'"',$($(p)_NAME))'; ) echo ' Packages: $($(p)_PACKAGES)'; \
80 .profiles.mk: .targetinfo
81 $(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
83 staging_dir/host/.prereq-build: include/prereq-build.mk
85 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
86 echo "Prerequisite check failed. Use FORCE=1 to override."; \
89 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
90 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
91 echo "Preparation failed."; \
98 echo 'Current Target: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
99 echo 'Default Packages: $(DEFAULT_PACKAGES)'
100 echo 'Available Profiles:'
101 echo; $(PROFILE_LIST)
103 BUILD_PACKAGES:=$(USER_PACKAGES) $(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
104 # "-pkgname" in the package list means remove "pkgname" from the package list
105 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
108 _call_image: staging_dir/host/.prereq-build
109 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
110 echo 'Packages: $(BUILD_PACKAGES)'
113 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
114 $(MAKE) package_reload
115 $(MAKE) package_install
116 ifneq ($(USER_FILES),)
119 $(MAKE) -s package_postinst
120 $(MAKE) -s build_image
125 @echo Building package index...
126 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
127 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
128 gzip -9nc Packages > Packages.gz \
129 ) >/dev/null 2>/dev/null
130 $(OPKG) update || true
133 if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
134 echo "Package list missing or not up-to-date, generating it.";\
135 $(MAKE) package_index; \
137 mkdir -p $(TARGET_DIR)/tmp; \
138 $(OPKG) update || true; \
142 @$(MAKE) -s package_reload
143 @$(OPKG) list --size 2>/dev/null | awk -F" - " '{printf "%s %s %s\n", $$1, $$2, $$3}'
145 package_install: FORCE
147 @echo Installing packages...
148 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
149 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
150 $(OPKG) install $(BUILD_PACKAGES)
151 rm -f $(TARGET_DIR)/usr/lib/opkg/lists/*
155 @echo Copying extra files
156 @$(call file_copy,$(USER_FILES)/*,$(TARGET_DIR)/)
158 package_postinst: FORCE
161 @rm -f $(TARGET_DIR)/tmp/opkg.lock
163 @echo Activating init scripts
164 @mkdir -p $(TARGET_DIR)/etc/rc.d
167 for script in ./usr/lib/opkg/info/*.postinst; do \
168 IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
171 rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
172 $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
176 @echo Building images...
177 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
178 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
182 @echo Calculating checksums...
183 @$(call sha256sums,$(BIN_DIR))
186 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
190 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
192 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
196 ifeq ($(PROFILE_FILTER),)
197 @echo 'Profile "$(PROFILE)" does not exist!'
198 @echo 'Use "make info" to get a list of available profile names.'
202 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
203 $(MAKE) -s _call_image \
204 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
205 $(if $(FILES),USER_FILES="$(FILES)") \
206 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
207 $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)"))
209 .SILENT: help info image