275932577b4c7024e4bb2e496f4c36cbdca0628d
[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 PATH:=$(TOPDIR)/staging_dir/host/bin:$(PATH)
17
18 ifneq ($(OPENWRT_BUILD),1)
19 override OPENWRT_BUILD=1
20 export OPENWRT_BUILD
21 endif
22
23 include rules.mk
24 include $(INCLUDE_DIR)/debug.mk
25 include $(INCLUDE_DIR)/depends.mk
26 include $(INCLUDE_DIR)/rootfs.mk
27
28 include $(INCLUDE_DIR)/version.mk
29 export REVISION
30 export SOURCE_DATE_EPOCH
31
32 define Helptext
33 Available Commands:
34 help: This help text
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
41
42 image:
43 By default 'make image' will create an image with the default
44 target profile and package set. You can use the following parameters
45 to change that:
46
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
54
55 manifest:
56 List "all" packages which get installed into the image.
57 You can use the following parameters:
58
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
62
63
64 package_whatdepends:
65 List "all" packages that have a dependency on this package
66 You can use the following parameters:
67
68 make package_whatdepends PACKAGE="<pkg>"
69
70 package_depends:
71 List "all" packages dependency of the package
72 You can use the following parameters:
73
74 make package_depends PACKAGE="<pkg>"
75
76 endef
77 $(eval $(call shexport,Helptext))
78
79 help: FORCE
80 echo "$$$(call shvar,Helptext)"
81
82
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 \
90 --cache $(DL_DIR) \
91 --lists-dir $(LISTS_DIR)
92
93 include $(INCLUDE_DIR)/target.mk
94 -include .profiles.mk
95
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)';) )
101
102
103 .profiles.mk: .targetinfo
104 @$(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
105
106 staging_dir/host/.prereq-build: include/prereq-build.mk
107 mkdir -p tmp
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."; \
110 false; \
111 }
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."; \
115 false; \
116 }
117 endif
118 touch $@
119
120 _call_info: FORCE
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)
127
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))
131 PACKAGES:=
132
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)'
136 echo
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
144 $(MAKE) -s checksum
145
146 _call_manifest: FORCE
147 rm -rf $(TARGET_DIR)
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)
152
153 package_index: FORCE
154 @echo >&2
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
163
164 package_reload:
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; \
171 else \
172 mkdir -p $(TARGET_DIR)/tmp; \
173 $(OPKG) update >&2 || true; \
174 fi
175
176 package_list: FORCE
177 @$(MAKE) -s package_reload
178 @$(OPKG) list --size 2>/dev/null
179
180 package_install: FORCE
181 @echo
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)
186
187 prepare_rootfs: FORCE
188 @echo
189 @echo Finalizing root filesystem...
190
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 \
196 ) \
197 )
198 $(call prepare_rootfs,$(TARGET_DIR),$(USER_FILES),$(DISABLED_SERVICES))
199
200 build_image: FORCE
201 @echo
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)")
206
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 $@ \
211 )
212
213 json_overview_image_info: $(BIN_DIR)/profiles.json
214
215 checksum: FORCE
216 @echo
217 @echo Calculating checksums...
218 @$(call sha256sums,$(BIN_DIR))
219
220 clean:
221 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
222
223
224 info:
225 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
226
227 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
228
229 _check_profile: FORCE
230 ifneq ($(PROFILE),)
231 ifeq ($(PROFILE_FILTER),)
232 @echo 'Profile "$(PROFILE)" does not exist!'
233 @echo 'Use "make info" to get a list of available profile names.'
234 @exit 1
235 endif
236 endif
237
238 _check_keys: FORCE
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; \
245 fi
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 \
251 -s $(BUILD_KEY); \
252 fi
253 endif
254
255 image:
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)"))
265
266 manifest: FORCE
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)"))
273
274 package_whatdepends: FORCE
275 ifeq ($(PACKAGE),)
276 @echo 'Variable `PACKAGE` is not set but required by `whatdepends`'
277 @exit 1
278 endif
279 @$(MAKE) -s package_reload
280 @$(OPKG) whatdepends -A $(PACKAGE)
281
282 package_depends: FORCE
283 ifeq ($(PACKAGE),)
284 @echo 'Variable `PACKAGE` is not set but required by `package_depends`'
285 @exit 1
286 endif
287 @$(MAKE) -s package_reload
288 @$(OPKG) depends -A $(PACKAGE)
289
290
291 .SILENT: help info image manifest package_whatdepends package_depends