-
Notifications
You must be signed in to change notification settings - Fork 10
/
Makefile
114 lines (89 loc) · 3.12 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Copyright 2016 The Fuchsia Authors
#
# 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.
ARCH := x86_64
EFI_TOOLCHAIN :=
EFI_CC := $(EFI_TOOLCHAIN)gcc
EFI_LD := $(EFI_TOOLCHAIN)ld
EFI_OBJCOPY := $(EFI_TOOLCHAIN)objcopy
EFI_AR := $(EFI_TOOLCHAIN)ar
EFI_PATH := third_party/gnu-efi
EFI_LIB_PATHS := $(EFI_PATH)/$(ARCH)/lib $(EFI_PATH)/$(ARCH)/gnuefi out
EFI_INC_PATHS := $(EFI_PATH)/inc $(EFI_PATH)/inc/$(ARCH) $(EFI_PATH)/inc/protocol
EFI_CRT0 := $(EFI_PATH)/$(ARCH)/gnuefi/crt0-efi-$(ARCH).o
EFI_LINKSCRIPT := $(EFI_PATH)/gnuefi/elf_$(ARCH)_efi.lds
EFI_CFLAGS := -fpic -fshort-wchar -fno-stack-protector -mno-red-zone
EFI_CFLAGS += -Wall
EFI_CFLAGS += -std=c99
EFI_CFLAGS += -ffreestanding -nostdinc -Iinclude -Isrc -Ithird_party/edk2 -Ithird_party/lk/include
EFI_CFLAGS += $(patsubst %,-I%,$(EFI_INC_PATHS))
EFI_CFLAGS += -DHAVE_USE_MS_ABI=1
EFI_CFLAGS += -ggdb
EFI_LDFLAGS := -nostdlib -znocombreloc -T $(EFI_LINKSCRIPT)
EFI_LDFLAGS += -shared -Bsymbolic
EFI_LDFLAGS += $(patsubst %,-L%,$(EFI_LIB_PATHS))
EFI_LIBS := -lstuff -lefi -lgnuefi
what_to_build:: all
# build rules and macros
include build/build.mk
# declare applications here
#$(call efi_app, hello, hello.c)
$(call efi_app, showmem, showmem.c)
$(call efi_app, fileio, fileio.c)
$(call efi_app, osboot, osboot.c netboot.c netifc.c inet6.c)
$(call efi_app, usbtest, usbtest.c)
ifneq ($(APP),)
APP := out/$(APP).efi
else
APP := out/osboot.efi
endif
LIB_SRCS := lib/goodies.c lib/loadfile.c lib/console-printf.c lib/string.c
LIB_SRCS += third_party/lk/src/printf.c
LIB_OBJS := $(patsubst %.c,out/%.o,$(LIB_SRCS))
DEPS += $(patsubst %.c,out/%.d,$(LIB_SRCS))
out/libstuff.a: $(LIB_OBJS)
@mkdir -p $(dir $@)
@echo archiving: $@
$(QUIET)rm -f $@
$(QUIET)ar rc $@ $^
out/BOOTx64.EFI: $(APP)
@mkdir -p $(dir $@)
$(QUIET)cp -f $^ $@
# generate a small IDE disk image for qemu
out/disk.img: $(APPS) out/BOOTx64.EFI
@mkdir -p $(dir $@)
$(QUIET)./build/mkdiskimg.sh $@
@echo copying: $(APPS) README.txt to disk.img
$(QUIET)mcopy -o -i out/disk.img@@1024K $(APPS) README.txt ::
$(QUIET)mcopy -o -i out/disk.img@@1024K $(APPS) out/BOOTx64.EFI ::EFI/BOOT/
ALL += out/disk.img
-include $(DEPS)
# ensure gnu-efi gets built
$(EFI_CRT0):
@echo building: gnu-efi
$(QUIET)$(MAKE) -C $(EFI_PATH)
QEMU_OPTS := -cpu qemu64
QEMU_OPTS += -bios third_party/ovmf/OVMF.fd
QEMU_OPTS += -drive file=out/disk.img,format=raw,if=ide
QEMU_OPTS += -serial stdio
qemu:: all
qemu-system-x86_64 $(QEMU_OPTS)
out/nbserver: src/nbserver.c
@mkdir -p out
@echo building nbserver
$(QUIET)gcc -o out/nbserver -Isrc -Wall src/nbserver.c
all: $(ALL) out/nbserver
clean::
rm -rf out
all-clean: clean
make -C third_party/gnu-efi clean