-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (55 loc) · 1.51 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
# Makefile for cross assembling ARM Assembly programs for RPi
# adapted from other sources by TC Wan <tcwan@usm.my>
# -- Cross tools and flags
XPREFIX=aarch64-linux-gnu-
AS=$(XPREFIX)as
ASFLAGS=-g
LD=$(XPREFIX)ld
LDFLAGS=
CC=$(XPREFIX)gcc
CFLAGS=-g
# -- Specify additional libraries to link with executable
LIBS=
# -- Select Linker
# use $(CC) for mixed Assembly and C projects. The entry point must be 'main'
# use $(LD) for pure Assembly projects. The entry point must be '_start'
#
LINKER=$(CC)
#LINKER=$(LD)
# -- source and include directories
DIR_C=.
DIR_ASM=$(DIR_C)
DIR_HDR=$(DIR_C)
# -- source code suffix
EXT_H=.h
EXT_C=.c
EXT_ASM=.S
# ---------------------------------
# files lists
# ---------------------------------
HEADERS=$(wildcard $(addsuffix /*$(EXT_H), $(DIR_HDR)))
CSOURCE=$(wildcard $(addsuffix /*$(EXT_C), $(DIR_C)))
ASOURCE=$(wildcard $(addsuffix /*$(EXT_ASM), $(DIR_ASM)))
# ---------------------------------
# object and output lists
# ---------------------------------
AOBJS=$(ASOURCE:%.S=%.o)
ALSTS=$(ASOURCE:%.S=%.lst)
COBJS=$(CSOURCE:%.c=%.o)
CLSTS=$(CSOURCE:%.c=%.lst)
TARGET=$(notdir $(shell pwd))
EXEC=$(TARGET).elf
# ---------------------------------
# Build logic
# ---------------------------------
$(CSOURCE) $(ASOURCE): $(HEADERS)
%.o: %.S
$(AS) $(ASFLAGS) -a=$(@:%.o=%.lst) -o $@ $<
%.o: %.c
$(CC) $(CFLAGS) -c $<
$(EXEC): $(AOBJS) $(COBJS)
$(LINKER) $(LDFLAGS) -o $(EXEC) $(AOBJS) $(COBJS) $(LIBS)
all: $(EXEC)
.PHONY: clean
clean:
rm -f $(EXEC) $(AOBJS) $(ALSTS) $(COBJS) $(CLSTS)