build: refactor JSON info files to `profiles.json`
[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
31 define Helptext
32 Available Commands:
33 help: This help text
34 info: Show a list of available target profiles
35 clean: Remove images and temporary build files
36 image: Build an image (see below for more information).
37
38 Building images:
39 By default 'make image' will create an image with the default
40 target profile and package set. You can use the following parameters
41 to change that:
42
43 make image PROFILE="<profilename>" # override the default target profile
44 make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
45 make image FILES="<path>" # include extra files from <path>
46 make image BIN_DIR="<path>" # alternative output directory for the images
47 make image EXTRA_IMAGE_NAME="<string>" # Add this to the output image filename (sanitized)
48 make image DISABLED_SERVICES="<svc1> [<svc2> [<svc3> ..]]" # Which services in /etc/init.d/ should be disabled
49
50 Print manifest:
51 List "all" packages which get installed into the image.
52 You can use the following parameters:
53
54 make manifest PROFILE="<profilename>" # override the default target profile
55 make manifest PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
56
57 endef
58 $(eval $(call shexport,Helptext))
59
60 help: FORCE
61 echo "$$$(call shvar,Helptext)"
62
63
64 # override variables from rules.mk
65 PACKAGE_DIR:=$(TOPDIR)/packages
66 LISTS_DIR:=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(TARGET_DIR))))$(DL_DIR)
67 OPKG:=$(call opkg,$(TARGET_DIR)) \
68 -f $(TOPDIR)/repositories.conf \
69 --cache $(DL_DIR) \
70 --lists-dir $(LISTS_DIR)
71
72 include $(INCLUDE_DIR)/target.mk
73 -include .profiles.mk
74
75 USER_PROFILE ?= $(firstword $(PROFILE_NAMES))
76 PROFILE_LIST = $(foreach p,$(PROFILE_NAMES), \
77 echo '$(patsubst DEVICE_%,%,$(p)):'; $(if $($(p)_NAME),echo ' $(subst ','"'"',$($(p)_NAME))'; ) \
78 echo ' Packages: $($(p)_PACKAGES)'; echo ' hasImageMetadata: $($(p)_HAS_IMAGE_METADATA)'; \
79 $(if $($(p)_SUPPORTED_DEVICES),echo ' SupportedDevices: $($(p)_SUPPORTED_DEVICES)';) )
80
81
82 .profiles.mk: .targetinfo
83 @$(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
84
85 staging_dir/host/.prereq-build: include/prereq-build.mk
86 mkdir -p tmp
87 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
88 echo "Prerequisite check failed. Use FORCE=1 to override."; \
89 false; \
90 }
91 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
92 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
93 echo "Preparation failed."; \
94 false; \
95 }
96 endif
97 touch $@
98
99 _call_info: FORCE
100 echo 'Current Target: "$(TARGETID)"'
101 echo 'Current Revision: "$(REVISION)"'
102 echo 'Default Packages: $(DEFAULT_PACKAGES)'
103 echo 'Available Profiles:'
104 echo; $(PROFILE_LIST)
105
106 BUILD_PACKAGES:=$(USER_PACKAGES) $(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
107 # "-pkgname" in the package list means remove "pkgname" from the package list
108 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
109 PACKAGES:=
110
111 _call_image: staging_dir/host/.prereq-build
112 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
113 echo 'Packages: $(BUILD_PACKAGES)'
114 echo
115 rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
116 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
117 $(MAKE) package_reload
118 $(MAKE) package_install
119 $(MAKE) -s prepare_rootfs
120 $(MAKE) -s build_image
121 $(MAKE) -s json_overview_image_info
122 $(MAKE) -s checksum
123
124 _call_manifest: FORCE
125 rm -rf $(TARGET_DIR)
126 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
127 $(MAKE) package_reload >/dev/null
128 $(MAKE) package_install >/dev/null
129 $(OPKG) list-installed
130
131 package_index: FORCE
132 @echo >&2
133 @echo Building package index... >&2
134 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
135 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
136 gzip -9nc Packages > Packages.gz \
137 ) >/dev/null 2>/dev/null
138 $(OPKG) update >&2 || true
139
140 package_reload:
141 if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
142 echo "Package list missing or not up-to-date, generating it." >&2 ;\
143 $(MAKE) package_index; \
144 else \
145 mkdir -p $(TARGET_DIR)/tmp; \
146 $(OPKG) update >&2 || true; \
147 fi
148
149 package_list: FORCE
150 @$(MAKE) -s package_reload
151 @$(OPKG) list --size 2>/dev/null
152
153 package_install: FORCE
154 @echo
155 @echo Installing packages...
156 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
157 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
158 $(OPKG) install $(BUILD_PACKAGES)
159
160 prepare_rootfs: FORCE
161 @echo
162 @echo Finalizing root filesystem...
163
164 $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG)
165 $(call prepare_rootfs,$(TARGET_DIR),$(USER_FILES),$(DISABLED_SERVICES))
166
167
168 build_image: FORCE
169 @echo
170 @echo Building images...
171 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
172 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
173
174 $(BIN_DIR)/profiles.json: FORCE
175 $(if $(CONFIG_JSON_OVERVIEW_IMAGE_INFO), \
176 WORK_DIR=$(BUILD_DIR)/json_info_files \
177 $(SCRIPT_DIR)/json_overview_image_info.py $@ \
178 )
179
180 json_overview_image_info: $(BIN_DIR)/profiles.json
181
182 checksum: FORCE
183 @echo
184 @echo Calculating checksums...
185 @$(call sha256sums,$(BIN_DIR))
186
187 clean:
188 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
189
190
191 info:
192 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
193
194 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
195
196 _check_profile: FORCE
197 ifneq ($(PROFILE),)
198 ifeq ($(PROFILE_FILTER),)
199 @echo 'Profile "$(PROFILE)" does not exist!'
200 @echo 'Use "make info" to get a list of available profile names.'
201 @exit 1
202 endif
203 endif
204
205 image:
206 $(MAKE) -s _check_profile
207 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
208 $(MAKE) -s _call_image \
209 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
210 $(if $(FILES),USER_FILES="$(FILES)") \
211 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
212 $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)") \
213 $(if $(DISABLED_SERVICES),DISABLED_SERVICES="$(DISABLED_SERVICES)"))
214
215 manifest: FORCE
216 $(MAKE) -s _check_profile
217 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
218 $(MAKE) -s _call_manifest \
219 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
220 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)"))
221
222 .SILENT: help info image manifest