forked from ViudiraTech/ApexBIOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
66 lines (50 loc) · 1.91 KB
/
Makefile
File metadata and controls
66 lines (50 loc) · 1.91 KB
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
# =====================================================
# Makefile
# ApexBIOS compile script
#
# Based on GPL-3.0 open source agreement
# Copyright © 2020 ViudiraTech, based on the GPLv3 agreement.
# =====================================================
ifeq ($(VERBOSE), 1)
V=
Q=
else
V=@printf "\033[1;32m[Build]\033[0m $@ ...\n";
Q=@
endif
ASM = nasm
ASMFLAGS = -fbin
CC = gcc
CFLAGS = -m32 -ffreestanding -fno-pic -w -Os -I ./src/include/ -fno-stack-protector
LD = ld
LDFLAGS = -nostdlib -static -T scripts/linker.ld
SRCDIR := src
OBJDIR := build
C_SOURCES := $(shell find * -name "*.c")
S_SOURCES := $(shell find * -name "*.s")
HEADERS := $(shell find * -name "*.h")
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
SRC = $(call rwildcard,$(SRCDIR),*.c)
OBJS = $(call reverse,$(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SRC)))
OUTFILE = bios.rom
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(@D)
$(V)$(CC) $(CFLAGS) -c $^ -o $@
%.fmt: %
$(Q)printf "\033[1;32m[Format]\033[0m $< ...\n"
$(Q)clang-format -i $<
.PHONY: format build clean run
build: $(OBJS)
@$(LD) $(LDFLAGS) $(OBJS) src/lib/logo.lib src/lib/EPA.lib -o build/c_entry.bin
@printf "\n\033[1;32m[LINK]\033[0m Linking..."
@stat -L -c "" build/c_entry.bin
@$(ASM) $(ASMFLAGS) src/entry16.asm -o $(OUTFILE)
@printf "\033[1;32m[Done]\033[0m Compilation complete.\n\n"
format: $(C_SOURCES:%=%.fmt) $(S_SOURCES:%=%.fmt) $(HEADERS:%=%.fmt)
$(Q)printf "\033[1;32m[Done]\033[0m Code Format complete.\n\n"
clean:
@rm -rf build bios.rom
@printf "\033[1;32m[Done]\033[0m Clean done.\n\n"
run:
qemu-system-x86_64 -bios $(OUTFILE) -serial stdio -vga none -device ramfb -m 256M