30ec9a3ccab49368b2691d756b31cfc3adbe062e
[platform/upstream/gummiboot.git] / Makefile
1 VERSION=24
2
3 ifeq ($(strip $(V)),)
4         E = @echo
5         Q = @
6 else
7         E = @\#
8         Q =
9 endif
10 export E Q
11
12 ARCH=$(shell $(CC) -dumpmachine | sed "s/\(-\).*$$//")
13 LIBDIR=$(shell echo $$(cd /usr/lib/$$(gcc -print-multi-os-directory); pwd))
14 LIBEFIDIR=$(or $(wildcard $(LIBDIR)/gnuefi), $(LIBDIR))
15
16 ifeq ($(ARCH),i686)
17         ARCH=ia32
18         MACHINE_TYPE_NAME=ia32
19 endif
20
21 ifeq ($(ARCH),x86_64)
22         MACHINE_TYPE_NAME=x64
23         ARCH_CFLAGS= \
24                 -DEFI_FUNCTION_WRAPPER \
25                 -mno-red-zone
26 endif
27
28 all: gummiboot$(MACHINE_TYPE_NAME).efi gummiboot
29
30 # ------------------------------------------------------------------------------
31 CPPFLAGS = \
32         -I. \
33         -I/usr/include/efi \
34         -I/usr/include/efi/$(ARCH)
35
36 CFLAGS = \
37         -DVERSION=$(VERSION) \
38         -Wall \
39         -Wextra \
40         -nostdinc \
41         -ggdb -O0 \
42         -fpic \
43         -fshort-wchar \
44         -nostdinc \
45         -ffreestanding \
46         -fno-strict-aliasing \
47         -fno-stack-protector \
48         -Wsign-compare \
49         $(ARCH_CFLAGS)
50
51 LDFLAGS = -T $(LIBEFIDIR)/elf_$(ARCH)_efi.lds \
52         -shared \
53         -Bsymbolic \
54         -nostdlib \
55         -znocombreloc \
56         -L $(LIBDIR) \
57         $(LIBEFIDIR)/crt0-efi-$(ARCH).o
58
59 %.o: %.c
60         $(E) "  CC       " $@
61         $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
62
63 src/efi/gummiboot.o: src/efi/gummiboot.c Makefile
64
65 src/efi/gummiboot.so: src/efi/gummiboot.o
66         $(E) "  LD       " $@
67         $(Q) $(LD) $(LDFLAGS) src/efi/gummiboot.o -o $@ -lefi -lgnuefi \
68           $(shell $(CC) -print-libgcc-file-name)
69         $(Q) nm -D -u $@ | grep ' U ' && exit 1 || :
70
71 gummiboot$(MACHINE_TYPE_NAME).efi: src/efi/gummiboot.so
72         $(E) "  OBJCOPY  " $@
73         $(Q) objcopy -j .text -j .sdata -j .data -j .dynamic \
74           -j .dynsym -j .rel -j .rela -j .reloc -j .eh_frame \
75           --target=efi-app-$(ARCH) $< $@
76
77 # ------------------------------------------------------------------------------
78 gummiboot: src/setup/setup.c src/setup/efivars.h src/setup/efivars.c Makefile
79         $(E) "  CCLD     " $@
80         $(Q) $(CC) -O0 -g -Wall -Wextra \
81           -Wno-unused-parameter -D_GNU_SOURCE \
82           -DMACHINE_TYPE_NAME=\"$(MACHINE_TYPE_NAME)\" \
83           src/setup/setup.c \
84           src/setup/efivars.c \
85           `pkg-config --cflags --libs blkid` \
86           -o $@
87
88 # ------------------------------------------------------------------------------
89 man: gummiboot.1
90
91 gummiboot.1: src/setup/gummiboot.xml
92         $(E) "  XSLT     " $@
93         $(Q) xsltproc -o @ --nonet \
94           --stringparam man.output.quietly 1 \
95           --stringparam man.th.extra1.suppress 1 \
96           --stringparam man.authors.section.enabled 0 \
97           --stringparam man.copyright.section.enabled 0 \
98           http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
99
100 # ------------------------------------------------------------------------------
101 clean:
102         rm -f src/efi/gummiboot.o src/efi/gummiboot.so gummiboot gummiboot$(MACHINE_TYPE_NAME).efi
103
104 install: all
105         mkdir -p $(DESTDIR)/usr/bin/
106         cp gummiboot $(DESTDIR)/usr/bin
107         mkdir -p $(DESTDIR)/usr/lib/gummiboot/
108         cp gummiboot$(MACHINE_TYPE_NAME).efi $(DESTDIR)/usr/lib/gummiboot/
109         [ -e gummiboot.1 ] && mkdir -p $(DESTDIR)/usr/share/man/man1/ && cp gummiboot.1 $(DESTDIR)/usr/share/man/man1/ || :
110
111 tar:
112         git archive --format=tar --prefix=gummiboot-$(VERSION)/ $(VERSION) | xz > gummiboot-$(VERSION).tar.xz
113
114 test-disk: gummiboot$(MACHINE_TYPE_NAME).efi test/test-create-disk.sh
115         test/test-create-disk.sh
116
117 test: test-disk
118         qemu-kvm -m 256 -L /usr/lib/qemu-bios -snapshot test-disk