OSDN Git Service

8050c219c2d307a9f2d1d518948e741e6eda421d
[android-x86/bootable-newinstaller.git] / Android.mk
1 # Copyright 2009-2010, The Android-x86 Open Source Project
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 ifeq ($(TARGET_ARCH),x86)
16 LOCAL_PATH := $(call my-dir)
17 include $(CLEAR_VARS)
18
19 LOCAL_MODULE := edit_mbr
20 LOCAL_SRC_FILES := editdisklbl/editdisklbl.c
21 LOCAL_CFLAGS := -O2 -g -W -Wall -Werror# -D_LARGEFILE64_SOURCE
22 LOCAL_STATIC_LIBRARIES := libdiskconfig_host libcutils liblog
23 edit_mbr := $(HOST_OUT_EXECUTABLES)/$(LOCAL_MODULE)
24 include $(BUILD_HOST_EXECUTABLE)
25
26 VER ?= $(shell date +"%F")
27
28 # use squashfs for iso, unless explictly disabled
29 ifneq ($(USE_SQUASHFS),0)
30 MKSQUASHFS = $(shell which mksquashfs)
31
32 define build-squashfs-target
33         $(if $(shell $(MKSQUASHFS) -version | grep "version [0-3].[0-9]"),\
34                 $(error Your mksquashfs is too old to work with kernel 2.6.29. Please upgrade to squashfs-tools 4.0))
35         $(hide) $(MKSQUASHFS) $(1) $(2) -noappend
36 endef
37 endif
38
39 initrd_dir := $(LOCAL_PATH)/initrd
40 initrd_bin := \
41         $(initrd_dir)/init \
42         $(wildcard $(initrd_dir)/*/*)
43
44 systemimg  := $(PRODUCT_OUT)/system.$(if $(MKSQUASHFS),sfs,img)
45
46 INITRD_RAMDISK := $(PRODUCT_OUT)/initrd.img
47 $(INITRD_RAMDISK): $(initrd_bin) $(systemimg) $(TARGET_INITRD_SCRIPTS) | $(ACP) $(MKBOOTFS)
48         rm -rf $(TARGET_INSTALLER_OUT)
49         $(ACP) -pr $(initrd_dir) $(TARGET_INSTALLER_OUT)
50         $(if $(TARGET_INITRD_SCRIPTS),$(ACP) -p $(TARGET_INITRD_SCRIPTS) $(TARGET_INSTALLER_OUT)/scripts)
51         ln -s /bin/ld-linux.so.2 $(TARGET_INSTALLER_OUT)/lib
52         mkdir -p $(addprefix $(TARGET_INSTALLER_OUT)/,android iso mnt proc sys tmp sfs hd)
53         echo "VER=$(VER)" > $(TARGET_INSTALLER_OUT)/scripts/00-ver
54         $(MKBOOTFS) $(TARGET_INSTALLER_OUT) | gzip -9 > $@
55
56 INSTALL_RAMDISK := $(PRODUCT_OUT)/install.img
57 $(INSTALL_RAMDISK): $(wildcard $(LOCAL_PATH)/install/*/* $(LOCAL_PATH)/install/*/*/*/*) | $(MKBOOTFS)
58         $(if $(TARGET_INSTALL_SCRIPTS),$(ACP) -p $(TARGET_INSTALL_SCRIPTS) $(TARGET_INSTALLER_OUT)/scripts)
59         $(MKBOOTFS) $(dir $(dir $(<D))) | gzip -9 > $@
60
61 boot_dir := $(PRODUCT_OUT)/boot
62 $(boot_dir): $(shell find $(LOCAL_PATH)/boot -type f | sort -r) $(systemimg) $(GENERIC_X86_CONFIG_MK) | $(ACP)
63         $(hide) rm -rf $@
64         $(ACP) -pr $(dir $(<D)) $@
65
66 BUILT_IMG := $(addprefix $(PRODUCT_OUT)/,ramdisk.img initrd.img install.img) $(systemimg)
67 BUILT_IMG += $(if $(TARGET_PREBUILT_KERNEL),$(TARGET_PREBUILT_KERNEL),$(PRODUCT_OUT)/kernel)
68
69 ISO_IMAGE := $(PRODUCT_OUT)/$(TARGET_PRODUCT).iso
70 $(ISO_IMAGE): $(boot_dir) $(BUILT_IMG)
71         @echo ----- Making iso image ------
72         $(hide) sed -i "s|\(Installation CD\)\(.*\)|\1 $(VER)|; s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $</isolinux/isolinux.cfg
73         $(hide) sed -i "s|VER|$(VER)|; s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $</boot/grub/grub.cfg
74         $(hide) cp -r $(<D)/../../../../bootable/newinstaller/install/grub2/efi $</efi
75         genisoimage -vJURT -b isolinux/isolinux.bin -c isolinux/boot.cat \
76                 -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot \
77                 -input-charset utf-8 -V "Android-x86 LiveCD" -o $@ $^
78         $(hide) isohybrid --uefi $@ || echo -e "isohybrid not found.\nInstall syslinux 4.0 or higher if you want to build a usb bootable iso."
79         @echo -e "\n\n$@ is built successfully.\n\n"
80
81 # Note: requires dosfstools
82 EFI_IMAGE := $(PRODUCT_OUT)/$(TARGET_PRODUCT).img
83 ESP_LAYOUT := $(LOCAL_PATH)/editdisklbl/esp_layout.conf
84 $(EFI_IMAGE): $(wildcard $(LOCAL_PATH)/boot/boot/*/*) $(BUILT_IMG) $(ESP_LAYOUT) | $(edit_mbr)
85         $(hide) sed "s|VER|$(VER)|; s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $(<D)/grub.cfg > $(@D)/grub.cfg
86         $(hide) size=0; \
87         for s in `du -sk $^ | awk '{print $$1}'`; do \
88                 size=$$(($$size+$$s)); \
89         done; \
90         size=$$(($$(($$(($$(($$(($$size + $$(($$size / 100)))) - 1)) / 32)) + 1)) * 32)); \
91         rm -f $@.fat; mkdosfs -n Android-x86 -C $@.fat $$size
92         $(hide) mcopy -Qsi $@.fat $(<D)/../../../install/grub2/efi $(BUILT_IMG) ::
93         $(hide) mmd -i $@.fat ::boot; mmd -i $@.fat ::boot/grub
94         $(hide) mcopy -Qoi $@.fat $(@D)/grub.cfg ::boot/grub
95         $(hide) cat /dev/null > $@; $(edit_mbr) -l $(ESP_LAYOUT) -i $@ esp=$@.fat
96         $(hide) rm -f $@.fat
97
98 .PHONY: iso_img usb_img efi_img
99 iso_img: $(ISO_IMAGE)
100 usb_img: $(ISO_IMAGE)
101 efi_img: $(EFI_IMAGE)
102
103 endif