-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmakefile
133 lines (111 loc) · 3.2 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#name and versioning
NAME = ExOS
BIN_NAME = kernel.bin
VERSION = 0.0.1A
FULL_NAME = $(NAME)-$(VERSION)
COMMIT = $(shell git log -n 1 --format="%h")
TIMESTAMP = $(shell date +'%Y%m%d.%H%M')
#top level dirs
TOPDIR = $(shell git rev-parse --show-toplevel)
SRCDIR = src
OBJDIR = .build
#source files and dirs
SRC_SUBDIRS = $(shell find $(SRCDIR) -type d -print)
C_SRC_FILES = $(foreach dir, $(SRC_SUBDIRS), $(wildcard $(dir)/*.c))
CPP_SRC_FILES = $(foreach dir, $(SRC_SUBDIRS), $(wildcard $(dir)/*.cpp))
SPECIAL_SRC_FILES = Boot.s ISRWrapper.s
LINKER_FILE = $(TOPDIR)/linker.ld
#object files
OBJFILES = $(patsubst %.c,$(OBJDIR)/%.o,$(C_SRC_FILES)) \
$(patsubst %.cpp,$(OBJDIR)/%.o,$(CPP_SRC_FILES)) \
$(OBJDIR)/Boot.o $(OBJDIR)/ISRWrapper.o
#programs
AS = i686-elf-as
GPP = i686-elf-g++
GCC = i686-elf-gcc
MKDIR = mkdir --parents
#flags
INCLUDES = -I$(TOPDIR)/src
LDFLAGS = -ffreestanding -O2 -fno-rtti -fno-exceptions -nostartfiles \
-nostdlib
CFLAGS = -c -ffreestanding -O2 -Wno-packed-bitfield-compat -Wall -Wextra \
-fno-rtti -fno-exceptions -g -std=gnu++14 $(INCLUDES)
LINK = -lgcc
#Text minip
RED = $$(tput setaf 1)
BLUE = $$(tput setaf 4)
GREEN = $$(tput setaf 2)
WHITE = $$(tput setaf 7)
YELLOW = $$(tput setaf 3)
BOLD = $$(tput bold)
NORMAL = $$(tput sgr0)
#verbose option
ifeq ($(VERBOSE), yes)
RUN =
else
RUN = @
VERBOSE = no
endif
#general info
HOSTTYPE = $(shell uname -s)
ifdef MAKECMDGOALS
TARGETGOAL = $(MAKECMDGOALS)
else
TARGETGOAL = $(.DEFAULT_GOAL)
endif
all: warning config $(BIN_NAME) finish
warning:
ifeq ($(VERBOSE),no)
@echo
@echo 'For a more verbose output'
@echo ' make '$(GREEN)'VERBOSE=yes' $(NORMAL)$(TARGETGOAL)
@echo
endif
config:
@echo
@echo 'TARGET' $(TARGETGOAL)
@echo 'VERBOSE' $(VERBOSE)
@echo
@echo 'VERSION ' $(VERSION)
@echo 'COMMIT '$(COMMIT)
@echo 'DATE ' $(TIMESTAMP)
@echo 'HOST ' $(HOSTTYPE)
@echo
$(BIN_NAME): $(OBJFILES)
ifeq ($(VERBOSE),no)
@echo 'Constructing' $(RED)$@$(NORMAL)
endif
$(RUN)$(GCC) -T $(LINKER_FILE) -o '$@' $(LDFLAGS) $(OBJFILES) $(LINK)
#general rules
$(OBJDIR)/%.o: %.c
ifeq ($(VERBOSE),no)
@echo 'Building' $(YELLOW)$<$(NORMAL)
endif
@test -d $(OBJDIR)/$(dir $<) || $(MKDIR) $(OBJDIR)/$(dir $<)
$(RUN)$(GPP) -o '$@' $(CFLAGS) "$<"
$(OBJDIR)/%.o: %.cpp
ifeq ($(VERBOSE),no)
@echo 'Building' $(YELLOW)$<$(NORMAL)
endif
@test -d $(OBJDIR)/$(dir $<) || $(MKDIR) $(OBJDIR)/$(dir $<)
$(RUN)$(GPP) -o '$@' $(CFLAGS) "$<"
#special rules
$(OBJDIR)/Boot.o: $(TOPDIR)/src/boot/Boot.s
ifeq ($(VERBOSE),no)
@echo 'Building' $(YELLOW)$<$(NORMAL)
endif
@test -d $(OBJDIR)/$(dir $<) || $(MKDIR) $(OBJDIR)/$(dir $<)
$(RUN)nasm $(TOPDIR)/src/boot/Boot.s -felf -o $(OBJDIR)/Boot.o
$(OBJDIR)/ISRWrapper.o: $(TOPDIR)/src/interrupts/ISRWrapper.s
ifeq ($(VERBOSE),no)
@echo 'Building' $(YELLOW)$<$(NORMAL)
endif
@test -d $(OBJDIR)/$(dir $<) || $(MKDIR) $(OBJDIR)/$(dir $<)
$(RUN)$(AS) $(TOPDIR)/src/interrupts/ISRWrapper.s -o $(OBJDIR)/ISRWrapper.o
finish:
@echo 'Finished' $(BOLD)$(GREEN)$(TARGETGOAL)$(NORMAL)
clean:
$(RUN)rm -rf $(OBJDIR)
$(RUN)rm $(BIN_NAME)
@echo 'Finished' $(BOLD)$(GREEN)$(TARGETGOAL)$(NORMAL)
.PHONY: all warning config clean finish