5aeedb74dadab41f6b3249a3ce2f1229372ef4d9
[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 make image ROOTFS_PARTSIZE="<size>" # override the default rootfs partition size in MegaBytes
55
56 manifest:
57 List "all" packages which get installed into the image.
58 You can use the following parameters:
59
60 make manifest PROFILE="<profilename>" # override the default target profile
61 make manifest PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
62 make manifest STRIP_ABI=1 # remove ABI version from printed package names
63
64
65 package_whatdepends:
66 List "all" packages that have a dependency on this package
67 You can use the following parameters:
68
69 make package_whatdepends PACKAGE="<pkg>"
70
71 package_depends:
72 List "all" packages dependency of the package
73 You can use the following parameters:
74
75 make package_depends PACKAGE="<pkg>"
76
77 endef
78 $(eval $(call shexport,Helptext))
79
80 help: FORCE
81 echo "$$$(call shvar,Helptext)"
82
83
84 # override variables from rules.mk
85 PACKAGE_DIR:=$(TOPDIR)/packages
86 LISTS_DIR:=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(TARGET_DIR))))$(DL_DIR)
87 export OPKG_KEYS:=$(TOPDIR)/keys
88 OPKG:=$(call opkg,$(TARGET_DIR)) \
89 -f $(TOPDIR)/repositories.conf \
90 --verify-program $(SCRIPT_DIR)/opkg-key \
91 --cache $(DL_DIR) \
92 --lists-dir $(LISTS_DIR)
93
94 include $(INCLUDE_DIR)/target.mk
95 -include .profiles.mk
96
97 USER_PROFILE ?= $(firstword $(PROFILE_NAMES))
98 PROFILE_LIST = $(foreach p,$(PROFILE_NAMES), \
99 echo '$(patsubst DEVICE_%,%,$(p)):'; $(if $($(p)_NAME),echo ' $(subst ','"'"',$($(p)_NAME))'; ) \
100 echo ' Packages: $($(p)_PACKAGES)'; echo ' hasImageMetadata: $($(p)_HAS_IMAGE_METADATA)'; \
101 $(if $($(p)_SUPPORTED_DEVICES),echo ' SupportedDevices: $($(p)_SUPPORTED_DEVICES)';) )
102
103
104 .profiles.mk: .targetinfo
105 @$(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
106
107 staging_dir/host/.prereq-build: include/prereq-build.mk
108 mkdir -p tmp
109 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq IB=1 2>/dev/null || { \
110 echo "Prerequisite check failed. Use FORCE=1 to override."; \
111 false; \
112 }
113 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
114 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
115 echo "Preparation failed."; \
116 false; \
117 }
118 endif
119 touch $@
120
121 _call_info: FORCE
122 echo 'Current Target: "$(TARGETID)"'
123 echo 'Current Architecture: "$(ARCH)"'
124 echo 'Current Revision: "$(REVISION)"'
125 echo 'Default Packages: $(DEFAULT_PACKAGES)'
126 echo 'Available Profiles:'
127 echo; $(PROFILE_LIST)
128
129 BUILD_PACKAGES:=$(USER_PACKAGES) $(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
130 # "-pkgname" in the package list means remove "pkgname" from the package list
131 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
132 PACKAGES:=
133
134 _call_image: staging_dir/host/.prereq-build
135 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
136 echo 'Packages: $(BUILD_PACKAGES)'
137 echo
138 rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
139 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
140 $(MAKE) package_reload
141 $(MAKE) package_install
142 $(MAKE) -s prepare_rootfs
143 $(MAKE) -s build_image
144 $(MAKE) -s json_overview_image_info
145 $(MAKE) -s checksum
146
147 _call_manifest: FORCE
148 rm -rf $(TARGET_DIR)
149 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
150 $(MAKE) package_reload >/dev/null
151 $(MAKE) package_install >/dev/null
152 $(OPKG) list-installed $(if $(STRIP_ABI),--strip-abi)
153
154 package_index: FORCE
155 @echo >&2
156 @echo Building package index... >&2
157 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
158 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
159 gzip -9nc Packages > Packages.gz; \
160 $(if $(CONFIG_SIGNATURE_CHECK), \
161 $(STAGING_DIR_HOST)/bin/usign -S -m Packages -s $(BUILD_KEY)) \
162 ) >/dev/null 2>/dev/null
163 $(OPKG) update >&2 || true
164
165 package_reload:
166 if [ -d "$(PACKAGE_DIR)" ] && ( \
167 [ ! -f "$(PACKAGE_DIR)/Packages" ] || \
168 [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || \
169 [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ] ); then \
170 echo "Package list missing or not up-to-date, generating it." >&2 ;\
171 $(MAKE) package_index; \
172 else \
173 mkdir -p $(TARGET_DIR)/tmp; \
174 $(OPKG) update >&2 || true; \
175 fi
176
177 package_list: FORCE
178 @$(MAKE) -s package_reload
179 @$(OPKG) list --size 2>/dev/null
180
181 package_install: FORCE
182 @echo
183 @echo Installing packages...
184 $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/libc_*.ipk $(PACKAGE_DIR)/libc_*.ipk))
185 $(OPKG) install $(firstword $(wildcard $(LINUX_DIR)/kernel_*.ipk $(PACKAGE_DIR)/kernel_*.ipk))
186 $(OPKG) install $(BUILD_PACKAGES)
187
188 prepare_rootfs: FORCE
189 @echo
190 @echo Finalizing root filesystem...
191
192 $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG)
193 $(if $(CONFIG_SIGNATURE_CHECK), \
194 $(if $(ADD_LOCAL_KEY), \
195 OPKG_KEYS=$(TARGET_DIR)/etc/opkg/keys/ \
196 $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub \
197 ) \
198 )
199 $(call prepare_rootfs,$(TARGET_DIR),$(USER_FILES),$(DISABLED_SERVICES))
200
201 build_image: FORCE
202 @echo
203 @echo Building images...
204 rm -rf $(BUILD_DIR)/json_info_files/
205 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
206 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
207
208 $(BIN_DIR)/profiles.json: FORCE
209 $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
210 WORK_DIR=$(BUILD_DIR)/json_info_files \
211 $(SCRIPT_DIR)/json_overview_image_info.py $@ \
212 )
213
214 json_overview_image_info: $(BIN_DIR)/profiles.json
215
216 checksum: FORCE
217 @echo
218 @echo Calculating checksums...
219 @$(call sha256sums,$(BIN_DIR))
220
221 clean:
222 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
223
224
225 info:
226 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
227
228 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
229
230 _check_profile: FORCE
231 ifneq ($(PROFILE),)
232 ifeq ($(PROFILE_FILTER),)
233 @echo 'Profile "$(PROFILE)" does not exist!'
234 @echo 'Use "make info" to get a list of available profile names.'
235 @exit 1
236 endif
237 endif
238
239 _check_keys: FORCE
240 ifneq ($(CONFIG_SIGNATURE_CHECK),)
241 @if [ ! -s $(BUILD_KEY) -o ! -s $(BUILD_KEY).pub ]; then \
242 echo Generate local signing keys... >&2; \
243 $(STAGING_DIR_HOST)/bin/usign -G \
244 -s $(BUILD_KEY) -p $(BUILD_KEY).pub -c "Local build key"; \
245 $(SCRIPT_DIR)/opkg-key add $(BUILD_KEY).pub; \
246 fi
247 if [ ! -s $(BUILD_KEY).ucert ]; then \
248 echo Generate local certificate... >&2; \
249 $(STAGING_DIR_HOST)/bin/ucert -I \
250 -c $(BUILD_KEY).ucert \
251 -p $(BUILD_KEY).pub \
252 -s $(BUILD_KEY); \
253 fi
254 endif
255
256 image:
257 $(MAKE) -s _check_profile
258 $(MAKE) -s _check_keys
259 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
260 $(MAKE) -s _call_image \
261 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
262 $(if $(FILES),USER_FILES="$(FILES)") \
263 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
264 $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)") \
265 $(if $(DISABLED_SERVICES),DISABLED_SERVICES="$(DISABLED_SERVICES)") \
266 $(if $(ROOTFS_PARTSIZE),CONFIG_TARGET_ROOTFS_PARTSIZE="$(ROOTFS_PARTSIZE)"))
267
268 manifest: FORCE
269 $(MAKE) -s _check_profile
270 $(MAKE) -s _check_keys
271 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
272 $(MAKE) -s _call_manifest \
273 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
274 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)"))
275
276 package_whatdepends: FORCE
277 ifeq ($(PACKAGE),)
278 @echo 'Variable `PACKAGE` is not set but required by `whatdepends`'
279 @exit 1
280 endif
281 @$(MAKE) -s package_reload
282 @$(OPKG) whatdepends -A $(PACKAGE)
283
284 package_depends: FORCE
285 ifeq ($(PACKAGE),)
286 @echo 'Variable `PACKAGE` is not set but required by `package_depends`'
287 @exit 1
288 endif
289 @$(MAKE) -s package_reload
290 @$(OPKG) depends -A $(PACKAGE)
291
292
293 .SILENT: help info image manifest package_whatdepends package_depends