~remexre/stahl

ref: 2e6a9d7890c8a6c5b59bb79615e66e6b67c61d41 stahl/Makefile -rw-r--r-- 4.0 KiB
2e6a9d78Nathan Ringo Updates mailing list link, fixes[?] MIT license name in readme. 10 months ago
                                                                                
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
TARGET_ARCH?=$(shell uname -m)
DESTDIR?=out
TMPDIR?=tmp
WATCH_TARGET?=help

AARCH64_AS?=$(or $(shell which aarch64-none-elf-as 2>/dev/null),$(CROSS_COMPILE)as)
AARCH64_GDB?=$(or $(shell which aarch64-none-elf-gdb 2>/dev/null),$(CROSS_COMPILE)gdb)
AARCH64_LD?=$(or $(shell which aarch64-none-elf-ld 2>/dev/null),$(CROSS_COMPILE)ld)
AARCH64_OBJCOPY?=$(or $(shell which aarch64-none-elf-objcopy 2>/dev/null),$(CROSS_COMPILE)objcopy)
AARCH64_STRIP?=$(or $(shell which aarch64-none-elf-strip 2>/dev/null),$(CROSS_COMPILE)strip)

ARCHES+=aarch64
ARCHES+=hosted

EXPS+=memtile

all: help
	@exit 1
clean:
ifeq ($(DESTDIR),out)
	[ ! -d out ] || rm -r out
endif
ifeq ($(TMPDIR),tmp)
	[ ! -d tmp ] || rm -r tmp
endif
debug: debug-$(TARGET_ARCH)
docs:
	@$(MAKE) -C doc \
		$(SUBMAKE_FLAGS) \
		DESTDIR=$(abspath $(DESTDIR)/doc) \
		TMPDIR=$(abspath $(TMPDIR)/doc)
emu: emu-$(TARGET_ARCH)
exp: $(patsubst %,exp-%,$(EXPS))
help:
	@echo >&2 'Targets:'
	@echo >&2 '  clean  - Removes temporary and output files'
	@echo >&2 '  debug  - Runs a debugger, typically gdb attached to QEMU'
	@echo >&2 '  docs   - Builds documentation'
	@echo >&2 '  emu    - Runs for TARGET_ARCH, typically in QEMU'
	@echo >&2 '  exp    - Builds experiments (this may not, in general, work)'
	@echo >&2 '  image  - Builds a disk image for TARGET_ARCH'
	@echo >&2 '  kernel - Builds the kernel for TARGET_ARCH'
	@echo >&2 '  lang   - Builds the bootstrapper for the Stahl language'
	@echo >&2 '  watch  - Watches source files, running WATCH_TARGET on changes'
	@echo >&2 ''
	@echo >&2 'Environment Variables:'
	@echo >&2 '  TARGET_ARCH=$(TARGET_ARCH)'
	@echo >&2 '  DESTDIR=$(DESTDIR)'
	@echo >&2 '  TMPDIR=$(TMPDIR)'
	@echo >&2 '  WATCH_TARGET=$(WATCH_TARGET)'
	@echo >&2 ''
	@echo >&2 '  AARCH64_AS=$(AARCH64_AS)'
	@echo >&2 '  AARCH64_GDB=$(AARCH64_GDB)'
	@echo >&2 '  AARCH64_LD=$(AARCH64_LD)'
	@echo >&2 '  AARCH64_OBJCOPY=$(AARCH64_OBJCOPY)'
	@echo >&2 '  AARCH64_STRIP=$(AARCH64_STRIP)'
	@echo >&2 '  AARCH64_QEMU_FLAGS=$(AARCH64_QEMU_FLAGS)'
image: image-$(TARGET_ARCH)
kernel: kernel-$(TARGET_ARCH)
lang:
	@$(MAKE) -C src/compiler-bootstrap install \
		$(SUBMAKE_FLAGS) \
		DESTDIR=$(abspath $(DESTDIR)/lang)
watch:
	watchexec -r -w Makefile -w doc -w exp -w src $(MAKE) $(WATCH_TARGET)
.PHONY: all clean debug docs emu exp help kernel lang watch

# Despite "recursive make considered harmful," we actually want to isolate
# both experiments and each arch's kernel from the rest of the source tree.
# (And furthermore, we want to allow separate compilation of each of these:
# experiments, since they may be arbitrarily broken at any given moment, and
# arches, since the user probably doesn't want all of them.)
SUBMAKE_FLAGS += CALLED_FROM_MAIN_MAKEFILE=1
SUBMAKE_FLAGS += IGNORE_MISSING_PROGRAMS="$(IGNORE_MISSING_PROGRAMS)"
SUBMAKE_FLAGS += AARCH64_AS="$(AARCH64_AS)"
SUBMAKE_FLAGS += AARCH64_GDB="$(AARCH64_GDB)"
SUBMAKE_FLAGS += AARCH64_LD="$(AARCH64_LD)"
SUBMAKE_FLAGS += AARCH64_OBJCOPY="$(AARCH64_OBJCOPY)"
SUBMAKE_FLAGS += AARCH64_STRIP="$(AARCH64_STRIP)"
SUBMAKE_FLAGS += AARCH64_QEMU_FLAGS="$(AARCH64_QEMU_FLAGS)"

define build-exp =
exp-$(1):
	@$(MAKE) -C exp/$(1) \
		$(SUBMAKE_FLAGS) \
		DESTDIR=$(abspath $(DESTDIR)/exp/$(1)) \
		TMPDIR=$(abspath $(TMPDIR)/exp/$(1))
.PHONY: exp-$(1)
endef
$(foreach EXP,$(EXPS),$(eval $(call build-exp,$(EXP))))

define build-arch =
debug-$(1):
	@$(MAKE) -C src/kernel-$(1) debug \
		$(SUBMAKE_FLAGS) \
		DESTDIR=$(abspath $(DESTDIR)/kernel-$(1)) \
		TMPDIR=$(abspath $(TMPDIR)/kernel-$(1))
emu-$(1):
	@$(MAKE) -C src/kernel-$(1) emu \
		$(SUBMAKE_FLAGS) \
		DESTDIR=$(abspath $(DESTDIR)/kernel-$(1)) \
		TMPDIR=$(abspath $(TMPDIR)/kernel-$(1))
image-$(1):
	@$(MAKE) -C src/kernel-$(1) image \
		$(SUBMAKE_FLAGS) \
		DESTDIR=$(abspath $(DESTDIR)/kernel-$(1)) \
		TMPDIR=$(abspath $(TMPDIR)/kernel-$(1))
kernel-$(1):
	@$(MAKE) -C src/kernel-$(1) kernel \
		$(SUBMAKE_FLAGS) \
		DESTDIR=$(abspath $(DESTDIR)/kernel-$(1)) \
		TMPDIR=$(abspath $(TMPDIR)/kernel-$(1))
.PHONY: image-$(1) kernel-$(1)
endef
$(foreach ARCH,$(ARCHES),$(eval $(call build-arch,$(ARCH))))