-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
83 lines (64 loc) · 2.14 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
# Makefile for Lua OS
# Copyright 2022-2023, Joe Xue(lgxue@hotmail.com)
PROJ = luaos
SRCDIR = src lua-5.4.4
BUILDDIR = output
SCRIPTDIR = script
ROOTFSDIR = rootfs
SRC_NOT_BUILD = lua-5.4.4/src/luac.c
SRC = $(filter-out $(SRC_NOT_BUILD), $(shell find $(SRCDIR) -name *.c -o -name *.S -o -name *.lua))
OBJS = $(addsuffix .o,$(addprefix $(BUILDDIR)/,$(SRC)))
FILES = $(shell find $(ROOTFSDIR) -type f)
CFLAGS = -g -Wall -MMD -Ilua-5.4.4/src
SYSROOT = /opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf/aarch64-none-elf
CROSS_COMPILE = $(SYSROOT)/../bin/aarch64-none-elf-
CC = $(CROSS_COMPILE)gcc
OBJCOPY = $(CROSS_COMPILE)objcopy
QUIET = @
.PHONY: all clean run
all: $(BUILDDIR)/$(PROJ).bin
$(BUILDDIR)/$(PROJ).bin: $(BUILDDIR)/$(PROJ).elf
$(QUIET)$(OBJCOPY) -O binary $^ $@
$(BUILDDIR)/$(PROJ).elf: $(OBJS)
$(QUIET)$(CC) -static -T $(SCRIPTDIR)/$(PROJ).ld $^ -nostdlib -lc -lm -lgcc -o $@
run: $(BUILDDIR)/$(PROJ).elf
$(QUIET)qemu-system-aarch64 \
-M virt \
-m 16 \
-cpu cortex-a53 \
-nographic \
-serial mon:stdio \
-kernel $(BUILDDIR)/$(PROJ).bin
clean:
-rm -rf $(BUILDDIR)
$(BUILDDIR)/%.c.o : %.c
$(QUIET)echo $@
$(QUIET)-mkdir -p $(@D)
$(QUIET)$(CC) $(CFLAGS) -c $< -o $@
$(BUILDDIR)/%.S.o : %.S
$(QUIET)echo $@
$(QUIET)-mkdir -p $(@D)
$(QUIET)$(CC) $(CFLAGS) -c $< -o $@
$(BUILDDIR)/$(ROOTFSDIR)/ramfs: $(FILES)
$(QUIET)echo $@
$(QUIET)-mkdir -p $(@D)
$(QUIET)echo "local ramfs = {}" > $@
$(QUIET)for f in $(FILES); do \
n=`basename $$f`; \
echo "local fc = [==[" >> $@; \
cat $$f >> $@; \
echo "]==]" >> $@; \
echo "ramfs[\"$$n\"] = fc" >> $@; \
done
# convert the lua file into c char[]
.NOTPARALLEL: $(BUILDDIR)/%.lua.o
$(BUILDDIR)/%.lua.o : %.lua $(FILES) $(BUILDDIR)/$(ROOTFSDIR)/ramfs
$(QUIET)echo $@
$(QUIET)-mkdir -p $(@D)
$(QUIET)echo "unsigned char $(basename $(<F))[] = {" > $@.c
$(QUIET)cat $(BUILDDIR)/$(ROOTFSDIR)/ramfs | xxd -i >> $@.c
$(QUIET)echo "," >> $@.c
$(QUIET)cat $< | xxd -i >> $@.c
$(QUIET)echo ", 0x00 };" >> $@.c
$(QUIET)$(CC) $(CFLAGS) -c $@.c -o $@
-include $(wildcard $(BUILDDIR)/*.d)