enable travis notification
[openadk.git] / mk / image.mk
blobb880e48af0c7772dfac7368669c3f0079ef820b1
1 # This file is part of the OpenADK project. OpenADK is copyrighted
2 # material, please see the LICENCE file in the top-level directory.
4 ifeq ($(ADK_RUNTIME_FIX_PERMISSION),y)
5 FAKEROOT:=$(STAGING_HOST_DIR)/usr/bin/fakeroot --
6 else
7 FAKEROOT:=
8 endif
10 ifeq ($(ADK_TARGET_OS_LINUX),y)
11 # relative paths, like 'mksh' or '../usr/bin/foosh'
12 ifeq (${ADK_BINSH_ASH},y)
13 BINSH:=ash
14 else ifeq (${ADK_BINSH_BASH},y)
15 BINSH:=bash
16 else ifeq (${ADK_BINSH_SASH},y)
17 BINSH:=sash
18 else ifeq (${ADK_BINSH_HUSH},y)
19 BINSH:=hush
20 else ifeq (${ADK_BINSH_MKSH},y)
21 BINSH:=mksh
22 else ifeq (${ADK_BINSH_ZSH},y)
23 BINSH:=zsh
24 else
25 $(error No /bin/sh configured!)
26 endif
28 # absolute paths
29 ifeq (${ADK_ROOTSH_ASH},y)
30 ROOTSH:=/bin/ash
31 else ifeq (${ADK_ROOTSH_BASH},y)
32 ROOTSH:=/bin/bash
33 else ifeq (${ADK_ROOTSH_SASH},y)
34 ROOTSH:=/bin/sash
35 else ifeq (${ADK_ROOTSH_HUSH},y)
36 ROOTSH:=/bin/hush
37 else ifeq (${ADK_ROOTSH_MKSH},y)
38 ROOTSH:=/bin/mksh
39 else ifeq (${ADK_ROOTSH_TCSH},y)
40 ROOTSH:=/usr/bin/tcsh
41 else ifeq (${ADK_ROOTSH_ZSH},y)
42 ROOTSH:=/bin/zsh
43 else
44 $(error No login shell configured!)
45 endif
46 endif
48 imageprepare: image-prepare-post extra-install prelink
50 # if an extra directory exist in ADK_TOPDIR, copy all content over the
51 # root directory, do the same if make extra=/dir/to/extra is used
52 extra-install:
53 @-if [ -h ${TARGET_DIR}/etc/resolv.conf -a -f $(ADK_TOPDIR)/extra/etc/resolv.conf ];then \
54 rm ${TARGET_DIR}/etc/resolv.conf;\
56 @if [ -d $(ADK_TOPDIR)/extra ];then $(CP) $(ADK_TOPDIR)/extra/* ${TARGET_DIR};fi
57 @if [ ! -z $(extra) ];then $(CP) $(extra)/* ${TARGET_DIR};fi
59 image-prepare-post:
60 $(BASH) $(ADK_TOPDIR)/scripts/update-rcconf
61 rng=/dev/arandom; test -e $$rng || rng=/dev/urandom; \
62 dd if=$$rng bs=512 count=1 >>${TARGET_DIR}/etc/.rnd 2>/dev/null; \
63 chmod 600 ${TARGET_DIR}/etc/.rnd
64 -for dir in X11 truetype; do \
65 if [ -d ${TARGET_DIR}/usr/share/fonts/$${dir} ];then \
66 for i in $$(ls ${TARGET_DIR}/usr/share/fonts/$${dir}/);do \
67 mkfontdir ${TARGET_DIR}/usr/share/fonts/$${dir}/$${i}; \
68 mkfontscale ${TARGET_DIR}/usr/share/fonts/$${dir}/$${i}; \
69 done; \
70 fi; \
71 done
72 $(SED) '/^root:/s!:/bin/sh$$!:${ROOTSH}!' ${TARGET_DIR}/etc/passwd
73 -rm -f ${TARGET_DIR}/bin/sh
74 ln -sf ${BINSH} ${TARGET_DIR}/bin/sh
75 test -z $(GIT) || \
76 $(GIT) log -1|head -1|sed -e 's#commit ##' \
77 > $(TARGET_DIR)/etc/.adkgithash
78 echo $(ADK_APPLIANCE_VERSION) > $(TARGET_DIR)/etc/.adkversion
79 echo $(ADK_TARGET_SYSTEM) > $(TARGET_DIR)/etc/.adktarget
80 $(TARGET_CC) -v 2> $(TARGET_DIR)/etc/.adkcompiler
81 $(TARGET_LD) -v > $(TARGET_DIR)/etc/.adklinker
82 ifneq (${ADK_PACKAGE_CONFIG_IN_ETC},)
83 gzip -9c ${ADK_TOPDIR}/.config > $(TARGET_DIR)/etc/adkconfig.gz
84 chmod 600 $(TARGET_DIR)/etc/adkconfig.gz
85 endif
86 ifneq ($(ADK_TARGET_ARCH_AARCH64)$(ADK_TARGET_ARCH_X86_64)$(ADK_TARGET_ARCH_PPC64)$(ADK_TARGET_ARCH_SPARC64)$(ADK_TARGET_ABI_N32)$(ADK_TARGET_ABI_N64),)
87 test ! -d ${TARGET_DIR}/lib || mv ${TARGET_DIR}/lib/* ${TARGET_DIR}/${ADK_TARGET_LIBC_PATH}
88 test ! -d ${TARGET_DIR}/lib || rm -rf ${TARGET_DIR}/lib
89 ln -sf /${ADK_TARGET_LIBC_PATH} ${TARGET_DIR}/lib
90 mkdir -p ${TARGET_DIR}/usr/${ADK_TARGET_LIBC_PATH} 2>/dev/null
91 -test ! -d ${TARGET_DIR}/usr/lib || mv ${TARGET_DIR}/usr/lib/* ${TARGET_DIR}/usr/${ADK_TARGET_LIBC_PATH} 2>/dev/null
92 test ! -d ${TARGET_DIR}/usr/lib || rm -rf ${TARGET_DIR}/usr/lib/
93 (cd ${TARGET_DIR}/usr ; ln -sf ${ADK_TARGET_LIBC_PATH} lib)
94 endif
95 ifeq ($(ADK_TARGET_ARCH_S390),y)
96 (cd ${TARGET_DIR}/; ln -sf lib lib64)
97 endif
99 ifeq (${ADK_PRELINK},)
100 prelink:
101 else
102 ${TARGET_DIR}/etc/prelink.conf:
103 echo '/' > $@
105 prelink: ${TARGET_DIR}/etc/prelink.conf
106 $(TRACE) target/prelink
107 ${TARGET_CROSS}prelink ${ADK_PRELINK_OPTS} \
108 --ld-library-path=${STAGING_TARGET_DIR}/usr/lib:${STAGING_TARGET_DIR}/lib \
109 --root=${TARGET_DIR} -a $(MAKE_TRACE)
110 endif
112 KERNEL_PKGDIR:=$(LINUX_BUILD_DIR)/kernel-pkg
113 KERNEL_PKG:=$(PACKAGE_DIR)/kernel_$(KERNEL_VERSION)_$(ADK_TARGET_CPU_ARCH).$(PKG_SUFFIX)
114 TARGET_KERNEL= ${ADK_TARGET_SYSTEM}-${ADK_TARGET_FS}-kernel
115 INITRAMFS= ${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}
116 ROOTFSSQUASHFS= ${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}.img
117 ROOTFSJFFS2= ${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-jffs2.img
118 ROOTFSTARBALL= ${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}+kernel.tar.xz
119 ROOTFSUSERTARBALL= ${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}-${ADK_TARGET_FS}.tar.xz
120 ROOTFSISO= ${ADK_TARGET_SYSTEM}-${ADK_TARGET_LIBC}.iso
122 kernel-package: kernel-strip
123 $(START_TRACE) "target/$(ADK_TARGET_ARCH)-create-kernel-package.. "
124 rm -rf $(KERNEL_PKGDIR)
125 @mkdir -p $(KERNEL_PKGDIR)/boot
126 cp $(BUILD_DIR)/$(TARGET_KERNEL) $(KERNEL_PKGDIR)/boot/kernel
127 @${BASH} ${SCRIPT_DIR}/make-ipkg-dir.sh ${KERNEL_PKGDIR} \
128 ../linux/kernel.control ${KERNEL_VERSION} ${ADK_TARGET_CPU_ARCH}
129 $(PKG_BUILD) $(KERNEL_PKGDIR) $(PACKAGE_DIR) $(MAKE_TRACE)
130 $(PKG_INSTALL) $(KERNEL_PKG) $(MAKE_TRACE)
131 $(CMD_TRACE) " done"
132 $(END_TRACE)
134 ${FW_DIR}/${ROOTFSTARBALL}: ${TARGET_DIR}/.adk kernel-package
135 cd ${TARGET_DIR}; find . | sed -n '/^\.\//s///p' | \
136 sed "s#\(.*\)#:0:0::::::\1#" | sort | \
137 ${STAGING_HOST_DIR}/usr/bin/cpio -o -Hustar -P | $(XZ) -c >$@
138 ifeq ($(ADK_TARGET_QEMU),y)
139 @cp $(KERNEL) $(FW_DIR)/$(TARGET_KERNEL)
140 endif
142 ${FW_DIR}/${ROOTFSUSERTARBALL}: ${TARGET_DIR}/.adk
143 cd ${TARGET_DIR}; find . | grep -v ./boot/ | sed -n '/^\.\//s///p' | \
144 sed "s#\(.*\)#:0:0::::::\1#" | sort | \
145 ${STAGING_HOST_DIR}/usr/bin/cpio -o -Hustar -P | $(XZ) -c >$@
147 ${STAGING_TARGET_DIR}/${INITRAMFS}_list: ${TARGET_DIR}/.adk
148 env PATH='${HOST_PATH}' $(BASH) ${LINUX_DIR}/scripts/gen_initramfs_list.sh -u squash -g squash \
149 ${TARGET_DIR}/ >$@
151 echo "nod /dev/console 0644 0 0 c 5 1"; \
152 echo "nod /dev/tty 0644 0 0 c 5 0"; \
153 for i in 0 1 2 3 4; do \
154 echo "nod /dev/tty$$i 0644 0 0 c 4 $$$$i"; \
155 done; \
156 echo "nod /dev/null 0644 0 0 c 1 3"; \
157 echo "nod /dev/ram 0655 0 0 b 1 1"; \
158 echo "nod /dev/ttyS0 0660 0 0 c 4 64"; \
159 echo "nod /dev/ttyS1 0660 0 0 c 4 65"; \
160 echo "nod /dev/ttyAMA0 0660 0 0 c 204 64"; \
161 echo "nod /dev/ttyAMA1 0660 0 0 c 204 65"; \
162 echo "nod /dev/ttySC0 0660 0 0 c 204 8"; \
163 echo "nod /dev/ttySC1 0660 0 0 c 204 9"; \
164 echo "nod /dev/ttyBF0 0660 0 0 c 204 64"; \
165 echo "nod /dev/ttyBF1 0660 0 0 c 204 65"; \
166 ) >>$@
169 ${FW_DIR}/${INITRAMFS}: ${STAGING_TARGET_DIR}/${INITRAMFS}_list
170 ${LINUX_DIR}/usr/gen_init_cpio ${STAGING_TARGET_DIR}/${INITRAMFS}_list | \
171 ${ADK_COMPRESSION_TOOL} -c >$@
173 ${BUILD_DIR}/root.squashfs: ${TARGET_DIR}/.adk
174 ${STAGING_HOST_DIR}/usr/bin/mksquashfs ${TARGET_DIR} \
175 ${BUILD_DIR}/root.squashfs -comp xz \
176 -nopad -noappend -root-owned $(MAKE_TRACE)
178 ${FW_DIR}/${ROOTFSJFFS2}: ${TARGET_DIR}
179 ${STAGING_HOST_DIR}/usr/bin/mkfs.jffs2 $(ADK_JFFS2_OPTS) -q -r ${TARGET_DIR} \
180 --pad=$(ADK_TARGET_MTD_SIZE) -o ${FW_DIR}/${ROOTFSJFFS2} $(MAKE_TRACE)
182 createinitramfs: ${STAGING_TARGET_DIR}/${INITRAMFS}_list
183 ${SED} 's/.*CONFIG_\(RD_\|BLK_DEV_INITRD\|INITRAMFS_\).*//' \
184 ${LINUX_DIR}/.config
186 echo "CONFIG_BLK_DEV_INITRD=y"; \
187 echo "CONFIG_ACPI_INITRD_TABLE_OVERRIDE=n"; \
188 echo 'CONFIG_INITRAMFS_SOURCE="${STAGING_TARGET_DIR}/${INITRAMFS}_list"'; \
189 echo '# CONFIG_INITRAMFS_COMPRESSION_NONE is not set'; \
190 echo 'CONFIG_CRC32_BIT=y'; \
191 echo '# CONFIG_CRC32_SELFTEST is not set'; \
192 echo '# CONFIG_CRC32_SLICEBY8 is not set'; \
193 echo '# CONFIG_CRC32_SLICEBY4 is not set'; \
194 echo '# CONFIG_CRC32_SARWATE is not set'; \
195 echo 'CONFIG_INITRAMFS_ROOT_UID=0'; \
196 echo 'CONFIG_INITRAMFS_ROOT_GID=0'; \
197 ) >> ${LINUX_DIR}/.config
198 ifeq ($(ADK_KERNEL_COMP_XZ),y)
199 echo "CONFIG_RD_BZIP2=n" >> ${LINUX_DIR}/.config
200 echo "CONFIG_RD_GZIP=n" >> ${LINUX_DIR}/.config
201 echo "CONFIG_RD_LZMA=n" >> ${LINUX_DIR}/.config
202 echo "CONFIG_RD_LZ4=n" >> ${LINUX_DIR}/.config
203 echo "CONFIG_RD_LZO=n" >> ${LINUX_DIR}/.config
204 echo "CONFIG_RD_XZ=y" >> ${LINUX_DIR}/.config
205 echo "CONFIG_INITRAMFS_COMPRESSION_XZ=y" >> ${LINUX_DIR}/.config
206 echo "CONFIG_XZ_DEC_X86=n" >> ${LINUX_DIR}/.config
207 echo "CONFIG_XZ_DEC_POWERPC=n" >> ${LINUX_DIR}/.config
208 echo "CONFIG_XZ_DEC_IA64=n" >> ${LINUX_DIR}/.config
209 echo "CONFIG_XZ_DEC_ARM=n" >> ${LINUX_DIR}/.config
210 echo "CONFIG_XZ_DEC_ARMTHUMB=n" >> ${LINUX_DIR}/.config
211 echo "CONFIG_XZ_DEC_SPARC=n" >> ${LINUX_DIR}/.config
212 echo "CONFIG_XZ_DEC_TEST=n" >> ${LINUX_DIR}/.config
213 endif
214 ifeq ($(ADK_KERNEL_COMP_LZ4),y)
215 echo "CONFIG_RD_XZ=n" >> ${LINUX_DIR}/.config
216 echo "CONFIG_RD_BZIP2=n" >> ${LINUX_DIR}/.config
217 echo "CONFIG_RD_GZIP=n" >> ${LINUX_DIR}/.config
218 echo "CONFIG_RD_LZO=n" >> ${LINUX_DIR}/.config
219 echo "CONFIG_RD_LZ4=y" >> ${LINUX_DIR}/.config
220 echo "CONFIG_RD_LZMA=n" >> ${LINUX_DIR}/.config
221 echo "CONFIG_INITRAMFS_COMPRESSION_LZ4=y" >> ${LINUX_DIR}/.config
222 endif
223 ifeq ($(ADK_KERNEL_COMP_LZMA),y)
224 echo "CONFIG_RD_XZ=n" >> ${LINUX_DIR}/.config
225 echo "CONFIG_RD_BZIP2=n" >> ${LINUX_DIR}/.config
226 echo "CONFIG_RD_GZIP=n" >> ${LINUX_DIR}/.config
227 echo "CONFIG_RD_LZO=n" >> ${LINUX_DIR}/.config
228 echo "CONFIG_RD_LZ4=n" >> ${LINUX_DIR}/.config
229 echo "CONFIG_RD_LZMA=y" >> ${LINUX_DIR}/.config
230 echo "CONFIG_INITRAMFS_COMPRESSION_LZMA=y" >> ${LINUX_DIR}/.config
231 endif
232 ifeq ($(ADK_KERNEL_COMP_LZO),y)
233 echo "CONFIG_RD_XZ=n" >> ${LINUX_DIR}/.config
234 echo "CONFIG_RD_BZIP2=n" >> ${LINUX_DIR}/.config
235 echo "CONFIG_RD_GZIP=n" >> ${LINUX_DIR}/.config
236 echo "CONFIG_RD_LZMA=n" >> ${LINUX_DIR}/.config
237 echo "CONFIG_RD_LZ4=n" >> ${LINUX_DIR}/.config
238 echo "CONFIG_RD_LZO=y" >> ${LINUX_DIR}/.config
239 echo "CONFIG_INITRAMFS_COMPRESSION_LZO=y" >> ${LINUX_DIR}/.config
240 endif
241 ifeq ($(ADK_KERNEL_COMP_GZIP),y)
242 echo "CONFIG_RD_XZ=n" >> ${LINUX_DIR}/.config
243 echo "CONFIG_RD_BZIP2=n" >> ${LINUX_DIR}/.config
244 echo "CONFIG_RD_LZO=n" >> ${LINUX_DIR}/.config
245 echo "CONFIG_RD_LZMA=n" >> ${LINUX_DIR}/.config
246 echo "CONFIG_RD_LZ4=n" >> ${LINUX_DIR}/.config
247 echo "CONFIG_RD_GZIP=y" >> ${LINUX_DIR}/.config
248 echo "CONFIG_INITRAMFS_COMPRESSION_GZIP=y" >> ${LINUX_DIR}/.config
249 endif
250 ifeq ($(ADK_KERNEL_COMP_BZIP2),y)
251 echo "CONFIG_RD_XZ=n" >> ${LINUX_DIR}/.config
252 echo "CONFIG_RD_GZIP=n" >> ${LINUX_DIR}/.config
253 echo "CONFIG_RD_LZMA=n" >> ${LINUX_DIR}/.config
254 echo "CONFIG_RD_LZO=n" >> ${LINUX_DIR}/.config
255 echo "CONFIG_RD_LZ4=n" >> ${LINUX_DIR}/.config
256 echo "CONFIG_RD_BZIP2=y" >> ${LINUX_DIR}/.config
257 echo "CONFIG_INITRAMFS_COMPRESSION_BZIP2=y" >> ${LINUX_DIR}/.config
258 endif
259 ifeq ($(ADK_KERNEL_COMPRESS_NONE),y)
260 echo "CONFIG_RD_XZ=n" >> ${LINUX_DIR}/.config
261 echo "CONFIG_RD_BZIP2=n" >> ${LINUX_DIR}/.config
262 echo "CONFIG_RD_LZO=n" >> ${LINUX_DIR}/.config
263 echo "CONFIG_RD_LZMA=n" >> ${LINUX_DIR}/.config
264 echo "CONFIG_RD_LZ4=n" >> ${LINUX_DIR}/.config
265 echo "CONFIG_RD_GZIP=n" >> ${LINUX_DIR}/.config
266 endif
267 @-rm $(LINUX_DIR)/usr/initramfs_data.cpio* 2>/dev/null
268 env $(KERNEL_MAKE_ENV) $(MAKE) -C "${LINUX_DIR}" $(KERNEL_MAKE_OPTS) \
269 -j${ADK_MAKE_JOBS} $(ADK_TARGET_KERNEL) $(MAKE_TRACE)
270 @cp $(KERNEL) $(FW_DIR)/$(TARGET_KERNEL)
272 ${FW_DIR}/${ROOTFSISO}: ${TARGET_DIR} kernel-package
273 mkdir -p ${TARGET_DIR}/boot/syslinux
274 cp ${STAGING_HOST_DIR}/usr/share/syslinux/{isolinux.bin,ldlinux.c32} \
275 ${TARGET_DIR}/boot/syslinux
276 echo 'DEFAULT /boot/kernel root=/dev/sr0' > \
277 ${TARGET_DIR}/boot/syslinux/isolinux.cfg
278 PATH='${HOST_PATH}' mkisofs -R -uid 0 -gid 0 -o $@ \
279 -b boot/syslinux/isolinux.bin \
280 -c boot/syslinux/boot.cat -no-emul-boot \
281 -boot-load-size 4 -boot-info-table ${TARGET_DIR}
283 ${FW_DIR}/${GENIMAGE}: ${TARGET_DIR} kernel-package
284 @rm -rf ${FW_DIR}/temp
285 @mkdir -p ${FW_DIR}/temp
286 @$(CP) $(KERNEL) $(FW_DIR)/kernel
287 @dd if=/dev/zero of=${FW_DIR}/cfgfs.img bs=16384 count=1 $(MAKE_TRACE)
288 ifeq ($(ADK_RUNTIME_FIX_PERMISSION),y)
289 echo '#!/bin/sh' > $(ADK_TOPDIR)/scripts/fakeroot.sh
290 echo "chown -R 0:0 $(TARGET_DIR)" >> $(ADK_TOPDIR)/scripts/fakeroot.sh
291 echo 'cd $(TARGET_DIR)' >> $(ADK_TOPDIR)/scripts/fakeroot.sh
292 -@cat $(STAGING_TARGET_DIR)/scripts/permissions.sh >> $(ADK_TOPDIR)/scripts/fakeroot.sh 2>/dev/null
293 chmod 755 $(ADK_TOPDIR)/scripts/fakeroot.sh
294 PATH='$(HOST_PATH)' $(FAKEROOT) $(ADK_TOPDIR)/scripts/fakeroot.sh
295 rm $(ADK_TOPDIR)/scripts/fakeroot.sh $(STAGING_TARGET_DIR)/scripts/permissions.sh
296 endif
297 PATH='${HOST_PATH}' $(FAKEROOT) mke2img \
298 -G 4 \
299 -d "$(TARGET_DIR)" \
300 -o $(FW_DIR)/rootfs.ext $(MAKE_TRACE)
301 PATH='${HOST_PATH}' genimage \
302 --config "$(ADK_TOPDIR)/target/$(ADK_TARGET_ARCH)/$(ADK_TARGET_SYSTEM)/genimage.cfg" \
303 --tmppath "${FW_DIR}/temp" \
304 --rootpath "$(TARGET_DIR)" \
305 --inputpath "$(FW_DIR)" \
306 --outputpath "$(FW_DIR)" $(MAKE_TRACE)
307 ifeq ($(ADK_PACKAGE_GRUB_EFI_X86)$(ADK_PACKAGE_GRUB_EFI_X86_64),y)
308 @if [ ! -f $(ADK_TOPDIR)/bios-$(ADK_TARGET_ARCH).bin ]; then \
309 cd $(ADK_TOPDIR); wget http://distfiles.openadk.org/bios-$(ADK_TARGET_ARCH).bin ;\
311 endif
313 imageclean:
314 rm -f $(FW_DIR)/$(ADK_TARGET_SYSTEM)-* ${BUILD_DIR}/$(ADK_TARGET_SYSTEM)-*