build: add checksum target
[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 include $(TOPDIR)/include/host.mk
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
27 include $(INCLUDE_DIR)/version.mk
28 export REVISION
29
30 define Helptext
31 Available Commands:
32 help: This help text
33 info: Show a list of available target profiles
34 clean: Remove images and temporary build files
35 image: Build an image (see below for more information).
36
37 Building images:
38 By default 'make image' will create an image with the default
39 target profile and package set. You can use the following parameters
40 to change that:
41
42 make image PROFILE="<profilename>" # override the default target profile
43 make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
44 make image FILES="<path>" # include extra files from <path>
45 make image BIN_DIR="<path>" # alternative output directory for the images
46 make image EXTRA_IMAGE_NAME="<string>" # Add this to the output image filename (sanitized)
47 endef
48 $(eval $(call shexport,Helptext))
49
50 help: FORCE
51 echo "$$$(call shvar,Helptext)"
52
53
54 # override variables from rules.mk
55 PACKAGE_DIR:=$(TOPDIR)/packages
56 LISTS_DIR:=$(subst $(space),/,$(patsubst %,..,$(subst /,$(space),$(TARGET_DIR))))$(DL_DIR)
57 OPKG:= \
58 IPKG_NO_SCRIPT=1 \
59 IPKG_INSTROOT="$(TARGET_DIR)" \
60 $(STAGING_DIR_HOST)/bin/opkg \
61 -f $(TOPDIR)/repositories.conf \
62 --force-depends \
63 --force-overwrite \
64 --force-postinstall \
65 --cache $(DL_DIR) \
66 --lists-dir $(LISTS_DIR) \
67 --offline-root $(TARGET_DIR) \
68 --add-dest root:/ \
69 --add-arch all:100 \
70 --add-arch $(ARCH_PACKAGES):200
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 ' $($(p)_NAME)'; ) echo ' Packages: $($(p)_PACKAGES)'; \
78 )
79
80 .profiles.mk: .targetinfo
81 $(SCRIPT_DIR)/target-metadata.pl profile_mk $< '$(BOARD)$(if $(SUBTARGET),/$(SUBTARGET))' > $@
82
83 staging_dir/host/.prereq-build: include/prereq-build.mk
84 mkdir -p tmp
85 rm -f tmp/.host.mk
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: "$(BOARD)$(if $(SUBTARGET), ($(BOARDNAME)))"'
100 echo 'Default Packages: $(DEFAULT_PACKAGES)'
101 echo 'Available Profiles:'
102 echo; $(PROFILE_LIST)
103
104 BUILD_PACKAGES:=$(USER_PACKAGES) $(sort $(DEFAULT_PACKAGES) $($(USER_PROFILE)_PACKAGES) kernel)
105 # "-pkgname" in the package list means remove "pkgname" from the package list
106 BUILD_PACKAGES:=$(filter-out $(filter -%,$(BUILD_PACKAGES)) $(patsubst -%,%,$(filter -%,$(BUILD_PACKAGES))),$(BUILD_PACKAGES))
107 PACKAGES:=
108
109 _call_image: staging_dir/host/.prereq-build
110 echo 'Building images for $(BOARD)$(if $($(USER_PROFILE)_NAME), - $($(USER_PROFILE)_NAME))'
111 echo 'Packages: $(BUILD_PACKAGES)'
112 echo
113 rm -rf $(TARGET_DIR)
114 mkdir -p $(TARGET_DIR) $(BIN_DIR) $(TMP_DIR) $(DL_DIR)
115 if [ ! -f "$(PACKAGE_DIR)/Packages" ] || [ ! -f "$(PACKAGE_DIR)/Packages.gz" ] || [ "`find $(PACKAGE_DIR) -cnewer $(PACKAGE_DIR)/Packages.gz`" ]; then \
116 echo "Package list missing or not up-to-date, generating it.";\
117 $(MAKE) package_index; \
118 else \
119 mkdir -p $(TARGET_DIR)/tmp; \
120 $(OPKG) update || true; \
121 fi
122 $(MAKE) package_install
123 ifneq ($(USER_FILES),)
124 $(MAKE) copy_files
125 endif
126 $(MAKE) package_postinst
127 $(MAKE) build_image
128 $(MAKE) checksum
129
130 package_index: FORCE
131 @echo
132 @echo Building package index...
133 @mkdir -p $(TMP_DIR) $(TARGET_DIR)/tmp
134 (cd $(PACKAGE_DIR); $(SCRIPT_DIR)/ipkg-make-index.sh . > Packages && \
135 gzip -9nc Packages > Packages.gz \
136 ) >/dev/null 2>/dev/null
137 $(OPKG) update || true
138
139 package_install: FORCE
140 @echo
141 @echo Installing packages...
142 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/libc_*.ipk $(PACKAGE_DIR)/base/libc_*.ipk))
143 $(OPKG) install $(firstword $(wildcard $(PACKAGE_DIR)/kernel_*.ipk $(PACKAGE_DIR)/base/kernel_*.ipk))
144 $(OPKG) install $(BUILD_PACKAGES)
145 rm -f $(TARGET_DIR)/usr/lib/opkg/lists/*
146
147 copy_files: FORCE
148 @echo
149 @echo Copying extra files
150 @$(call file_copy,$(USER_FILES)/*,$(TARGET_DIR)/)
151
152 package_postinst: FORCE
153 @echo
154 @echo Cleaning up
155 @rm -f $(TARGET_DIR)/tmp/opkg.lock
156 @echo
157 @echo Activating init scripts
158 @mkdir -p $(TARGET_DIR)/etc/rc.d
159 @( \
160 cd $(TARGET_DIR); \
161 for script in ./usr/lib/opkg/info/*.postinst; do \
162 IPKG_INSTROOT=$(TARGET_DIR) $$(which bash) $$script; \
163 done || true \
164 )
165 rm -f $(TARGET_DIR)/usr/lib/opkg/info/*.postinst
166 $(if $(CONFIG_CLEAN_IPKG),rm -rf $(TARGET_DIR)/usr/lib/opkg)
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 checksum: FORCE
175 @echo
176 @echo Calculating checksums...
177 @$(call sha256sums,$(BIN_DIR))
178
179 clean:
180 rm -rf $(TMP_DIR) $(DL_DIR) $(TARGET_DIR) $(BIN_DIR)
181
182
183 info:
184 (unset PROFILE FILES PACKAGES MAKEFLAGS; $(MAKE) -s _call_info)
185
186 PROFILE_FILTER = $(filter DEVICE_$(PROFILE) $(PROFILE),$(PROFILE_NAMES))
187
188 image:
189 ifneq ($(PROFILE),)
190 ifeq ($(PROFILE_FILTER),)
191 @echo 'Profile "$(PROFILE)" does not exist!'
192 @echo 'Use "make info" to get a list of available profile names.'
193 @exit 1
194 endif
195 endif
196 (unset PROFILE FILES PACKAGES MAKEFLAGS; \
197 $(MAKE) _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
203 .SILENT: help info image
204