-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
111 lines (80 loc) · 2.47 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
SRCDIR := src
BINDIR := bin
OBJDIR := obj
INCDIR := include
CXX := g++
CC := gcc
ASM := nasm
CXXFLAGS := -g -Wall -std=c++11 -I$(INCDIR)
CCFLAGS := -g -Wall -I$(INCDIR)
ASMFLAGS := -I$(SRCDIR)/
QEMU := qemu-system-i386
# Edit the below lists to add binaries and objects
# List of projects (binaries) to make by default, run 'make binaryname' to make a non-default one from the list below
PROJS := boot stage2 sector2
# List of binaries that can be made, and the objects they each need
# binname1 := obj1 obj2 obj3
# binname2 := obj1 obj3 obj4
boot := boot
stage2 := stage2
sector2 := sector2.asm
makedisk:
scripts/createdisk.sh
scripts/lo.sh
scripts/formatdisk.sh
scripts/copyboot.sh
scripts/copystage2.sh
scripts/unlo.sh
full: all makedisk
run: full runonly
runonly:
${QEMU} disk.img
doc: doc/README.html
doc/README.html: README.md
mkdir -p doc
markdown README.md > doc/README.html
# Custom clean commands to be automatically executed when 'make clean' is run
userclean:
rm -f disk.img
# ----- DON'T EDIT BELOW HERE -----
# So that we can find .h and .cpp files as prereqs
vpath %.h $(INCDIR)
vpath %.c $(SRCDIR)
vpath %.cpp $(SRCDIR)
vpath %.asm $(SRCDIR)
# Format PROJS correctly to be valid targets
_PROJ_TARGETS := $(addprefix $(BINDIR)/, ${PROJS})
# Make all the binaries in $(_PROJ_TARGETS)
.DEFAULT_GOAL := all
.PHONY: all
all: folders $(_PROJ_TARGETS)
.PHONY: folders
folders:
@if [ ! -d "$(BINDIR)" ]; then mkdir -p $(BINDIR) && echo "mkdir -p $(BINDIR)"; fi
@if [ ! -d "$(OBJDIR)" ]; then mkdir -p $(OBJDIR) && echo "mkdir -p $(OBJDIR)"; fi
# Makes '$(BINDIR)/binaryname' with prerequisites: '$(OBJDIR)/prereqname.o'. Prereq names come from expanding the variable named like binaryname
# $$($$(*F)) expands (with second expansion) to the names of the needed prereqs. $(*F) expands to the target name without directory. $($(*F)) in effect expands the variable named *F
.SECONDEXPANSION:
$(BINDIR)/%: $$(addprefix $(OBJDIR)/, $$(addsuffix .o, $$($$(*F))))
$(CXX) $(CXXFLAGS) -o $(BINDIR)/$* $^
# Secondary to prevent auto deletion of .o files
# CXX objects
.SECONDARY:
$(OBJDIR)/%.o : %.cpp %.h
$(CXX) $(CXXFLAGS) -c -o $@ $<
# C objects
.SECONDARY:
$(OBJDIR)/%.o : %.c %.h
$(CC) $(CFLAGS) -c -o $@ $<
# ASM binaries
.SECONDARY:
$(BINDIR)/% : %.asm
$(ASM) $(ASMFLAGS) -o $@ $<
# Make '$(BINDIR)/targetname' when 'make targetname' is invoked
.DEFAULT:
$(MAKE) $(BINDIR)/$@
# Disable built-in suffix rules
.SUFFIXES:
.PHONY: clean
clean: userclean
rm -rf $(OBJDIR) $(BINDIR)