-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
63 lines (49 loc) · 1.12 KB
/
makefile
File metadata and controls
63 lines (49 loc) · 1.12 KB
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
CC := gcc
AR := ar
AS := as
SRC_DIR := src
INC_DIR := include/libc
BUILD := build
SYSROOT := sysroot
LIB_DIR := $(SYSROOT)/lib
INC_OUT := $(SYSROOT)/include
LIBC_A := blibc.a
CFLAGS := \
-ffreestanding \
-fno-builtin \
-fno-stack-protector \
-fno-pic \
-fno-pie \
-nostdinc \
-Iinclude \
-Iinclude/libc \
-Wall -Wextra \
-std=gnu11 \
-O2 \
C_SRCS := $(sort $(shell find $(SRC_DIR) -type f -name '*.c'))
S_SRCS := $(sort $(shell find $(SRC_DIR) -type f -name '*.S'))
OBJS := \
$(C_SRCS:$(SRC_DIR)/%.c=$(BUILD)/%.o) \
$(S_SRCS:$(SRC_DIR)/%.S=$(BUILD)/%.o)
START_SRC := $(firstword $(filter %/start.S,$(S_SRCS)))
START := $(START_SRC:$(SRC_DIR)/%.S=$(BUILD)/%.o)
.PHONY: all sysroot clean
all: sysroot
sysroot: $(LIBC_A)
@mkdir -p $(LIB_DIR)
@mkdir -p $(INC_OUT)
cp $(LIBC_A) $(LIB_DIR)/
cp $(START) $(LIB_DIR)/
cp -r include/* $(INC_OUT)/
$(LIBC_A): $(OBJS)
$(AR) rcs $@ $^
$(BUILD)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD)/%.o: $(SRC_DIR)/%.S
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -rf $(BUILD)
rm -rf $(LIBC_A)
rm -rf $(SYSROOT)