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
26 include $(INCLUDE_DIR
)/rootfs.mk
28 include $(INCLUDE_DIR
)/version.mk
30 export SOURCE_DATE_EPOCH
35 info: Show a list of available target profiles
36 clean: Remove images and temporary build files
37 image
: Build an image
(see below for more information
).
38 manifest
: Show
all package that will be installed into the image
39 package_depends
: Show installation dependency of the package
42 By default
'make image' will create an image with the default
43 target profile and package set. You can use the following parameters
46 make image PROFILE
="<profilename>" # override the default target profile
47 make image PACKAGES
="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
48 make image FILES
="<path>" # include extra files from <path>
49 make image BIN_DIR
="<path>" # alternative output directory for the images
50 make image EXTRA_IMAGE_NAME
="<string>" # Add this to the output image filename (sanitized)
51 make image DISABLED_SERVICES
="<svc1> [<svc2> [<svc3> ..]]" # Which services in /etc/init.d/ should be disabled
52 make image ADD_LOCAL_KEY
=1 # store locally generated signing key in built images
55 List
"all" packages which
get installed into the image.
56 You can use the following parameters
:
58 make manifest PROFILE
="<profilename>" # override the default target profile
59 make manifest PACKAGES
="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
60 make manifest STRIP_ABI
=1 # remove ABI version from printed package names
63 List
"all" packages dependency of the package
64 You can use the following parameters
:
66 make package_depends PACKAGE
="<pkg>"
69 $(eval
$(call shexport
,Helptext
))
72 echo
"$$$(call shvar,Helptext)"
75 # override variables from rules.mk
76 PACKAGE_DIR
:=$(TOPDIR
)/packages
77 LISTS_DIR
:=$(subst $(space
),/,$(patsubst %,..
,$(subst /,$(space
),$(TARGET_DIR
))))$(DL_DIR
)
78 export OPKG_KEYS
:=$(TOPDIR
)/keys
79 OPKG
:=$(call opkg
,$(TARGET_DIR
)) \
80 -f
$(TOPDIR
)/repositories.conf \
81 --verify-program
$(SCRIPT_DIR
)/opkg-key \
83 --lists-dir
$(LISTS_DIR
)
85 include $(INCLUDE_DIR
)/target.mk
88 USER_PROFILE ?
= $(firstword $(PROFILE_NAMES
))
89 PROFILE_LIST
= $(foreach p
,$(PROFILE_NAMES
), \
90 echo
'$(patsubst DEVICE_%,%,$(p)):'; $(if
$($(p
)_NAME
),echo
' $(subst ','"'"',$($(p)_NAME))'; ) \
91 echo ' Packages: $($(p)_PACKAGES)'; echo ' hasImageMetadata: $($(p)_HAS_IMAGE_METADATA)'; \
92 $(if $($(p)_SUPPORTED_DEVICES),echo ' SupportedDevices: $($(p)_SUPPORTED_DEVICES)';) )
95 .profiles.mk: .targetinfo
96 @$(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
98 staging_dir/host/.prereq-build: include/prereq-build.mk
100 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq IB=1 2>/dev/null || { \
101 echo "Prerequisite
check failed. Use FORCE
=1 to
override.
"; \
104 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
105 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
106 echo "Preparation failed.
"; \
113 echo 'Current Target: "$(TARGETID
)"'
114 echo 'Current Architecture: "$(ARCH
)"'
115 echo 'Current Revision: "$(REVISION
)"'
116 echo 'Default Packages: $(DEFAULT_PACKAGES)'
117 echo 'Available Profiles:'
118 echo; $(PROFILE_LIST)
120 BUILD_PACKAGES:=$(USER_PACKAGES) $(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
121 # "-pkgname
" in the package list means remove "pkgname
" from the package list
122 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
125 _call_image: staging_dir/host/.prereq-build
126 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
127 echo 'Packages: $(BUILD_PACKAGES)'
129 rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
130 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
131 $(MAKE) package_reload
132 $(MAKE) package_install
133 $(MAKE) -s prepare_rootfs
134 $(MAKE) -s build_image
135 $(MAKE) -s json_overview_image_info
138 _call_manifest: FORCE
140 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
141 $(MAKE) package_reload >/dev/null
142 $(MAKE) package_install >/dev/null
143 $(OPKG) list-installed $(if $(STRIP_ABI),--strip-abi)
147 @echo Building package index... >&2
148 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
149 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
150 gzip -9nc Packages > Packages.gz; \
151 $(if $(CONFIG_SIGNATURE_CHECK), \
152 $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY)) \
153 ) >/dev/null 2>/dev/null
154 $(OPKG) update >&2 || true
157 if [ -d "$(PACKAGE_DIR
)" ] && ( \
158 [ ! -f "$(PACKAGE_DIR
)/Packages
" ] || \
159 [ ! -f "$(PACKAGE_DIR
)/Packages.gz
" ] || \
160 [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ] ); then \
161 echo "Package list missing or not up-to-date
, generating it.
" >&2 ;\
162 $(MAKE) package_index; \
164 mkdir -p $(TARGET_DIR)/tmp; \
165 $(OPKG) update >&2 || true; \
169 @$(MAKE) -s package_reload
170 @$(OPKG) list --size 2>/dev/null
172 package_install: FORCE
174 @echo Installing packages...
175 $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/libc_*.ipk $(PACKAGE_DIR)/libc_*.ipk))
176 $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/kernel_*.ipk $(PACKAGE_DIR)/kernel_*.ipk))
177 $(OPKG) install $(BUILD_PACKAGES)
179 prepare_rootfs: FORCE
181 @echo Finalizing root filesystem...
183 $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG)
184 $(if $(CONFIG_SIGNATURE_CHECK), \
185 $(if $(ADD_LOCAL_KEY), \
186 OPKG_KEYS=$(TARGET_DIR)/etc/opkg/keys/ \
187 $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub \
190 $(call prepare_rootfs,$(TARGET_DIR),$(USER_FILES),$(DISABLED_SERVICES))
194 @echo Building images...
195 rm -rf $(BUILD_DIR)/json_info_files/
196 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME
)" \
197 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE
)")
199 $(BIN_DIR)/profiles.json: FORCE
200 $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
201 WORK_DIR=$(BUILD_DIR)/json_info_files \
202 $(SCRIPT_DIR)/json_overview_image_info.py $@ \
205 json_overview_image_info: $(BIN_DIR)/profiles.json
209 @echo Calculating checksums...
210 @$(call sha256sums,$(BIN_DIR))
213 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
217 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
219 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
221 _check_profile: FORCE
223 ifeq ($(PROFILE_FILTER),)
224 @echo 'Profile "$(PROFILE
)" does not exist!'
225 @echo 'Use "make
info" to get a list of available profile names.'
231 ifneq ($(CONFIG_SIGNATURE_CHECK),)
232 @if [ ! -s $(BUILD_KEY) -o ! -s $(BUILD_KEY).pub ]; then \
233 echo Generate local signing keys... >&2; \
234 $(STAGING_DIR_HOST)/bin/usign -G \
235 -s $(BUILD_KEY) -p $(BUILD_KEY).pub -c "Local build key
"; \
236 $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub; \
238 if [ ! -s $(BUILD_KEY).ucert ]; then \
239 echo Generate local certificate... >&2; \
240 $(STAGING_DIR_HOST)/bin/ucert -I \
241 -c $(BUILD_KEY).ucert \
242 -p $(BUILD_KEY).pub \
248 $(MAKE) -s _check_profile
249 $(MAKE) -s _check_keys
250 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
251 $(MAKE) -s _call_image \
252 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER
)") \
253 $(if $(FILES),USER_FILES="$(FILES
)") \
254 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES
)") \
255 $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR
)") \
256 $(if $(DISABLED_SERVICES),DISABLED_SERVICES="$(DISABLED_SERVICES
)"))
259 $(MAKE) -s _check_profile
260 $(MAKE) -s _check_keys
261 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
262 $(MAKE) -s _call_manifest \
263 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER
)") \
264 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES
)"))
268 @echo 'Variable `PACKAGE` is not set but required by `whatdepends`'
271 @$(MAKE) -s package_reload
272 @$(OPKG) whatdepends -A $(PACKAGE)
274 package_depends: FORCE
276 @echo 'Variable `PACKAGE` is not set but required by `package_depends`'
279 @$(MAKE) -s package_reload
280 @$(OPKG) depends -A $(PACKAGE)
283 .SILENT: help info image manifest whatdepends package_depends