forked from sysprog21/semu
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
119 lines (94 loc) · 2.48 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
include mk/common.mk
STOP_AT_LOGIN=0
C64=1
ifeq ($(C64), 1)
CC = mos-c64-clang
CFLAGS := -O3 -g -Wall -Wextra -flto -DC64=1
else
CC ?= gcc
CFLAGS := -O2 -g -Wall -Wextra -DC64=0
endif
ifeq ($(STOP_AT_LOGIN), 1)
CFLAGS += -DSTOP_AT_LOGIN=1
endif
CFLAGS += -include common.h
OBJS_EXTRA :=
# command line option
OPTS :=
# virtio-blk
ENABLE_VIRTIOBLK ?= 0
$(call set-feature, VIRTIOBLK)
DISKIMG_FILE :=
MKFS_EXT4 ?= mkfs.ext4
ifeq ($(call has, VIRTIOBLK), 1)
OBJS_EXTRA += virtio-blk.o
DISKIMG_FILE := ext4.img
OPTS += -d $(DISKIMG_FILE)
MKFS_EXT4 := $(shell which $(MKFS_EXT4))
ifndef MKFS_EXT4
MKFS_EXT4 := $(shell which $$(brew --prefix e2fsprogs)/sbin/mkfs.ext4)
endif
ifndef MKFS_EXT4
$(error "No mkfs.ext4 found.")
endif
endif
# virtio-net
ENABLE_VIRTIONET ?= 0
ifneq ($(UNAME_S),Linux)
ENABLE_VIRTIONET := 0
endif
$(call set-feature, VIRTIONET)
ifeq ($(call has, VIRTIONET), 1)
OBJS_EXTRA += virtio-net.o
endif
BIN = semu
all: $(BIN) minimal.dtb
OBJS := \
riscv.o \
ram.o \
plic.o \
uart.o \
main.o \
persistence.o \
$(OBJS_EXTRA)
ifeq ($(C64), 1)
OBJS += reu.o
endif
deps := $(OBJS:%.o=.%.o.d)
$(BIN): $(OBJS)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)
%.o: %.c
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) -c -MMD -MF [email protected] $<
DTC ?= dtc
# GNU Make treats the space character as a separator. The only way to handle
# filtering a pattern with space characters in a Makefile is by replacing spaces
# with another character that is guaranteed not to appear in the variable value.
# For instance, one can choose a character like '^' that is known not to be
# present in the variable value.
# Reference: https://stackoverflow.com/questions/40886386
E :=
S := $E $E
minimal.dtb: minimal.dts
$(VECHO) " DTC\t$@\n"
$(Q)$(CC) -nostdinc -E -P -x assembler-with-cpp -undef \
$(subst ^,$S,$(filter -D^SEMU_FEATURE_%, $(subst -D$(S)SEMU_FEATURE,-D^SEMU_FEATURE,$(CFLAGS)))) $< \
| $(DTC) - > $@
# Rules for downloading prebuilt Linux kernel image
include mk/external.mk
ext4.img:
$(Q)dd if=/dev/zero of=$@ bs=4k count=600
$(Q)$(MKFS_EXT4) -F $@
check: $(BIN) minimal.dtb $(KERNEL_DATA) $(INITRD_DATA) $(DISKIMG_FILE)
@$(call notice, Ready to launch Linux kernel. Please be patient.)
$(Q)./$(BIN) -k $(KERNEL_DATA) -b minimal.dtb -i $(INITRD_DATA) $(OPTS)
build-image:
scripts/build-image.sh
clean:
$(Q)$(RM) $(BIN) $(OBJS) $(deps)
distclean: clean
$(Q)$(RM) minimal.dtb
$(Q)$(RM) Image rootfs.cpio
$(Q)$(RM) ext4.img
-include $(deps)