-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (50 loc) · 1.83 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
# OUTELF and OUTBIN.
OUTELF := tart
OUTBIN := $(OUTELF).bin
CCFLAGS ?= -O2
# Include the config and rules.
include config.mk
include target/$(TARGET)/rules.mk
include platform/$(PLATFORM)/rules.mk
include rules.mk
# List of CFLAGS.
CFLAGS += -std=c99 -Wall -Wextra -nostdlib -ffreestanding -lgcc $(CCFLAGS)
# Includes.
CPPFLAGS := -Iinclude -Ikernel/include -Iarch/$(ARCH)/include -Itarget/$(TARGET)/include -Iplatform/$(PLATFORM)/include
# Get a list of source files.
CSRC := $(shell find arch/$(ARCH) -type f -name "*.c") $(shell find kernel -type f -name "*.c") \
$(shell find target/$(TARGET) -type f -name "*.c") $(shell find platform/$(PLATFORM) -type f -name "*.c")
ASMSRC := $(shell find arch/$(ARCH) -type f -name "*.S") $(shell find kernel -type f -name "*.S") \
$(shell find target/$(TARGET) -type f -name "*.S") $(shell find platform/$(PLATFORM) -type f -name "*.S")
# Get the object files.
OBJ := $(patsubst %.S,%.o,$(ASMSRC)) $(patsubst %.c,%.o,$(CSRC))
# Get the dependancies.
DEP := $(patsubst %.S,%.d,$(ASMSRC)) $(patsubst %.c,%.d,$(CSRC))
# Linker script.
LINK := arch/$(ARCH)/link.ld
# Make related files.
MAKEDEPS := Makefile rules.mk config.mk target/$(TARGET)/rules.mk platform/$(PLATFORM)/rules.mk
# The default target.
all: $(OUTFORMAT)
# List phony targets.
.PHONY: all clean
# ELF output.
$(OUTELF): $(OBJ) $(LINK)
$(HOSTLD) $(OBJ) -T$(LINK) -o $@
# Binary output.
$(OUTBIN): $(OUTELF)
$(HOSTOBJCOPY) $(OUTELF) -O binary $@
# Include dependancy files.
-include $(DEP)
# Clean.
clean:
-$(RM) $(wildcard $(OBJ) $(DEP) $(OUTELF) $(OUTFORMAT))
# Dog.
dog:
$(warning Experimental dog generator. Don't try it out; the default size isn't set, so-)
# CC.
%.o: %.c $(MAKEDEPS)
$(HOSTCC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -c $< -o $@
# AS.
%.o: %.S $(MAKEDEPS)
$(HOSTCC) $(CFLAGS) $(CPPFLAGS) -MMD -MP -c $< -o $@