-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
40 lines (28 loc) · 957 Bytes
/
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
TOOLPREFIX = arm-none-eabi
CC = $(TOOLPREFIX)-gcc
AS = $(TOOLPREFIX)-gcc
LD = $(TOOLPREFIX)-ld
OBJCOPY = $(TOOLPREFIX)-objcopy
CFLAGS = -mcpu=arm1176jzf-s -fpic -ffreestanding -g -O0 -std=gnu99
ASFLAGS = -mcpu=arm1176jzf-s -fpic -ffreestanding -g
SRCS=$(wildcard *.c fatfs/*.c)
OBJS=$(SRCS:.c=.o)
ASMSRCS=$(wildcard *.S)
ASMOBJS=$(ASMSRCS:.S=.o)
libgcc := $(shell $(CC) -print-file-name=libgcc.a)
kernel: $(OBJS) $(ASMOBJS) kernel.ld
$(LD) -T kernel.ld --oformat elf32-littlearm -o kernel.elf $(OBJS) $(ASMOBJS) -L$(dir $(libgcc)) -lgcc
$(OBJCOPY) kernel.elf -O binary kernel.img
clean:
rm -f *.o *.elf *.img */*.o */*.elf */*.img */*.bin */*.hex
USERSRCS=$(wildcard user/*.S)
USERTARGETS=$(USERSRCS:.S=.hex)
user/%.hex: user/%.bin
xxd $^ > $@
user/%.bin: user/%.elf
$(OBJCOPY) -S -O binary $^ $@
user/%.elf: user/%.o
$(LD) -N -e start -Ttext 0 $^ -o $@
user/%.o: user/%.S
$(CC) $(CFLAGS) -nostdinc -I. -c $^ -o $@
user: $(USERTARGETS)