-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
85 lines (61 loc) · 1.94 KB
/
Copy pathMakefile
File metadata and controls
85 lines (61 loc) · 1.94 KB
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
# GNUMakefile to compile s2boot modules
ARCH ?= amd64
ifeq ($(ARCH), amd64)
BITS = 64
ARCH_UPSTREAM = x86
else ifeq ($(ARCH), i386)
BITS = 32
ARCH_UPSTREAM = x86
else
$(error Unknown or unsupported architecture '$(ARCH)')
endif
ROOTDIR ?= .
BINDIR ?= bin/$(ARCH)
ROOTS2BOOT ?= s2boot
cc ?= clang
ld ?= ld.lld
S2BOOTSRCDIR = $(ROOTDIR)/$(ROOTS2BOOT)
SRCDIR = .
TMPDIR = $(ROOTDIR)/$(BINDIR)/s2modtmp
DESTDIR = $(ROOTDIR)/$(BINDIR)/s2modules
CCFLAGS = -target $(ARCH)-pc-none-elf -fPIC -m$(BITS) -mno-sse -mno-red-zone -ffreestanding -I$(ROOTDIR)/include -I$(S2BOOTSRCDIR)/include -I$(S2BOOTSRCDIR)/arch/$(ARCH) \
-I$(S2BOOTSRCDIR)/arch -DARCH_$(ARCH) -DARCH_UPSTREAM_$(ARCH_UPSTREAM) -DARCH_NAME=$(ARCH) -DARCH_BITS=$(BITS) -Werror
LDFLAGS = -melf_$(ARCH) -shared
source := $(wildcard $(SRCDIR)/*.c $(SRCDIR)/*/*.c $(SRCDIR)/*/*/*.c)
headers := $(wildcard $(S2BOOTSRCDIR)/*.h $(S2BOOTSRCDIR)/*/*.h $(S2BOOTSRCDIR)/*/*/*.h $(S2BOOTSRCDIR)/*/*/*/*.h $(SRCDIR)/*.h $(SRCDIR)/*/*.h $(SRCDIR)/*/*/*.h \
$(ROOTDIR)/include/*.h $(ROOTDIR)/include/*/*.h)
objects_wdir := $(source:%.c=%.o)
objects := $(objects_wdir:$(SRCDIR)/%=$(TMPDIR)/%)
targets_wdir := $(source:%.c=%.ko)
targets := $(targets_wdir:$(SRCDIR)/%=$(DESTDIR)/%)
all: bindir link
bindir:
ifeq ($(WINDOWS), yes)
@if not exist $(subst /,\,$(TMPDIR)) mkdir $(subst /,\,$(TMPDIR))
@if not exist $(subst /,\,$(DESTDIR)) mkdir $(subst /,\,$(DESTDIR))
else
@mkdir -p $(TMPDIR)
@mkdir -p $(DESTDIR)
endif
link: $(targets)
$(DESTDIR)/%.ko: $(TMPDIR)/%.o
ifeq ($(WINDOWS), yes)
@if not exist $(subst /,\,$(dir $@)) mkdir $(subst /,\,$(dir $@))
else
@mkdir -p $(dir $@)
endif
$(ld) $(LDFLAGS) -o $@ $<
$(TMPDIR)/%.o: $(SRCDIR)/%.c $(headers)
ifeq ($(WINDOWS), yes)
@if not exist $(subst /,\,$(dir $@)) mkdir $(subst /,\,$(dir $@))
else
@mkdir -p $(dir $@)
endif
$(cc) $(CCFLAGS) -I$(dir $<) -c -o $@ $<
.PHONY: clean
clean:
ifeq ($(WINDOWS), yes)
del /s /q $(subst /,\,$(TMPDIR))
else
rm -r $(TMPDIR)
endif