x86: drop 6.1 support
[openwrt/openwrt.git] / target / imagebuilder / files / Makefile
1 # Makefile for OpenWrt
2 #
3 # Copyright (C) 2007-2015 OpenWrt.org
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 TOPDIR:=${CURDIR}
10 LC_ALL:=C
11 LANG:=C
12 export TOPDIR LC_ALL LANG
13 export OPENWRT_VERBOSE=s
14 all: help
15
16 export ORIG_PATH:=$(if $(ORIG_PATH),$(ORIG_PATH),$(PATH))
17 export PATH:=$(TOPDIR)/staging_dir/host/bin:$(PATH)
18
19 ifneq ($(OPENWRT_BUILD),1)
20 override OPENWRT_BUILD=1
21 export OPENWRT_BUILD
22 endif
23
24 include rules.mk
25 include $(INCLUDE_DIR)/debug.mk
26 include $(INCLUDE_DIR)/depends.mk
27 include $(INCLUDE_DIR)/rootfs.mk
28
29 include $(INCLUDE_DIR)/version.mk
30 export REVISION
31 export SOURCE_DATE_EPOCH
32
33 define Helptext
34 Available Commands:
35 help: This help text
36 info: Show a list of available target profiles
37 clean: Remove images and temporary build files
38 image: Build an image (see below for more information).
39 manifest: Show all package that will be installed into the image
40 package_whatdepends: Show which packages have a dependency on this
41 package_depends: Show installation dependency of the package
42
43 image:
44 By default 'make image' will create an image with the default
45 target profile and package set. You can use the following parameters
46 to change that:
47
48 make image PROFILE="<profilename>" # override the default target profile
49 make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
50 make image FILES="<path>" # include extra files from <path>
51 make image BIN_DIR="<path>" # alternative output directory for the images
52 make image EXTRA_IMAGE_NAME="<string>" # Add this to the output image filename (sanitized)
53 make image DISABLED_SERVICES="<svc1> [<svc2> [<svc3> ..]]" # Which services in /etc/init.d/ should be disabled
54 make image ADD_LOCAL_KEY=1 # store locally generated signing key in built images
55 make image ROOTFS_PARTSIZE="<size>" # override the default rootfs partition size in MegaBytes
56
57 manifest:
58 List "all" packages which get installed into the image.
59 You can use the following parameters:
60
61 make manifest PROFILE="<profilename>" # override the default target profile
62 make manifest PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
63 make manifest STRIP_ABI=1 # remove ABI version from printed package names
64
65
66 package_whatdepends:
67 List "all" packages that have a dependency on this package
68 You can use the following parameters:
69
70 make package_whatdepends PACKAGE="<pkg>"
71
72 package_depends:
73 List "all" packages dependency of the package
74 You can use the following parameters:
75
76 make package_depends PACKAGE="<pkg>"
77
78 endef
79 $(eval $(call shexport,Helptext))
80
81 help: FORCE
82 echo "$$$(call shvar,Helptext)"
83
84
85 # override variables from rules.mk
86 PACKAGE_DIR:=$(TOPDIR)/packages
87 LISTS_DIR:=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(TARGET_DIR))))$(DL_DIR)
88 PACKAGE_DIR_ALL:=$(TOPDIR)/packages
89
90 export OPKG_KEYS:=$(TOPDIR)/keys
91 OPKG:=$(call opkg,$(TARGET_DIR)) \
92 -f $(TOPDIR)/repositories.conf \
93 --verify-program $(SCRIPT_DIR)/opkg-key \
94 --cache $(DL_DIR) \
95 --lists-dir $(LISTS_DIR)
96
97 APK:=$(call apk,$(TARGET_DIR)) \
98 --cache-dir $(DL_DIR) \
99 --allow-untrusted
100
101
102 include $(INCLUDE_DIR)/target.mk
103 -include .profiles.mk
104
105 USER_PROFILE ?= $(firstword $(PROFILE_NAMES))
106 PROFILE_LIST = $(foreach p,$(PROFILE_NAMES), \
107 echo '$(patsubst DEVICE_%,%,$(p)):'; $(if $($(p)_NAME),echo ' $(subst ','"'"',$($(p)_NAME))'; ) \
108 echo ' Packages: $($(p)_PACKAGES)'; echo ' hasImageMetadata: $($(p)_HAS_IMAGE_METADATA)'; \
109 $(if $($(p)_SUPPORTED_DEVICES),echo ' SupportedDevices: $($(p)_SUPPORTED_DEVICES)';) )
110
111
112 .profiles.mk: .targetinfo
113 @$(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)/$(SUBTARGET)' > $@
114
115 staging_dir/host/.prereq-build: include/prereq-build.mk
116 mkdir -p tmp
117 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq IB=1 2>/dev/null || { \
118 echo "Prerequisite check failed. Use FORCE=1 to override."; \
119 false; \
120 }
121 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
122 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
123 echo "Preparation failed."; \
124 false; \
125 }
126 endif
127 touch $@
128
129 _call_info: FORCE
130 echo 'Current Target: "$(TARGETID)"'
131 echo 'Current Architecture: "$(ARCH)"'
132 echo 'Current Revision: "$(REVISION)"'
133 echo 'Default Packages: $(DEFAULT_PACKAGES)'
134 echo 'Available Profiles:'
135 echo; $(PROFILE_LIST)
136
137 BUILD_PACKAGES:=$(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
138 # "-pkgname" in the package list means remove "pkgname" from the package list
139 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
140 BUILD_PACKAGES:=$(USER_PACKAGES) $(BUILD_PACKAGES)
141 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
142 PACKAGES:=
143
144 _call_image: staging_dir/host/.prereq-build
145 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
146 echo 'Packages: $(BUILD_PACKAGES)'
147 echo
148 rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
149 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
150 $(MAKE) package_reload
151 $(MAKE) package_install
152 $(MAKE) -s prepare_rootfs
153 $(MAKE) -s build_image
154 $(MAKE) -s json_overview_image_info
155 $(MAKE) -s checksum
156
157 _call_manifest: FORCE
158 rm -rf $(TARGET_DIR)
159 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
160 $(MAKE) package_reload >/dev/null
161 $(MAKE) package_install >/dev/null
162 ifeq ($(CONFIG_USE_APK),)
163 $(OPKG) list-installed $(if $(STRIP_ABI),--strip-abi)
164 else
165 $(APK) list --quiet --manifest --no-network
166 endif
167
168 package_index: FORCE
169 @echo >&2
170 @echo Building package index... >&2
171 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
172 ifeq ($(CONFIG_USE_APK),)
173 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
174 gzip -9nc Packages > Packages.gz; \
175 $(if $(CONFIG_SIGNATURE_CHECK), \
176 $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY)) \
177 ) >/dev/null 2>/dev/null
178 $(OPKG) update >&2 || true
179 else
180 (cd $(PACKAGE_DIR); $(APK) mkndx --output packages.adb *.apk) >&2
181 endif
182
183 package_reload:
184 ifeq ($(CONFIG_USE_APK),)
185 if [ -d "$(PACKAGE_DIR)" ] && ( \
186 [ ! -f "$(PACKAGE_DIR)/Packages" ] || \
187 [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || \
188 [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ] ); then \
189 echo "Package list missing or not up-to-date, generating it." >&2 ;\
190 $(MAKE) package_index; \
191 else \
192 mkdir -p $(TARGET_DIR)/tmp; \
193 $(OPKG) update >&2 || true; \
194 fi
195 else
196 if [ -d "$(PACKAGE_DIR)" ] && ( \
197 [ ! -f "$(PACKAGE_DIR)/packages.adb" ] || \
198 [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/packages.adb`" ] ); then \
199 echo "Package list missing or not up-to-date, generating it." >&2 ;\
200 $(MAKE) package_index; \
201 else \
202 mkdir -p $(TARGET_DIR)/tmp; \
203 $(APK) update >&2 || true; \
204 fi
205 endif
206
207 package_list: FORCE
208 @$(MAKE) -s package_reload
209 ifeq ($(CONFIG_USE_APK),)
210 @$(OPKG) list --size 2>/dev/null
211 else
212 @$(APK) list --size 2>/dev/null
213 endif
214
215 package_install: FORCE
216 @echo
217 @echo Installing packages...
218 ifeq ($(CONFIG_USE_APK),)
219 $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/libc_*.ipk $(PACKAGE_DIR)/libc_*.ipk))
220 $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/kernel_*.ipk $(PACKAGE_DIR)/kernel_*.ipk))
221 $(OPKG) install $(BUILD_PACKAGES)
222 else
223 $(APK) add --initdb --no-scripts $(firstword $(wildcard $(LINUX_DIR)/libc-*.apk $(PACKAGE_DIR)/libc_*.apk))
224 $(APK) add --no-scripts $(firstword $(wildcard $(LINUX_DIR)/kernel-*.apk $(PACKAGE_DIR)/kernel_*.apk))
225 $(APK) add --no-scripts $(BUILD_PACKAGES)
226 endif
227
228 prepare_rootfs: FORCE
229 @echo
230 @echo Finalizing root filesystem...
231
232 $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG)
233 ifeq ($(CONFIG_USE_APK),)
234 $(if $(CONFIG_SIGNATURE_CHECK), \
235 $(if $(ADD_LOCAL_KEY), \
236 OPKG_KEYS=$(TARGET_DIR)/etc/opkg/keys/ \
237 $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub \
238 ) \
239 )
240 endif
241 $(call prepare_rootfs,$(TARGET_DIR),$(USER_FILES),$(DISABLED_SERVICES))
242
243 build_image: FORCE
244 @echo
245 @echo Building images...
246 rm -rf $(BUILD_DIR)/json_info_files/
247 if [ -d "target/linux/feeds/$(BOARD)" ]; then \
248 $(NO_TRACE_MAKE) -C target/linux/feeds/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
249 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)"); \
250 else \
251 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
252 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)"); \
253 fi
254
255 $(BIN_DIR)/profiles.json: FORCE
256 $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
257 WORK_DIR=$(BUILD_DIR)/json_info_files \
258 $(SCRIPT_DIR)/json_overview_image_info.py $@ \
259 )
260
261 json_overview_image_info: $(BIN_DIR)/profiles.json
262
263 checksum: FORCE
264 @echo
265 @echo Calculating checksums...
266 @$(call sha256sums,$(BIN_DIR))
267
268 clean:
269 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
270
271
272 info:
273 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
274
275 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
276
277 _check_profile: FORCE
278 ifneq ($(PROFILE),)
279 ifeq ($(PROFILE_FILTER),)
280 @echo 'Profile "$(PROFILE)" does not exist!'
281 @echo 'Use "make info" to get a list of available profile names.'
282 @exit 1
283 endif
284 endif
285
286 _check_keys: FORCE
287 ifeq ($(CONFIG_USE_APK),)
288 ifneq ($(CONFIG_SIGNATURE_CHECK),)
289 @if [ ! -s $(BUILD_KEY) -o ! -s $(BUILD_KEY).pub ]; then \
290 echo Generate local signing keys... >&2; \
291 $(STAGING_DIR_HOST)/bin/usign -G \
292 -s $(BUILD_KEY) -p $(BUILD_KEY).pub -c "Local build key"; \
293 $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub; \
294 fi
295 if [ ! -s $(BUILD_KEY).ucert ]; then \
296 echo Generate local certificate... >&2; \
297 $(STAGING_DIR_HOST)/bin/ucert -I \
298 -c $(BUILD_KEY).ucert \
299 -p $(BUILD_KEY).pub \
300 -s $(BUILD_KEY); \
301 fi
302 endif
303 else
304 # TODO
305 endif
306
307 image:
308 $(MAKE) -s _check_profile
309 $(MAKE) -s _check_keys
310 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
311 $(MAKE) -s _call_image \
312 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
313 $(if $(FILES),USER_FILES="$(FILES)") \
314 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
315 $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)") \
316 $(if $(DISABLED_SERVICES),DISABLED_SERVICES="$(DISABLED_SERVICES)") \
317 $(if $(ROOTFS_PARTSIZE),CONFIG_TARGET_ROOTFS_PARTSIZE="$(ROOTFS_PARTSIZE)"))
318
319 manifest: FORCE
320 $(MAKE) -s _check_profile
321 $(MAKE) -s _check_keys
322 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
323 $(MAKE) -s _call_manifest \
324 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
325 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)"))
326
327 package_whatdepends: FORCE
328 ifeq ($(PACKAGE),)
329 @echo 'Variable `PACKAGE` is not set but required by `whatdepends`'
330 @exit 1
331 endif
332 @$(MAKE) -s package_reload
333 ifeq ($(CONFIG_USE_APK),)
334 @$(OPKG) list --depends $(PACKAGE)
335 else
336 @$(APK) list --depends $(PACKAGE)
337 endif
338
339 package_depends: FORCE
340 ifeq ($(PACKAGE),)
341 @echo 'Variable `PACKAGE` is not set but required by `package_depends`'
342 @exit 1
343 endif
344 @$(MAKE) -s package_reload
345 ifeq ($(CONFIG_USE_APK),)
346 @$(OPKG) depends -A $(PACKAGE)
347 else
348 @$(OPKG) whatdepends -A $(PACKAGE)
349 endif
350
351 .SILENT: help info image manifest package_whatdepends package_depends