-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
131 lines (97 loc) · 3.49 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
CC = gcc
CWARN = -Wall -Wno-pointer-sign -Wno-unused-variable
CFLAGS = -fno-pie -no-pie -nostdlib -m32 -fno-builtin -O0 $(CWARN)
INCLUDE = -I include -I src/tools/stdlibc/include
LD = ld
LFLAGS = -m elf_i386
QEMU = qemu-system-x86_64
TARGET_DIR = bin
LST_DIR = $(TARGET_DIR)/lst
TMP_DIR = $(TARGET_DIR)/tmp
OS_SRC_DIR = src
OS_SRC=$(wildcard $(OS_SRC_DIR)/*.c)
OS_LS = scripts/bootpack.lds
OS = $(TARGET_DIR)/os.bin
OS_MMAP = $(TARGET_DIR)/os.map
OS_ENTRY_POINT = HariMain
SYSTEM_IMG = bin/haribooote.bin
ASMLIB_SRC = src/asm/asm_func.s
ASMLIB = $(TARGET_DIR)/asm_func.o
IPL_SRC = src/asm/boot/ipl20.s
IPL_LS = scripts/ipl.lds
IPL = $(TARGET_DIR)/ipl20.bin
OSL_SRC = src/asm/boot/asmhead.s
OSL_LS = scripts/asmhead.lds
OSL = $(TARGET_DIR)/asmhead.bin
#external lib
STDLIBC_DIR = src/tools/stdlibc
STDLIBC = $(STDLIBC_DIR)/bin/stdlibc.o
FONT_DIR = src/tools/makefont
FONT = $(FONT_DIR)/bin/hankaku.o
JPFONT = src/tools/font/nihongo.fnt
JPFONT_TEST_FILE = src/tools/font/sjis.txt src/tools/font/euc.txt
EXCLUDE_EXLIB_DEP_FILE = *.swp
IMG = $(TARGET_DIR)/haribooote.img
#application
APP_TARGET_DIR = $(TARGET_DIR)/app/dist
APP_SRC_DIR = src/app
APP_SRC = $(shell find $(APP_SRC_DIR) -type f)
APP_DIRS = $(shell find $(APP_SRC_DIR) -maxdepth 1 -type d -not -path $(APP_SRC_DIR))
PICT1 = src/tools/pictdata/fujisan.jpg
PICT2 = src/tools/pictdata/night.bmp
MML1 = src/tools/mmldata/daigo.mml
MML2 = src/tools/mmldata/daiku.mml
MML3 = src/tools/mmldata/fujisan.mml
MML4 = src/tools/mmldata/kirakira.mml
define make_app
cd $1; make;
endef
define copy_app
mcopy $1 -i $(IMG) ::
endef
all: $(IMG)
apps: $(APP_SRC)
@echo [Application] build
$(foreach x, $(APP_DIRS), $(call make_app, $(x)))
$(FONT): $(shell find $(FONT_DIR) -type f -not -name '$(EXCLUDE_EXLIB_DEP_FILE)' -not -name '$(notdir $(FONT))')
@echo [Dependent Files] FONT: $^
cd $(FONT_DIR); make
$(STDLIBC): $(shell find $(STDLIBC_DIR) -type f -not -name '$(EXCLUDE_EXLIB_DEP_FILE)' -not -name '$(notdir $(STDLIBC))')
@echo [Dependent Files] STDLIBC: $^
cd $(STDLIBC_DIR); make all
$(IMG): $(IPL) $(OSL) $(OS) apps $(JPFONT) $(JPFONT_TEST_FILE)
cat $(OSL) $(OS) > $(SYSTEM_IMG)
mformat -f 1440 -B $(IPL) -C -i $(IMG) ::
mcopy $(SYSTEM_IMG) -i $(IMG) ::
$(foreach x, $(shell find $(APP_TARGET_DIR) -type f), $(call copy_app, $(x)))
mcopy $(IPL_SRC) -i $(IMG) ::
mcopy $(JPFONT) -i $(IMG) ::
mcopy $(JPFONT_TEST_FILE) -i $(IMG) ::
mcopy $(PICT1) -i $(IMG) ::
mcopy $(PICT2) -i $(IMG) ::
mcopy $(MML1) -i $(IMG) ::
mcopy $(MML2) -i $(IMG) ::
mcopy $(MML3) -i $(IMG) ::
mcopy $(MML4) -i $(IMG) ::
$(OS): $(addprefix $(TARGET_DIR)/, $(notdir $(OS_SRC:.c=.o))) $(STDLIBC) $(ASMLIB) $(FONT)
ld $(LFLAGS) -o $@ -T $(OS_LS) -e HariMain --oformat=binary -Map=$(OS_MMAP) $^
$(ASMLIB): $(ASMLIB_SRC)
$(CC) $(CFLAGS) -c -g -Wa,-a,-ad $< -o $@ > $(addprefix $(LST_DIR)/, $(notdir $(@F:.o=.lst)))
$(TARGET_DIR)/%.o : $(OS_SRC_DIR)/%.c
$(CC) $(CFLAGS) $(INCLUDE) -nostdlib -m32 -c -o $@ $<
$(IPL): $(IPL_SRC)
mkdir -p $(TARGET_DIR)
mkdir -p $(LST_DIR)
mkdir -p $(TMP_DIR)
gcc $(CFLAGS) -o $@ -T$(IPL_LS) $(IPL_SRC)
$(OSL): $(OSL_SRC)
$(CC) $(CFLAGS) -o $@ -T $(OSL_LS) $(OSL_SRC)
$(CC) $(CFLAGS) -o $(addprefix $(TMP_DIR)/, $(notdir $(@F:.s=.o))) -T $(OSL_LS) -c -g -Wa,-a,-ad $(OSL_SRC) > $(addprefix $(LST_DIR)/, $(notdir $(@F:.bin=.lst)))
run: all
$(QEMU) -m 32M -drive format=raw,file=$(IMG),if=floppy
debug: all
$(QEMU) -drive format=raw,file=$(IMG),if=floppy -gdb tcp::10000 -S
clean:
rm -rf $(TARGET_DIR)
cd $(FONT_DIR); make clean
cd $(STDLIBC_DIR); make clean