forked from minosproject/minos2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
201 lines (165 loc) · 5.36 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
195
196
197
198
199
200
201
PHONY := _all
_all:
ifeq ($(DEBUG),1)
BUILD_DEBUG = 1
else
BUILD_DEBUG = 0
endif
ifeq ($(VERBOSE),1)
Q =
else
Q = @
endif
projtree := $(shell pwd)
srctree := .
src := $(srctree)
VPATH := $(srctree)
export BUILD_DEBUG VERBOSE srctree projtree
ARCH ?= aarch64
CROSS_COMPILE ?= aarch64-linux-gnu-
PLATFORM ?= fvp
TARGET_ARCH = $(ARCH)
TARGET_CROSS_COMPILE = $(CROSS_COMPILE)
TARGET_PLATFORM = $(PLATFORM)
export TARGET_ARCH TARGET_CROSS_COMPILE TARGET_PLATFORM
# Make variables (CC, etc...)
TARGET_AS = $(TARGET_CROSS_COMPILE)as
TARGET_LD = $(TARGET_CROSS_COMPILE)ld
TARGET_CC = $(TARGET_CROSS_COMPILE)gcc
TARGET_APP_CC = $(projtree)/out/bin/musl-gcc
TARGET_CPP = $(TARGET_CC) -E
TARGET_AR = $(TARGET_CROSS_COMPILE)ar
TARGET_NM = $(TARGET_CROSS_COMPILE)nm
TARGET_STRIP = $(TARGET_CROSS_COMPILE)strip
TARGET_OBJCOPY = $(TARGET_CROSS_COMPILE)objcopy
TARGET_OBJDUMP = $(TARGET_CROSS_COMPILE)objdump
TARGET_INSTALL = $(projtree)/tools/install.sh
TARGET_INCLUDE_DIR = $(projtree)/out/include
TARGET_LIBS_DIR = $(projtree)/out/lib
TARGET_OUT_DIR = $(projtree)/out
UAPI_INCLUDE_DIR = $(projtree)/generic/include/
HOST_LEX = flex
HOST_YACC = bison
HOST_AWK = awk
HOST_PERL = perl
HOST_PYTHON = python
HOST_PYTHON2 = python2
HOST_PYTHON3 = python3
HOST_CHECK = sparse
HOST_CC = gcc
HOST_AS = as
HOST_LD = ld
HOST_CC = gcc
HOST_CPP = gcc -E
HOST_AR = ar
HOST_NM = nm
HOST_STRIP = strip
HOST_OBJCOPY = objcopy
HOST_OBJDUMP = objdump
MAKE = make
MFLAGS := --no-print-directory
export TARGET_AS TARGET_LD TARGET_CC TARGET_APP_CC TARGET_CPP TARGET_AR TARGET_NM TARGET_STRIP TARGET_OBJCOPY TARGET_OBJDUMP MAKE TARGET_INCLUDE_DIR TARGET_LIBS_DIR TARGET_INSTALL TARGET_OUT_DIR UAPI_INCLUDE_DIR
export HOST_LEX HOST_YACC HOST_AWK HOST_PERL HOST_PYTHON HOST_PYTHON2 HOST_PYTHON3 HOST_CHECK HOST_CC HOST_AS HOST_LD HOST_CC HOST_APP_CC HOST_CPP HOST_AR HOST_NM HOST_STRIP HOST_OBJCOPY HOST_OBJDUMP
LIB_DIRS := user.libs
APP_DIRS := user.sbin user.bin user.driver
# get all the libs folder under LIB_DIRS
LIB_SUB_DIRS = $(foreach dir, $(LIB_DIRS), $(shell find $(dir) -maxdepth 1 -type d))
LIB_TARGETS = $(filter-out $(LIB_DIRS),$(LIB_SUB_DIRS))
# get the all application folders under APP_DIRS
APP_SUB_DIRS = $(foreach dir, $(APP_DIRS), $(shell find $(dir) -maxdepth 1 -type d))
APP_TARGETS = $(filter-out $(APP_DIRS),$(APP_SUB_DIRS))
PHONY += all
_all: all
PHONY += libc libs apps kernel
all: apps kernel
libc libs apps kernel: objdirs
apps: libs
$(Q) set -e; \
for i in $(APP_TARGETS); do \
if [ -f $$i/Makefile ]; then \
echo "\n\033[32m ---> Compiling App $$i ... \033[0m \n"; \
$(MAKE) $(MFLAGS) -C $$i ; \
$(MAKE) $(MFLAGS) -C $$i install; \
fi \
done
libs: libc
$(Q) set -e; \
for i in $(LIB_TARGETS); do \
if [ -f $$i/Makefile ]; then \
echo "\n\033[32m ---> Compiling Lib $$i ... \033[0m \n"; \
$(MAKE) $(MFLAGS) -C $$i ; \
$(MAKE) $(MFLAGS) -C $$i install; \
fi \
done
libc:
$(Q) echo "\n\033[32m---> Build LIBC ... \033[0m \n"
$(Q) $(MAKE) $(MFLAGS) -C user.libc -j 16
$(Q) $(MAKE) $(MFLAGS) -C user.libc install
kernel:
$(Q) echo "\n\033[32m ---> Build Kernel ... \033[0m \n"
$(Q) $(MAKE) $(MFLAGS) -C kernel
$(Q) $(MAKE) $(MFLAGS) -C kernel dtbs
$(Q) $(MAKE) $(MFLAGS) -C kernel install
clean-kernel:
$(Q) echo "\n\033[32m ---> Clean Kernel ... \033[0m \n"
$(Q) $(MAKE) $(MFLAGS) -C kernel clean
objdirs:
$(Q) mkdir -p $(srctree)/out
$(Q) mkdir -p $(srctree)/out/include
$(Q) mkdir -p $(srctree)/out/lib
$(Q) mkdir -p $(srctree)/out/ramdisk
$(Q) mkdir -p $(srctree)/out/rootfs/bin
$(Q) mkdir -p $(srctree)/out/rootfs/sbin
$(Q) mkdir -p $(srctree)/out/rootfs/driver
$(Q) mkdir -p $(srctree)/out/rootfs/etc
PHONY += images ramdisk rootfs prepare clean clean-libs clean-apps
clean-libs:
$(Q)set -e; \
for i in $(LIB_TARGETS); do \
if [ -f $$i/Makefile ]; then \
echo "\033[32m Clean $$i \033[0m"; \
$(MAKE) $(MFLAGS) -C $$i clean; \
fi \
done
clean-apps:
$(Q)set -e; \
for i in $(APP_TARGETS); do \
if [ -f $$i/Makefile ]; then \
echo "\033[32m Clean $$i \033[0m"; \
$(MAKE) $(MFLAGS) -C $$i clean; \
fi \
done
clean: clean-libs clean-apps
$(Q) echo "\033[32m Clean libc \033[0m"
$(Q) $(MAKE) $(MFLAGS) -C user.libc clean
$(Q) echo "\033[32m Clean kernel \033[0m"
$(Q) $(MAKE) $(MFLAGS) -C kernel clean
$(Q) rm -rf out
$(Q) echo "\033[32m Clean done ... \033[0m"
images: ramdisk rootfs kernel
ramdisk: apps kernel
$(Q) echo "\n\033[32m ---> Packing Ramdisk image ... \033[0m \n"
$(Q) mkrmd -d out/ramdisk.bin out/ramdisk
rootfs: apps
$(Q) echo "\n\033[32m ---> Packing Rootfs image ... \033[0m \n"
$(Q) mkdir -p /tmp/minos-mnt
$(Q) dd if=/dev/zero of=/tmp/rootfs.img bs=1M count=64
$(Q) mkfs.vfat -n "ROOTFS" -F 32 /tmp/rootfs.img
$(Q) sudo mount /tmp/rootfs.img /tmp/minos-mnt
$(Q) sudo cp -r out/rootfs/* /tmp/minos-mnt
$(Q) sudo umount /tmp/minos-mnt
$(Q) cp -f /tmp/rootfs.img out/rootfs.img
$(Q) rm -rf /tmp/rootfs.img /tmp/minos-mnt
prepare: objdirs
$(Q) cd user.libc; ./build.sh $(TARGET_OUT_DIR) $(TARGET_ARCH) $(TARGET_CROSS_COMPILE)
$(Q) cd kernel; make $(TARGET_PLATFORM)_defconfig
cp -f kernel/include/uapi/* user.libc/include/minos/
bin/% sbin/% driver/% libs/%:
$(Q)set -e; \
if [ -f user.$@/Makefile ]; then \
$(MAKE) $(MFLAGS) -C user.$@; \
$(MAKE) $(MFLAGS) -C user.$@ install; \
else \
echo "Target user.$@ not found"; \
fi
.PHONY: $(PHONY)