-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
194 lines (154 loc) · 4.23 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
include config.mk
############
# Programs #
############
# Toolchain
AR = $(CCPREFIX)ar
AS = $(CCPREFIX)as
CC = $(CCPREFIX)gcc
LD = $(CCPREFIX)ld
RANLIB = $(CCPREFIX)ranlib
# Common programs
CP = cp
MKDIR = mkdir
PWD = pwd
# Additional programs
GRUB_MKRESCUE = grub-mkrescue
RAKE = rake
QEMU = qemu-system-i386
#########
# Paths #
#########
ABS_REPO = $(shell $(PWD))
# Basic paths
MRUBY_CONF = build_config.rb
DEST_DIR = dest
IMAGE = image.iso
ROOTFS_DIR = rootfs
SRC_DIR = src
# Basic paths (dependencies)
LIBCLAYER_DIR = vendor/libclayer
LIBKERNAUX_DIR = vendor/libkernaux
DRIVERS_DIR = vendor/drivers
MRUBY_DIR = vendor/mruby
# Deeper paths
INCLUDE_DIR = $(DEST_DIR)/include
LIB_DIR = $(DEST_DIR)/lib
LIBCLAYER = $(LIB_DIR)/libc.a
LIBDRIVERS = $(LIB_DIR)/libdrivers.a
LIBKERNAUX = $(LIB_DIR)/libkernaux.a
LIBMRUBY = $(LIB_DIR)/libmruby.a
GRUBCFG = $(ROOTFS_DIR)/boot/grub/grub.cfg
MRUBYVISOR = $(ROOTFS_DIR)/boot/mrubyvisor.multiboot2
#############
# libclayer #
#############
LIBCLAYER_ARGS = \
--enable-libc \
--disable-libclayer \
--enable-freestanding
LIBCLAYER_VARS = \
AR='$(AR)' \
AS='$(AS)' \
CC='$(CC)' \
LD='$(LD)' \
RANLIB='$(RANLIB)'
##############
# libkernaux #
##############
LIBKERNAUX_ARGS = \
--enable-freestanding \
--enable-split-libc \
--enable-debug \
--disable-float
LIBKERNAUX_VARS = \
AR='$(AR)' \
AS='$(AS)' \
CC='$(CC)' \
LD='$(LD)' \
RANLIB='$(RANLIB)' \
CFLAGS='-I$(ABS_REPO)/$(INCLUDE_DIR)'
###########
# drivers #
###########
DRIVERS_CFLAGS = \
-nostdlib \
-ffreestanding \
-fno-pic \
-fno-stack-protector
DRIVERS_VARS = \
AR='$(AR)' \
AS='$(AS)' \
CC='$(CC)' \
LD='$(LD)' \
RANLIB='$(RANLIB)' \
CFLAGS='$(DRIVERS_CFLAGS)'
#########
# mruby #
#########
MRUBY_BUILD_NAME = mrubyvisor
MRUBY_FLAGS = \
-DMRB_NO_BOXING \
-DMRB_NO_FLOAT \
-DMRB_NO_STDIO
MRUBY_VARS = \
MRUBY_CONFIG='$(ABS_REPO)/$(MRUBY_CONF)' \
CROSS_AR='$(AR)' \
CROSS_CC='$(CC)' \
CROSS_LD='$(LD)' \
FLAGS='$(MRUBY_FLAGS)' \
BUILD_NAME='$(MRUBY_BUILD_NAME)' \
INCLUDE_DIR='$(ABS_REPO)/$(INCLUDE_DIR)' \
LIB_DIR='$(ABS_REPO)/$(LIB_DIR)'
#########
# Tasks #
#########
.PHONY: $(IMAGE) $(MRUBYVISOR)
all: runc
runc: $(IMAGE)
$(QEMU) -cdrom $< -serial stdio -display none
runw: $(IMAGE)
$(QEMU) -cdrom $< -serial stdio
clean: clean-src clean-dest clean-mruby clean-libkernaux clean-libclayer
clean-src:
$(MAKE) -C $(SRC_DIR) clean
clean-dest:
rm -rf $(MRUBYVISOR) $(DEST_DIR)/*
clean-mruby:
cd $(MRUBY_DIR) && $(RAKE) clean
clean-drivers:
$(MAKE) -C $(DRIVERS_DIR) distclean || true
clean-libkernaux:
$(MAKE) -C $(LIBKERNAUX_DIR) distclean || true
clean-libclayer:
$(MAKE) -C $(LIBCLAYER_DIR) distclean || true
##############
# File tasks #
##############
$(IMAGE): $(GRUBCFG) $(MRUBYVISOR)
$(GRUB_MKRESCUE) $(ROOTFS_DIR) -o $@
$(MRUBYVISOR): $(LIBCLAYER) $(LIBKERNAUX) $(LIBDRIVERS) $(LIBMRUBY)
$(MAKE) -C $(SRC_DIR) mrubyvisor.multiboot2 CCPREFIX='$(CCPREFIX)' DEST='$(ABS_REPO)/$(DEST_DIR)' MRUBY_FLAGS='$(MRUBY_FLAGS)'
$(CP) $(SRC_DIR)/mrubyvisor.multiboot2 $@
$(LIBCLAYER):
cd $(LIBCLAYER_DIR) && ./autogen.sh
cd $(LIBCLAYER_DIR) && ./configure --host='i386-elf' --prefix='$(ABS_REPO)/$(DEST_DIR)' $(LIBCLAYER_ARGS) $(LIBCLAYER_VARS)
cd $(LIBCLAYER_DIR) && $(MAKE)
cd $(LIBCLAYER_DIR) && $(MAKE) install
$(LIBKERNAUX): $(LIBCLAYER)
cd $(LIBKERNAUX_DIR) && ./autogen.sh
cd $(LIBKERNAUX_DIR) && ./configure --host='i386-elf' --prefix='$(ABS_REPO)/$(DEST_DIR)' $(LIBKERNAUX_ARGS) $(LIBKERNAUX_VARS)
cd $(LIBKERNAUX_DIR) && $(MAKE)
cd $(LIBKERNAUX_DIR) && $(MAKE) install
$(LIBDRIVERS):
cd $(DRIVERS_DIR) && ./autogen.sh
cd $(DRIVERS_DIR) && ./configure --host='i386-elf' --prefix='$(ABS_REPO)/$(DEST_DIR)' $(DRIVERS_VARS)
cd $(DRIVERS_DIR) && $(MAKE)
cd $(DRIVERS_DIR) && $(MAKE) install
$(LIBMRUBY): $(LIBKERNAUX) $(MRUBY_CONF)
$(MAKE) clean-mruby
$(MKDIR) -p $(INCLUDE_DIR) $(LIB_DIR)
cd $(MRUBY_DIR) && $(RAKE) $(MRUBY_VARS)
$(CP) -r $(MRUBY_DIR)/include/* $(INCLUDE_DIR)
$(CP) -r $(MRUBY_DIR)/build/$(MRUBY_BUILD_NAME)/include/* $(INCLUDE_DIR)
$(CP) $(MRUBY_DIR)/build/$(MRUBY_BUILD_NAME)/lib/libmruby.a $(LIB_DIR)