call Exit() when quitting
[platform/upstream/gummiboot.git] / Makefile
1 VERSION=3
2
3 ARCH=$(shell $(CC) -dumpmachine | sed "s/\(-\).*$$//")
4 LIBDIR=$(shell echo $$(cd /usr/lib/$$(gcc -print-multi-os-directory); pwd))
5
6 CPPFLAGS = \
7         -I. \
8         -I/usr/include/efi \
9         -I/usr/include/efi/$(ARCH)
10
11 CFLAGS = \
12         -DVERSION=$(VERSION) \
13         -Wall \
14         -ggdb -O0 \
15         -fpic \
16         -fshort-wchar \
17         -nostdinc \
18         -ffreestanding \
19         -fno-stack-protector
20 # -mno-red-zone
21
22 ifeq ($(ARCH),x86_64)
23 CFLAGS += \
24         -DEFI_FUNCTION_WRAPPER
25 endif
26
27 LDFLAGS = -T $(LIBDIR)/gnuefi/elf_$(ARCH)_efi.lds \
28         -shared \
29         -Bsymbolic \
30         -nostdlib \
31         -znocombreloc \
32         -L $(LIBDIR) \
33         $(LIBDIR)/gnuefi/crt0-efi-$(ARCH).o \
34         $(shell $(CC) -print-libgcc-file-name)
35
36 %.o: %.c
37         $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
38
39 gummiboot.efi: gummiboot.so
40         objcopy -j .text -j .sdata -j .data -j .dynamic \
41           -j .dynsym -j .rel -j .rela -j .reloc -j .eh_frame \
42           --target=efi-app-$(ARCH) $< $@
43
44 gummiboot.so: gummiboot.o
45         $(LD) $(LDFLAGS) gummiboot.o -o $@ -lefi -lgnuefi
46
47 gummiboot.o: gummiboot.c Makefile
48
49 clean:
50         rm -f gummiboot.o gummiboot.so gummiboot.efi
51
52 test: gummiboot.efi
53         @# UUID=677B-ECF2 /boot2 vfat noauto,x-systemd.automount,x-gvfs-hide 1 3
54         cp -v gummiboot.efi /boot/EFI/gummiboot/
55         @# unmount to sync EFI partition to disk
56         sync
57         umount /boot
58         echo 3 > /proc/sys/vm/drop_caches
59         @# run QEMU with UEFI firmware
60         qemu-kvm -m 512 -L /usr/lib/qemu-bios -snapshot /dev/sda