OSDN Git Service

Merge remote-tracking branch 'x86/nougat-x86' into oreo-x86
[android-x86/bootable-newinstaller.git] / Android.mk
index a8d6ffb..bf4d728 100644 (file)
@@ -1,20 +1,37 @@
-ifeq ($(TARGET_ARCH),x86)
+# Copyright 2009-2014, The Android-x86 Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+ifneq ($(filter x86%,$(TARGET_ARCH)),)
 LOCAL_PATH := $(call my-dir)
-include $(CLEAR_VARS)
 
-VER ?= $(shell date +"%F")
+include $(CLEAR_VARS)
+LOCAL_IS_HOST_MODULE := true
+LOCAL_SRC_FILES := rpm/qemu-android
+LOCAL_MODULE := $(notdir $(LOCAL_SRC_FILES))
+LOCAL_MODULE_TAGS := debug
+LOCAL_MODULE_CLASS := EXECUTABLES
+LOCAL_POST_INSTALL_CMD := $(hide) sed -i "s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $(HOST_OUT_EXECUTABLES)/$(LOCAL_MODULE)
+include $(BUILD_PREBUILT)
 
-LOCAL_MODULE := newinstaller
-LOCAL_MODULE_TAGS := system_builder
+VER ?= $$(date +"%F")
 
 # use squashfs for iso, unless explictly disabled
 ifneq ($(USE_SQUASHFS),0)
-MKSQUASHFS = $(shell which mksquashfs)
+MKSQUASHFS := $(MAKE_SQUASHFS)
 
 define build-squashfs-target
-       $(if $(shell $(MKSQUASHFS) -version | grep "version [0-3].[0-9]"),\
-               $(error Your mksquashfs is too old to work with kernel 2.6.29. Please upgrade to squashfs-tools 4.0))
-       $(hide) $(MKSQUASHFS) $(1) $(2) -noappend
+       $(hide) $(MKSQUASHFS) $(1) $(2) -noappend -comp gzip
 endef
 endif
 
@@ -23,65 +40,74 @@ initrd_bin := \
        $(initrd_dir)/init \
        $(wildcard $(initrd_dir)/*/*)
 
-INITRD_RAMDISK := $(PRODUCT_OUT)/initrd.img
-$(INITRD_RAMDISK): $(initrd_bin) $(TARGET_INITRD_SCRIPTS) | $(ACP) $(MKBOOTFS)
-       rm -rf $(TARGET_INSTALLER_OUT)
-       $(ACP) -pr $(initrd_dir) $(TARGET_INSTALLER_OUT)
-       $(if $(TARGET_INITRD_SCRIPTS),$(ACP) -p $(TARGET_INITRD_SCRIPTS) $(TARGET_INSTALLER_OUT)/scripts)
-       ln -s /bin/ld-linux.so.2 $(TARGET_INSTALLER_OUT)/lib
-       mkdir -p $(addprefix $(TARGET_INSTALLER_OUT)/,android mnt proc sys tmp sfs hd)
-       echo "VER=$(VER)" > $(TARGET_INSTALLER_OUT)/scripts/00-ver
-       $(MKBOOTFS) $(TARGET_INSTALLER_OUT) | gzip -9 > $@
+systemimg  := $(PRODUCT_OUT)/system.$(if $(MKSQUASHFS),sfs,img)
+
+TARGET_INITRD_OUT := $(PRODUCT_OUT)/initrd
+INITRD_RAMDISK := $(TARGET_INITRD_OUT).img
+$(INITRD_RAMDISK): $(initrd_bin) $(systemimg) $(TARGET_INITRD_SCRIPTS) | $(ACP) $(MKBOOTFS)
+       $(hide) rm -rf $(TARGET_INITRD_OUT)
+       mkdir -p $(addprefix $(TARGET_INITRD_OUT)/,android hd iso lib mnt proc scripts sfs sys tmp)
+       $(if $(TARGET_INITRD_SCRIPTS),$(ACP) -p $(TARGET_INITRD_SCRIPTS) $(TARGET_INITRD_OUT)/scripts)
+       ln -s /bin/ld-linux.so.2 $(TARGET_INITRD_OUT)/lib
+       echo "VER=$(VER)" > $(TARGET_INITRD_OUT)/scripts/00-ver
+       $(if $(RELEASE_OS_TITLE),echo "OS_TITLE=$(RELEASE_OS_TITLE)" >> $(TARGET_INITRD_OUT)/scripts/00-ver)
+       $(if $(INSTALL_PREFIX),echo "INSTALL_PREFIX=$(INSTALL_PREFIX)" >> $(TARGET_INITRD_OUT)/scripts/00-ver)
+       $(MKBOOTFS) $(<D) $(TARGET_INITRD_OUT) | gzip -9 > $@
 
 INSTALL_RAMDISK := $(PRODUCT_OUT)/install.img
-$(INSTALL_RAMDISK): $(wildcard $(LOCAL_PATH)/install/*/*) | $(MKBOOTFS)
-       $(MKBOOTFS) $(dir $(dir $(<D))) | gzip -9 > $@
+INSTALLER_BIN := $(TARGET_INSTALLER_OUT)/sbin/efibootmgr
+$(INSTALL_RAMDISK): $(wildcard $(LOCAL_PATH)/install/*/* $(LOCAL_PATH)/install/*/*/*/*) $(INSTALLER_BIN) | $(MKBOOTFS)
+       $(if $(TARGET_INSTALL_SCRIPTS),mkdir -p $(TARGET_INSTALLER_OUT)/scripts; $(ACP) -p $(TARGET_INSTALL_SCRIPTS) $(TARGET_INSTALLER_OUT)/scripts)
+       $(MKBOOTFS) $(dir $(dir $(<D))) $(TARGET_INSTALLER_OUT) | gzip -9 > $@
+
+isolinux_files := $(addprefix external/syslinux/bios/com32/, \
+       ../core/isolinux.bin \
+       chain/chain.c32 \
+       elflink/ldlinux/ldlinux.c32 \
+       lib/libcom32.c32 \
+       libutil/libutil.c32 \
+       menu/vesamenu.c32)
 
 boot_dir := $(PRODUCT_OUT)/boot
-$(boot_dir): $(wildcard $(LOCAL_PATH)/boot/isolinux/*) | $(ACP)
-       rm -rf $@
+$(boot_dir): $(shell find $(LOCAL_PATH)/boot -type f | sort -r) $(isolinux_files) $(systemimg) $(INSTALL_RAMDISK) $(GENERIC_X86_CONFIG_MK) | $(ACP)
+       $(hide) rm -rf $@
        $(ACP) -pr $(dir $(<D)) $@
+       $(ACP) -pr $(dir $(<D))../install/grub2/efi $@
+       $(ACP) $(isolinux_files) $@/isolinux
+       img=$@/boot/grub/efi.img; dd if=/dev/zero of=$$img bs=1M count=4; \
+       mkdosfs -n EFI $$img; mmd -i $$img ::boot; \
+       mcopy -si $$img $@/efi ::; mdel -i $$img ::efi/boot/*.cfg
 
-BUILT_IMG := $(addprefix $(PRODUCT_OUT)/,system.$(if $(MKSQUASHFS),sfs,img) ramdisk.img initrd.img install.img)
+BUILT_IMG := $(addprefix $(PRODUCT_OUT)/,ramdisk.img initrd.img install.img) $(systemimg)
 BUILT_IMG += $(if $(TARGET_PREBUILT_KERNEL),$(TARGET_PREBUILT_KERNEL),$(PRODUCT_OUT)/kernel)
 
+GENISOIMG := $(if $(shell which xorriso 2> /dev/null),xorriso -as mkisofs,genisoimage)
 ISO_IMAGE := $(PRODUCT_OUT)/$(TARGET_PRODUCT).iso
+ISOHYBRID := LD_LIBRARY_PATH=$(LOCAL_PATH)/install/lib external/syslinux/bios/utils/isohybrid
 $(ISO_IMAGE): $(boot_dir) $(BUILT_IMG)
        @echo ----- Making iso image ------
        $(hide) sed -i "s|\(Installation CD\)\(.*\)|\1 $(VER)|; s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $</isolinux/isolinux.cfg
-       genisoimage -vJURT -b isolinux/isolinux.bin -c isolinux/boot.cat \
-               -no-emul-boot -boot-load-size 4 -boot-info-table \
-               -input-charset utf-8 -V "Android LiveCD" -o $@ $^
-
-ANDROID_SRC := /android-system
-USB_BOOT := $(PRODUCT_OUT)/usb_boot
-
-usb_tmp_img := $(PRODUCT_OUT)/usb_tmp.img
-$(usb_tmp_img): $(wildcard $(LOCAL_PATH)/usb/*) $(BUILT_IMG) | $(ACP) $(MKEXT2IMG)
-       rm -rf $(USB_BOOT)
-       mkdir -p $(USB_BOOT)$(ANDROID_SRC)
-       touch $(USB_BOOT)/ramdisk
-       echo 1 > $(USB_BOOT)/cmdline
-       ln $(BUILT_IMG) $(USB_BOOT)$(ANDROID_SRC)
-       $(ACP) -fp $(<D)/* $(<D)/../install/grub/android-x86.xpm.gz $(USB_BOOT)
-       ln -s grub4dos $(USB_BOOT)/kernel
-       $(hide) sed -i "s|VER|$(VER)|; s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $(USB_BOOT)/menu.lst
-       num_blocks=`du -sk $(USB_BOOT) | tail -n1 | awk '{print $$1;}'`; \
-       num_inodes=`find $(USB_BOOT) | wc -l`; \
-       $(MKEXT2IMG) -d $(USB_BOOT) -b `expr $$num_blocks + 20480` -N `expr $$num_inodes + 15` -m 0 $@
-
-edit_mbr := $(HOST_OUT_EXECUTABLES)/editdisklbl
-USB_LAYOUT := $(LOCAL_PATH)/usb_layout.conf
-USB_IMAGE := $(PRODUCT_OUT)/$(TARGET_PRODUCT)_usb.img
-$(USB_IMAGE): $(usb_tmp_img) $(USB_LAYOUT) $(PRODUCT_OUT)/grub/grub.bin | $(edit_mbr)
-       @echo ----- Making usb image ------
-       @sed 's|default 2|default 0|' $(PRODUCT_OUT)/grub/grub.bin > $@
-       @$(edit_mbr) -l $(USB_LAYOUT) -i $@ usb_boot=$(usb_tmp_img)
-
-.PHONY: iso_img usb_img
+       $(hide) sed -i "s|VER|$(VER)|; s|CMDLINE|$(BOARD_KERNEL_CMDLINE)|" $</efi/boot/android.cfg
+       sed -i "s|OS_TITLE|$(if $(RELEASE_OS_TITLE),$(RELEASE_OS_TITLE),Android-x86)|" $</isolinux/isolinux.cfg $</efi/boot/android.cfg
+       $(GENISOIMG) -vJURT -b isolinux/isolinux.bin -c isolinux/boot.cat \
+               -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot \
+               -input-charset utf-8 -V "$(if $(RELEASE_OS_TITLE),$(RELEASE_OS_TITLE),Android-x86) $(VER) ($(TARGET_ARCH))" -o $@ $^
+       $(hide) $(ISOHYBRID) --uefi $@
+       @echo -e "\n\n$@ is built successfully.\n\n"
+
+rpm: $(wildcard $(LOCAL_PATH)/rpm/*) $(BUILT_IMG)
+       @echo ----- Making an rpm ------
+       OUT=$(abspath $(PRODUCT_OUT)); mkdir -p $$OUT/rpm/BUILD; rm -rf $$OUT/rpm/RPMS/*; $(ACP) $< $$OUT; \
+       echo $(VER) | grep -vq rc; EPOCH=$$((-$$? + `echo $(VER) | cut -d. -f1`)); \
+       rpmbuild -bb --target=$(if $(filter x86,$(TARGET_ARCH)),i686,x86_64) -D"cmdline $(BOARD_KERNEL_CMDLINE)" \
+               -D"_topdir $$OUT/rpm" -D"_sourcedir $$OUT" -D"systemimg $(notdir $(systemimg))" -D"ver $(VER)" -D"epoch $$EPOCH" \
+               $(if $(BUILD_NAME_VARIANT),-D"name $(BUILD_NAME_VARIANT)") \
+               -D"install_prefix $(if $(INSTALL_PREFIX),$(INSTALL_PREFIX),android-$(VER))" $(filter %.spec,$^); \
+       mv $$OUT/rpm/RPMS/*/*.rpm $$OUT
+
+.PHONY: iso_img usb_img efi_img rpm
 iso_img: $(ISO_IMAGE)
-usb_img: $(USB_IMAGE)
-
-include $(call first-makefiles-under,$(LOCAL_PATH))
+usb_img: $(ISO_IMAGE)
+efi_img: $(ISO_IMAGE)
 
 endif