OSDN Git Service

Merge remote-tracking branch 'x86/nougat-x86' into oreo-x86
[android-x86/bootable-newinstaller.git] / Android.mk
1 # Copyright 2009-2014, 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 ifneq ($(filter x86%,$(TARGET_ARCH)),)
16 LOCAL_PATH := $(call my-dir)
17 include $(CLEAR_VARS)
18
19 include $(CLEAR_VARS)
20 LOCAL_IS_HOST_MODULE := true
21 LOCAL_SRC_FILES := rpm/qemu-android
22 LOCAL_MODULE := $(notdir $(LOCAL_SRC_FILES))
23 LOCAL_MODULE_TAGS := debug
24 LOCAL_MODULE_CLASS := EXECUTABLES
25 LOCAL_POST_INSTALL_CMD := $(hide) sed -i "s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $(HOST_OUT_EXECUTABLES)/$(LOCAL_MODULE)
26 include $(BUILD_PREBUILT)
27
28 VER ?= $$(date +"%F")
29
30 # use squashfs for iso, unless explictly disabled
31 ifneq ($(USE_SQUASHFS),0)
32 MKSQUASHFS := $(MAKE_SQUASHFS)
33
34 define build-squashfs-target
35         $(hide) $(MKSQUASHFS) $(1) $(2) -noappend -comp gzip
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 TARGET_INITRD_OUT := $(PRODUCT_OUT)/initrd
47 INITRD_RAMDISK := $(TARGET_INITRD_OUT).img
48 $(INITRD_RAMDISK): $(initrd_bin) $(systemimg) $(TARGET_INITRD_SCRIPTS) | $(ACP) $(MKBOOTFS)
49         $(hide) rm -rf $(TARGET_INITRD_OUT)
50         mkdir -p $(addprefix $(TARGET_INITRD_OUT)/,android hd iso lib mnt proc scripts sfs sys tmp)
51         $(if $(TARGET_INITRD_SCRIPTS),$(ACP) -p $(TARGET_INITRD_SCRIPTS) $(TARGET_INITRD_OUT)/scripts)
52         ln -s /bin/ld-linux.so.2 $(TARGET_INITRD_OUT)/lib
53         echo "VER=$(VER)" > $(TARGET_INITRD_OUT)/scripts/00-ver
54         $(if $(RELEASE_OS_TITLE),echo "OS_TITLE=$(RELEASE_OS_TITLE)" >> $(TARGET_INITRD_OUT)/scripts/00-ver)
55         $(if $(INSTALL_PREFIX),echo "INSTALL_PREFIX=$(INSTALL_PREFIX)" >> $(TARGET_INITRD_OUT)/scripts/00-ver)
56         $(MKBOOTFS) $(<D) $(TARGET_INITRD_OUT) | gzip -9 > $@
57
58 INSTALL_RAMDISK := $(PRODUCT_OUT)/install.img
59 INSTALLER_BIN := $(TARGET_INSTALLER_OUT)/sbin/efibootmgr
60 $(INSTALL_RAMDISK): $(wildcard $(LOCAL_PATH)/install/*/* $(LOCAL_PATH)/install/*/*/*/*) $(INSTALLER_BIN) | $(MKBOOTFS)
61         $(if $(TARGET_INSTALL_SCRIPTS),mkdir -p $(TARGET_INSTALLER_OUT)/scripts; $(ACP) -p $(TARGET_INSTALL_SCRIPTS) $(TARGET_INSTALLER_OUT)/scripts)
62         $(MKBOOTFS) $(dir $(dir $(<D))) $(TARGET_INSTALLER_OUT) | gzip -9 > $@
63
64 isolinux_files := $(addprefix external/syslinux/bios/com32/, \
65         ../core/isolinux.bin \
66         chain/chain.c32 \
67         elflink/ldlinux/ldlinux.c32 \
68         lib/libcom32.c32 \
69         libutil/libutil.c32 \
70         menu/vesamenu.c32)
71
72 boot_dir := $(PRODUCT_OUT)/boot
73 $(boot_dir): $(shell find $(LOCAL_PATH)/boot -type f | sort -r) $(isolinux_files) $(systemimg) $(INSTALL_RAMDISK) $(GENERIC_X86_CONFIG_MK) | $(ACP)
74         $(hide) rm -rf $@
75         $(ACP) -pr $(dir $(<D)) $@
76         $(ACP) -pr $(dir $(<D))../install/grub2/efi $@
77         $(ACP) $(isolinux_files) $@/isolinux
78         img=$@/boot/grub/efi.img; dd if=/dev/zero of=$$img bs=1M count=4; \
79         mkdosfs -n EFI $$img; mmd -i $$img ::boot; \
80         mcopy -si $$img $@/efi ::; mdel -i $$img ::efi/boot/*.cfg
81
82 BUILT_IMG := $(addprefix $(PRODUCT_OUT)/,ramdisk.img initrd.img install.img) $(systemimg)
83 BUILT_IMG += $(if $(TARGET_PREBUILT_KERNEL),$(TARGET_PREBUILT_KERNEL),$(PRODUCT_OUT)/kernel)
84
85 GENISOIMG := $(if $(shell which xorriso 2> /dev/null),xorriso -as mkisofs,genisoimage)
86 ISO_IMAGE := $(PRODUCT_OUT)/$(TARGET_PRODUCT).iso
87 $(ISO_IMAGE): $(boot_dir) $(BUILT_IMG)
88         @echo ----- Making iso image ------
89         $(hide) sed -i "s|\(Installation CD\)\(.*\)|\1 $(VER)|; s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $</isolinux/isolinux.cfg
90         $(hide) sed -i "s|VER|$(VER)|; s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $</efi/boot/android.cfg
91         sed -i "s|OS_TITLE|$(if $(RELEASE_OS_TITLE),$(RELEASE_OS_TITLE),Android-x86)|" $</isolinux/isolinux.cfg $</efi/boot/android.cfg
92         $(GENISOIMG) -vJURT -b isolinux/isolinux.bin -c isolinux/boot.cat \
93                 -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot \
94                 -input-charset utf-8 -V "$(if $(RELEASE_OS_TITLE),$(RELEASE_OS_TITLE),Android-x86) LiveCD" -o $@ $^
95         $(hide) isohybrid --uefi $@ || echo -e "isohybrid not found.\nInstall syslinux 4.0 or higher if you want to build a usb bootable iso."
96         @echo -e "\n\n$@ is built successfully.\n\n"
97
98 rpm: $(wildcard $(LOCAL_PATH)/rpm/*) $(BUILT_IMG)
99         @echo ----- Making an rpm ------
100         OUT=$(abspath $(PRODUCT_OUT)); mkdir -p $$OUT/rpm/BUILD; rm -rf $$OUT/rpm/RPMS/*; $(ACP) $< $$OUT; \
101         echo $(VER) | grep -vq rc; EPOCH=$$((-$$? + `echo $(VER) | cut -d. -f1`)); \
102         rpmbuild -bb --target=$(if $(filter x86,$(TARGET_ARCH)),i686,x86_64) -D"cmdline $(BOARD_KERNEL_CMDLINE)" \
103                 -D"_topdir $$OUT/rpm" -D"_sourcedir $$OUT" -D"systemimg $(notdir $(systemimg))" -D"ver $(VER)" -D"epoch $$EPOCH" \
104                 $(if $(BUILD_NAME_VARIANT),-D"name $(BUILD_NAME_VARIANT)") \
105                 -D"install_prefix $(if $(INSTALL_PREFIX),$(INSTALL_PREFIX),android-$(VER))" $(filter %.spec,$^); \
106         mv $$OUT/rpm/RPMS/*/*.rpm $$OUT
107
108 .PHONY: iso_img usb_img efi_img rpm
109 iso_img: $(ISO_IMAGE)
110 usb_img: $(ISO_IMAGE)
111 efi_img: $(ISO_IMAGE)
112
113 endif