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_whatdepends
: Show which packages have a dependency on this
40 package_depends
: Show installation dependency of the package
43 By default
'make image' will create an image with the default
44 target profile and package set. You can use the following parameters
47 make image PROFILE
="<profilename>" # override the default target profile
48 make image PACKAGES
="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
49 make image FILES
="<path>" # include extra files from <path>
50 make image BIN_DIR
="<path>" # alternative output directory for the images
51 make image EXTRA_IMAGE_NAME
="<string>" # Add this to the output image filename (sanitized)
52 make image DISABLED_SERVICES
="<svc1> [<svc2> [<svc3> ..]]" # Which services in /etc/init.d/ should be disabled
53 make image ADD_LOCAL_KEY
=1 # store locally generated signing key in built images
56 List
"all" packages which
get installed into the image.
57 You can use the following parameters
:
59 make manifest PROFILE
="<profilename>" # override the default target profile
60 make manifest PACKAGES
="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
61 make manifest STRIP_ABI
=1 # remove ABI version from printed package names
65 List
"all" packages that have a dependency on this package
66 You can use the following parameters
:
68 make package_whatdepends PACKAGE
="<pkg>"
71 List
"all" packages dependency of the package
72 You can use the following parameters
:
74 make package_depends PACKAGE
="<pkg>"
77 $(eval
$(call shexport
,Helptext
))
80 echo
"$$$(call shvar,Helptext)"
83 # override variables from rules.mk
84 PACKAGE_DIR
:=$(TOPDIR
)/packages
85 LISTS_DIR
:=$(subst $(space
),/,$(patsubst %,..
,$(subst /,$(space
),$(TARGET_DIR
))))$(DL_DIR
)
86 export OPKG_KEYS
:=$(TOPDIR
)/keys
87 OPKG
:=$(call opkg
,$(TARGET_DIR
)) \
88 -f
$(TOPDIR
)/repositories.conf \
89 --verify-program
$(SCRIPT_DIR
)/opkg-key \
91 --lists-dir
$(LISTS_DIR
)
93 include $(INCLUDE_DIR
)/target.mk
96 USER_PROFILE ?
= $(firstword $(PROFILE_NAMES
))
97 PROFILE_LIST
= $(foreach p
,$(PROFILE_NAMES
), \
98 echo
'$(patsubst DEVICE_%,%,$(p)):'; $(if
$($(p
)_NAME
),echo
' $(subst ','"'"',$($(p)_NAME))'; ) \
99 echo ' Packages: $($(p)_PACKAGES)'; echo ' hasImageMetadata: $($(p)_HAS_IMAGE_METADATA)'; \
100 $(if $($(p)_SUPPORTED_DEVICES),echo ' SupportedDevices: $($(p)_SUPPORTED_DEVICES)';) )
103 .profiles.mk: .targetinfo
104 @$(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
106 staging_dir/host/.prereq-build: include/prereq-build.mk
108 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq IB=1 2>/dev/null || { \
109 echo "Prerequisite
check failed. Use FORCE
=1 to
override.
"; \
112 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
113 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
114 echo "Preparation failed.
"; \
121 echo 'Current Target: "$(TARGETID
)"'
122 echo 'Current Architecture: "$(ARCH
)"'
123 echo 'Current Revision: "$(REVISION
)"'
124 echo 'Default Packages: $(DEFAULT_PACKAGES)'
125 echo 'Available Profiles:'
126 echo; $(PROFILE_LIST)
128 BUILD_PACKAGES:=$(USER_PACKAGES) $(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
129 # "-pkgname
" in the package list means remove "pkgname
" from the package list
130 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
133 _call_image: staging_dir/host/.prereq-build
134 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
135 echo 'Packages: $(BUILD_PACKAGES)'
137 rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
138 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
139 $(MAKE) package_reload
140 $(MAKE) package_install
141 $(MAKE) -s prepare_rootfs
142 $(MAKE) -s build_image
143 $(MAKE) -s json_overview_image_info
146 _call_manifest: FORCE
148 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
149 $(MAKE) package_reload >/dev/null
150 $(MAKE) package_install >/dev/null
151 $(OPKG) list-installed $(if $(STRIP_ABI),--strip-abi)
155 @echo Building package index... >&2
156 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
157 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
158 gzip -9nc Packages > Packages.gz; \
159 $(if $(CONFIG_SIGNATURE_CHECK), \
160 $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY)) \
161 ) >/dev/null 2>/dev/null
162 $(OPKG) update >&2 || true
165 if [ -d "$(PACKAGE_DIR
)" ] && ( \
166 [ ! -f "$(PACKAGE_DIR
)/Packages
" ] || \
167 [ ! -f "$(PACKAGE_DIR
)/Packages.gz
" ] || \
168 [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ] ); then \
169 echo "Package list missing or not up-to-date
, generating it.
" >&2 ;\
170 $(MAKE) package_index; \
172 mkdir -p $(TARGET_DIR)/tmp; \
173 $(OPKG) update >&2 || true; \
177 @$(MAKE) -s package_reload
178 @$(OPKG) list --size 2>/dev/null
180 package_install: FORCE
182 @echo Installing packages...
183 $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/libc_*.ipk $(PACKAGE_DIR)/libc_*.ipk))
184 $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/kernel_*.ipk $(PACKAGE_DIR)/kernel_*.ipk))
185 $(OPKG) install $(BUILD_PACKAGES)
187 prepare_rootfs: FORCE
189 @echo Finalizing root filesystem...
191 $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG)
192 $(if $(CONFIG_SIGNATURE_CHECK), \
193 $(if $(ADD_LOCAL_KEY), \
194 OPKG_KEYS=$(TARGET_DIR)/etc/opkg/keys/ \
195 $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub \
198 $(call prepare_rootfs,$(TARGET_DIR),$(USER_FILES),$(DISABLED_SERVICES))
202 @echo Building images...
203 rm -rf $(BUILD_DIR)/json_info_files/
204 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME
)" \
205 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE
)")
207 $(BIN_DIR)/profiles.json: FORCE
208 $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
209 WORK_DIR=$(BUILD_DIR)/json_info_files \
210 $(SCRIPT_DIR)/json_overview_image_info.py $@ \
213 json_overview_image_info: $(BIN_DIR)/profiles.json
217 @echo Calculating checksums...
218 @$(call sha256sums,$(BIN_DIR))
221 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
225 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
227 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
229 _check_profile: FORCE
231 ifeq ($(PROFILE_FILTER),)
232 @echo 'Profile "$(PROFILE
)" does not exist!'
233 @echo 'Use "make
info" to get a list of available profile names.'
239 ifneq ($(CONFIG_SIGNATURE_CHECK),)
240 @if [ ! -s $(BUILD_KEY) -o ! -s $(BUILD_KEY).pub ]; then \
241 echo Generate local signing keys... >&2; \
242 $(STAGING_DIR_HOST)/bin/usign -G \
243 -s $(BUILD_KEY) -p $(BUILD_KEY).pub -c "Local build key
"; \
244 $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub; \
246 if [ ! -s $(BUILD_KEY).ucert ]; then \
247 echo Generate local certificate... >&2; \
248 $(STAGING_DIR_HOST)/bin/ucert -I \
249 -c $(BUILD_KEY).ucert \
250 -p $(BUILD_KEY).pub \
256 $(MAKE) -s _check_profile
257 $(MAKE) -s _check_keys
258 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
259 $(MAKE) -s _call_image \
260 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER
)") \
261 $(if $(FILES),USER_FILES="$(FILES
)") \
262 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES
)") \
263 $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR
)") \
264 $(if $(DISABLED_SERVICES),DISABLED_SERVICES="$(DISABLED_SERVICES
)"))
267 $(MAKE) -s _check_profile
268 $(MAKE) -s _check_keys
269 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
270 $(MAKE) -s _call_manifest \
271 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER
)") \
272 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES
)"))
274 package_whatdepends: FORCE
276 @echo 'Variable `PACKAGE` is not set but required by `whatdepends`'
279 @$(MAKE) -s package_reload
280 @$(OPKG) whatdepends -A $(PACKAGE)
282 package_depends: FORCE
284 @echo 'Variable `PACKAGE` is not set but required by `package_depends`'
287 @$(MAKE) -s package_reload
288 @$(OPKG) depends -A $(PACKAGE)
291 .SILENT: help info image manifest package_whatdepends package_depends