OSDN Git Service

Add rules to build an rpm package
authorChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 26 Oct 2016 15:54:21 +0000 (23:54 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Wed, 26 Oct 2016 15:54:21 +0000 (23:54 +0800)
The rpm could be installed to an rpm based linux distribution.
Boot entries for android-x86 will be added. After installation,
reboot the system to android-x86.

To build the rpm, you need to install 'rpm-build' on a Fedora
based system, or 'rpm' on a Debian/Ubuntu based system.
Then do it by 'make rpm'.

Just install the rpm as a normal package on a Fedora based system.
On Debian/Ubuntu, you can use the 'alien' to install it:

$ sudo apt install alien
$ sudo alien -c -i android-x86-6.0-r1.i686.rpm

Android.mk
rpm/rpm.spec [new file with mode: 0644]

index 0236423..8033c6a 100644 (file)
@@ -78,6 +78,14 @@ $(ISO_IMAGE): $(boot_dir) $(BUILT_IMG)
        $(hide) isohybrid --uefi $@ || echo -e "isohybrid not found.\nInstall syslinux 4.0 or higher if you want to build a usb bootable iso."
        @echo -e "\n\n$@ is built successfully.\n\n"
 
+rpm: $(LOCAL_PATH)/rpm/rpm.spec $(BUILT_IMG)
+       @echo ----- Making an rpm ------
+       OUT=$(abspath $(PRODUCT_OUT)); mkdir -p $$OUT/rpm/BUILD; rm -rf mv $$OUT/rpm/RPMS/*; \
+       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"install_prefix $(if $(INSTALL_PREFIX),$(INSTALL_PREFIX),android-$(VER))" $<; \
+       mv $$OUT/rpm/RPMS/*/*.rpm $$OUT
+
 # Note: requires dosfstools
 EFI_IMAGE := $(PRODUCT_OUT)/$(TARGET_PRODUCT).img
 ESP_LAYOUT := $(LOCAL_PATH)/editdisklbl/esp_layout.conf
@@ -95,7 +103,7 @@ $(EFI_IMAGE): $(wildcard $(LOCAL_PATH)/boot/boot/*/*) $(BUILT_IMG) $(ESP_LAYOUT)
        $(hide) cat /dev/null > $@; $(edit_mbr) -l $(ESP_LAYOUT) -i $@ esp=$@.fat
        $(hide) rm -f $@.fat
 
-.PHONY: iso_img usb_img efi_img
+.PHONY: iso_img usb_img efi_img rpm
 iso_img: $(ISO_IMAGE)
 usb_img: $(ISO_IMAGE)
 efi_img: $(EFI_IMAGE)
diff --git a/rpm/rpm.spec b/rpm/rpm.spec
new file mode 100644 (file)
index 0000000..0842ef2
--- /dev/null
@@ -0,0 +1,71 @@
+Summary: %{?title}%{!?title:Android-x86} - Run Android on your PC
+Name: %{?name}%{!?name:android-x86}
+Version: %(echo %{ver} | cut -d- -f1)
+Release: %(echo %{ver} | cut -d- -f2)
+Source1: kernel
+Source2: initrd.img
+Source3: ramdisk.img
+Source4: %{systemimg}
+License: Apache Public License / GPLv2
+Group: Operating system/Android
+URL: http://www.android-x86.org
+
+%description
+Android-x86 is an open source project to port AOSP to x86 platform. Most
+components of the project is licensed under Apache Public License 2.0.
+Some components are licensed under GNU General Public License (GPL) 2.0
+or later.
+
+%prep
+
+%build
+
+%install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}/%{install_prefix}
+install -m644 %{S:1} %{S:2} %{S:3} %{S:4} %{buildroot}/%{install_prefix}
+
+%post
+. /etc/os-release
+mkdir -p /%{install_prefix}/data
+if [ "$ID" = "debian" -o "$ID_LIKE" = "debian" ]; then
+       grubcfg=/boot/grub/custom.cfg
+elif mountpoint -q /boot/efi; then
+       grubcfg=/boot/efi/EFI/$ID/custom.cfg && efi=efi
+else
+       grubcfg=/boot/grub2/custom.cfg
+fi
+echo -e "menuentry \"%{?title}%{!?title:Android-x86} %{ver}\" {\n\tsearch --set=root --file /%{install_prefix}/kernel\n\tlinux$efi /%{install_prefix}/kernel quiet %{cmdline} \n\tinitrd$efi /%{install_prefix}/initrd.img\n}" > $grubcfg
+echo -e "menuentry \"%{?title}%{!?title:Android-x86} %{ver} (DEBUG mode)\" {\n\tsearch --set=root --file /%{install_prefix}/kernel\n\tlinux$efi /%{install_prefix}/kernel %{cmdline} DEBUG=2\n\tinitrd$efi /%{install_prefix}/initrd.img\n}" >> $grubcfg
+
+if [ "$ID" = "debian" -o "$ID_LIKE" = "debian" ]; then
+       sed -i 's/^GRUB_HIDDEN_/#GRUB_HIDDEN_/' /etc/default/grub
+       update-grub
+fi
+
+%postun
+. /etc/os-release
+if [ "$ID" = "debian" -o "$ID_LIKE" = "debian" ]; then
+       grubcfg=/boot/grub/custom.cfg
+elif mountpoint -q /boot/efi; then
+       grubcfg=/boot/efi/EFI/$ID/custom.cfg
+else
+       grubcfg=/boot/grub2/custom.cfg
+fi
+if [ "$1" = "1" ]; then
+       new_prefix=`dirname $(grep initrd $grubcfg | head -1 | awk '{print $2}')`
+       if [ "$new_prefix" != "/%{install_prefix}" ]; then
+               rmdir $new_prefix/data
+               mv /%{install_prefix}/data $new_prefix
+               rmdir /%{install_prefix}
+       fi
+else
+       rmdir /%{install_prefix}/data /%{install_prefix}
+       rm -f $grubcfg
+fi
+
+%clean
+rm -rf %{buildroot}
+
+%files
+/%{install_prefix}/*