-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathMakefile
126 lines (103 loc) · 3.63 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
.PHONY := kbuild all clean stat include_build unittest buildlib test
srctree := $(shell pwd)
include tools/Kbuild.include
# Check if V options is set by user, if V=1, debug mode is set
# e.g. make V=1 produces all the commands being executed through
# the building process
ifeq ("$(origin V)", "command line")
KBUILD_VERBOSE = $(V)
endif
ifndef KBUILD_VERBOSE
KBUILD_VERBOSE = 0
endif
ifeq ($(KBUILD_VERBOSE),1)
Q =
else
MAKEFLAGS += --no-print-directory -s
Q = @
endif
export NO_MAKE_DEPEND := $(N)
export KBUILD_VERBOSE
export Q
export srctree \\
export depcache := .depcache
export SREC_INCLUDE := include_winix/srec
export SREC = $(shell find $(SREC_INCLUDE) -name "*.srec")
export TEXT_OFFSET := 1024
export CURR_UNIX_TIME := $(shell date +%s)
export WINIX_INCLUDE_PATH := -Iinclude_winix
export INCLUDE_PATH := -Iinclude
export WRAMP := -D__wramp__
export COMMON_CFLAGS := -DTEXT_OFFSET=$(TEXT_OFFSET) -D_DEBUG
export GCC_FLAG := -g -Wall -Werror -pedantic -Wno-comment -Wno-stringop-overflow -Wno-discarded-qualifiers -Wno-format
export CFLAGS := $(COMMON_CFLAGS) $(WINIX_INCLUDE_PATH) $(GCC_FLAG)
L_HEAD = winix/limits/limits_head.o
L_TAIL = winix/limits/limits_tail.o
KERNEL_O = winix/*.o kernel/system/*.o kernel/*.o fs/*.o fs/system/*.o driver/*.o include_winix/*.o
ALLDIR = init user kernel fs driver winix
ALLDIR_CLEAN = winix lib init user kernel fs driver include_winix
FS_DEPEND = fs/*.c fs/system/*.c fs/mock/*.c winix/bitmap.c
UNIT_TEST_DEPEND = $(shell find tests -name "*.c" -not -name "utest_runner.c")
DISK = include_winix/disk.c
UTEST_RUNNER = tests/utest_runner.c
START_TIME_FILE = include_winix/startup_time.c
UNIT_TEST = unittest
FSUTIL = fsutil
all:
$(Q)$(MAKE) buildlib
$(Q)$(MAKE) kbuild
$(Q)$(MAKE) include_build
$(Q)tools/bin/wlink $(LDFLAGS) -Ttext $(TEXT_OFFSET) -v -o winix.srec $(L_HEAD) $(KERNEL_O) `$(get_libs) $(KERNEL_O)` $(L_TAIL) > $(SREC_INCLUDE)/winix.verbose
ifeq ($(KBUILD_VERBOSE),0)
@echo "LD \t winix.srec"
endif
$(FSUTIL): $(FS_DEPEND) fs/fsutil/*.c lib/ansi/strl*.c
ifeq ($(KBUILD_VERBOSE),0)
@echo "CC \t $(FSUTIL)"
endif
$(Q)gcc -DFSUTIL $(CFLAGS) $^ -o $(FSUTIL)
buildlib:
$(Q)$(MAKE) $(build)=lib
# building cache currently takes more time than necessary, disable it
# $(Q)$(build_depcache)
kbuild: $(ALLDIR) $(FSUTIL)
$(ALLDIR): FORCE
$(Q)$(MAKE) $(build)=$@
$(DISK): $(SREC) $(FSUTIL)
ifeq ($(KBUILD_VERBOSE),0)
@echo "LD \t $(DISK)"
endif
$(Q)./fsutil -t $(TEXT_OFFSET) -o $(DISK) -s $(SREC_INCLUDE) -u $(CURR_UNIX_TIME)
include_build: $(DISK)
$(Q)echo "unsigned int start_unix_time=$(CURR_UNIX_TIME);\n" > $(START_TIME_FILE)
$(Q)$(MAKE) $(build)=include_winix
$(UTEST_RUNNER): $(UNIT_TEST_DEPEND) tools/utest_generator.py
$(Q)python3 tools/utest_generator.py $(UNIT_TEST_DEPEND) > $(UTEST_RUNNER)
$(UNIT_TEST): $(FS_DEPEND) $(UNIT_TEST_DEPEND) $(UTEST_RUNNER) user/wsh/parse.c lib/ansi/strl*.c
ifeq ($(KBUILD_VERBOSE),0)
@echo "CC \t $(UNIT_TEST)"
endif
$(Q)gcc -DFSUTIL $(CFLAGS) $^ -o $(UNIT_TEST)
test: $(UNIT_TEST)
$(Q)./$(UNIT_TEST)
wsh: user/wsh/*.c lib/ansi/strl*.c
$(Q)gcc $(COMMON_CFLAGS) $(GCC_FLAG) $^ -lreadline -lhistory -o wsh
snake: user/commands/snake.c lib/ansi/strl*.c
$(Q)gcc $(COMMON_CFLAGS) $(GCC_FLAG) $^ -o snake
clean:
$(Q)rm -f $(depcache)
$(Q)rm -f $(FSUTIL)
$(Q)rm -f $(UNIT_TEST)
$(Q)rm -f $(UTEST_RUNNER)
$(Q)rm -f $(START_TIME_FILE)
$(Q)rm -f $(DISK)
$(Q)$(MAKE) $(cleanall)='$(ALLDIR_CLEAN)'
stat:
@echo "C Lines: "
@find . -type d -name "include_winix" -prune -o -name "*.c" -exec cat {} \; | wc -l
@echo "Header LoC: "
@find . -name "*.h" -exec cat {} \; | wc -l
@echo "Assembly LoC: "
@find . -name "*.s" -exec cat {} \; | wc -l
FORCE:
# DO NOT DELETE