22b2731358a31e7a635dfbfdd900e30fe8d90f7e
[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 [ "$($(p)_SUPPORTED_DEVICES)" ] && echo ' SupportedDevices: $($(p)_SUPPORTED_DEVICES)'; )
80
81 .profiles.mk: .targetinfo
82 @$(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
83
84 staging_dir/host/.prereq-build: include/prereq-build.mk
85 mkdir -p tmp
86 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
87 echo "Prerequisite check failed. Use FORCE=1 to override."; \
88 false; \
89 }
90 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
91 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
92 echo "Preparation failed."; \
93 false; \
94 }
95 endif
96 touch $@
97
98 _call_info: FORCE
99 echo 'Current Target: "$(TARGETID)"'
100 echo 'Current Revision: "$(REVISION)"'
101 echo 'Default Packages: $(DEFAULT_PACKAGES)'
102 echo 'Available Profiles:'
103 echo; $(PROFILE_LIST)
104
105 BUILD_PACKAGES:=$(USER_PACKAGES) $(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
106 # "-pkgname" in the package list means remove "pkgname" from the package list
107 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
108 PACKAGES:=
109
110 _call_image: staging_dir/host/.prereq-build
111 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
112 echo 'Packages: $(BUILD_PACKAGES)'
113 echo
114 rm -rf $(TARGET_DIR) $(TARGET_DIR_ORIG)
115 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
116 $(MAKE) package_reload
117 $(MAKE) package_install
118 $(MAKE) -s prepare_rootfs
119 $(MAKE) -s build_image
120 $(MAKE) -s checksum
121
122 _call_manifest: FORCE
123 rm -rf $(TARGET_DIR)
124 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
125 $(MAKE) package_reload >/dev/null
126 $(MAKE) package_install >/dev/null
127 $(OPKG) list-installed
128
129 package_index: FORCE
130 @echo >&2
131 @echo Building package index... >&2
132 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
133 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
134 gzip -9nc Packages > Packages.gz \
135 ) >/dev/null 2>/dev/null
136 $(OPKG) update >&2 || true
137
138 package_reload:
139 if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
140 echo "Package list missing or not up-to-date, generating it." >&2 ;\
141 $(MAKE) package_index; \
142 else \
143 mkdir -p $(TARGET_DIR)/tmp; \
144 $(OPKG) update >&2 || true; \
145 fi
146
147 package_list: FORCE
148 @$(MAKE) -s package_reload
149 @$(OPKG) list --size 2>/dev/null
150
151 package_install: FORCE
152 @echo
153 @echo Installing packages...
154 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
155 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
156 $(OPKG) install $(BUILD_PACKAGES)
157
158 prepare_rootfs: FORCE
159 @echo
160 @echo Finalizing root filesystem...
161
162 $(CP) $(TARGET_DIR) $(TARGET_DIR_ORIG)
163 $(call prepare_rootfs,$(TARGET_DIR),$(USER_FILES),$(DISABLED_SERVICES))
164
165 build_image: FORCE
166 @echo
167 @echo Building images...
168 $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \
169 $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)")
170
171 checksum: FORCE
172 @echo
173 @echo Calculating checksums...
174 @$(call sha256sums,$(BIN_DIR))
175
176 clean:
177 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
178
179
180 info:
181 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
182
183 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
184
185 _check_profile: FORCE
186 ifneq ($(PROFILE),)
187 ifeq ($(PROFILE_FILTER),)
188 @echo 'Profile "$(PROFILE)" does not exist!'
189 @echo 'Use "make info" to get a list of available profile names.'
190 @exit 1
191 endif
192 endif
193
194 image:
195 $(MAKE) -s _check_profile
196 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
197 $(MAKE) -s _call_image \
198 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
199 $(if $(FILES),USER_FILES="$(FILES)") \
200 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)") \
201 $(if $(BIN_DIR),BIN_DIR="$(BIN_DIR)") \
202 $(if $(DISABLED_SERVICES),DISABLED_SERVICES="$(DISABLED_SERVICES)"))
203
204 manifest: FORCE
205 $(MAKE) -s _check_profile
206 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
207 $(MAKE) -s _call_manifest \
208 $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \
209 $(if $(PACKAGES),USER_PACKAGES="$(PACKAGES)"))
210
211 .SILENT: help info image manifest