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