Repository navigation
Expand file tree
/
Copy pathMakefile.bak
More file actions
138 lines (120 loc) · 6.51 KB
/
Copy pathMakefile.bak
File metadata and controls
138 lines (120 loc) · 6.51 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
PROJECT := Machine
CC := gcc
CFLAGS := -D_POSIX_C_SOURCE=200809L -std=c17 -Wall -Wextra -Wpedantic -Werror -O2 -Iinclude
RUNTIME_CFLAGS := $(shell pkg-config --cflags sdl2 SDL2_image 2>/dev/null)
RUNTIME_LIBS := $(shell pkg-config --libs sdl2 SDL2_image 2>/dev/null)
SRC := src/common.c src/util.c src/lexer.c src/parser_expr.c src/parser_stmt.c src/codegen.c src/asm_backend.c
COMPILATION_SRC := Compilation/main.c Compilation/cli.c
OBJ := $(SRC:.c=.o) $(COMPILATION_SRC:.c=.o)
BIN := machine
BUILD_DIR := build
RUNTIME_OBJ := $(BUILD_DIR)/machine_runtime.o
POINTER_RUNTIME_SRC := src/pointer.c
FREESTANDING_RUNTIME_SRC := src/runtime_freestanding.c
FREESTANDING_ENTRY_SRC := src/runtime_freestanding_entry.S
BAREMETAL_RUNTIME_SRC := src/runtime_baremetal.c
BAREMETAL_ENTRY_SRC := src/runtime_baremetal_entry.S
BAREMETAL_LINKER_SRC := src/runtime_baremetal_link.ld
PREFIX ?= /usr/local
BINDIR := $(PREFIX)/bin
LIBDIR := $(PREFIX)/lib/machine
INCDIR := $(PREFIX)/include/machine
DOCDIR := $(PREFIX)/share/doc/machine
EXAMPLESDIR := $(PREFIX)/share/machine/examples
SHARE_VIMDIR := $(PREFIX)/share/vim/vimfiles
MACHINE_VIMDIR := $(PREFIX)/share/machine/vim
DOC_FILES := README.md README.zh-CN.md use_order.md use_order.zh-CN.md user_order.md user_order.zh-CN.md LICENSE
EXAMPLE_FILES := $(wildcard test/*.mne)
.PHONY: help Compilation clean install uninstall test freestanding-demo asm-demo baremetal-demo vim-install verify
help:
@echo "Machine project build targets"
@echo ""
@echo " make Compilation Build ./machine and precompiled runtime object"
@echo " make test Build compiler and test all bundled test sources"
@echo " make install Install compiler, runtimes, Vim files, examples, and docs"
@echo " make freestanding-demo Build test/lowlevel.mne for freestanding-x86_64"
@echo " make asm-demo Build test/lowlevel.mne with x86_64-asm backend"
@echo " make baremetal-demo Build test/baremetal_hello.mne as baremetal ELF"
@echo " make vim-install Install Vim syntax highlighting into ~/.vim"
@echo " make uninstall Remove installed Machine files"
@echo " make clean Remove object files and built outputs"
@echo ""
@echo "Compiler usage:"
@echo " ./machine --help"
@echo " ./machine --version"
@echo " ./machine test/struct.mne -o struct"
Compilation: $(BIN) $(RUNTIME_OBJ)
@echo "Build complete: ./$(BIN)"
$(BIN): $(OBJ)
$(CC) $(CFLAGS) -o $@ $(OBJ)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(RUNTIME_OBJ): src/runtime.c src/pointer.c include/machine_runtime.h | $(BUILD_DIR)
$(CC) $(CFLAGS) $(RUNTIME_CFLAGS) -c src/runtime.c -o $@
src/%.o: src/%.c
$(CC) $(CFLAGS) -c $< -o $@
Compilation/%.o: Compilation/%.c
$(CC) $(CFLAGS) -c $< -o $@
freestanding-demo: $(BIN)
./$(BIN) test/lowlevel.mne -o test/lowlevel.freestanding --target freestanding-x86_64 --unsafe
asm-demo: $(BIN) $(RUNTIME_OBJ)
./$(BIN) test/lowlevel.mne -o test/lowlevel.asm --backend x86_64-asm --unsafe
baremetal-demo: $(BIN)
./$(BIN) test/baremetal_hello.mne -o test/baremetal_hello.elf --backend x86_64-asm --target baremetal-x86_64 --unsafe
vim-install:
install -d $$HOME/.vim/ftdetect $$HOME/.vim/syntax $$HOME/.vim/ftplugin
install -m 0644 vim/ftdetect/machine.vim $$HOME/.vim/ftdetect/machine.vim
install -m 0644 vim/syntax/machine.vim $$HOME/.vim/syntax/machine.vim
install -m 0644 vim/ftplugin/machine.vim $$HOME/.vim/ftplugin/machine.vim
install: $(BIN) $(RUNTIME_OBJ)
install -d $(BINDIR)
install -d $(LIBDIR)
install -d $(INCDIR)
install -d $(DOCDIR)
install -d $(EXAMPLESDIR)
install -d $(MACHINE_VIMDIR)/ftdetect $(MACHINE_VIMDIR)/syntax $(MACHINE_VIMDIR)/ftplugin
install -d $(SHARE_VIMDIR)/ftdetect $(SHARE_VIMDIR)/syntax $(SHARE_VIMDIR)/ftplugin
install -m 0755 $(BIN) $(BINDIR)/$(BIN)
install -m 0644 $(RUNTIME_OBJ) $(LIBDIR)/machine_runtime.o
install -m 0644 include/machine_runtime.h $(INCDIR)/machine_runtime.h
install -m 0644 $(POINTER_RUNTIME_SRC) $(LIBDIR)/machine_pointer.c
install -m 0644 include/machine_runtime_freestanding.h $(INCDIR)/machine_runtime_freestanding.h
install -m 0644 $(FREESTANDING_RUNTIME_SRC) $(LIBDIR)/machine_runtime_freestanding.c
install -m 0644 $(FREESTANDING_ENTRY_SRC) $(LIBDIR)/machine_runtime_freestanding_entry.S
install -m 0644 include/machine_runtime_baremetal.h $(INCDIR)/machine_runtime_baremetal.h
install -m 0644 $(BAREMETAL_RUNTIME_SRC) $(LIBDIR)/machine_runtime_baremetal.c
install -m 0644 $(BAREMETAL_ENTRY_SRC) $(LIBDIR)/machine_runtime_baremetal_entry.S
install -m 0644 $(BAREMETAL_LINKER_SRC) $(LIBDIR)/machine_runtime_baremetal_link.ld
install -m 0644 vim/ftdetect/machine.vim $(MACHINE_VIMDIR)/ftdetect/machine.vim
install -m 0644 vim/syntax/machine.vim $(MACHINE_VIMDIR)/syntax/machine.vim
install -m 0644 vim/ftplugin/machine.vim $(MACHINE_VIMDIR)/ftplugin/machine.vim
install -m 0644 vim/ftdetect/machine.vim $(SHARE_VIMDIR)/ftdetect/machine.vim
install -m 0644 vim/syntax/machine.vim $(SHARE_VIMDIR)/syntax/machine.vim
install -m 0644 vim/ftplugin/machine.vim $(SHARE_VIMDIR)/ftplugin/machine.vim
install -m 0644 $(DOC_FILES) $(DOCDIR)
install -m 0644 $(EXAMPLE_FILES) $(EXAMPLESDIR)
@echo "Installed Machine compiler, runtimes, Vim syntax files, examples, and documentation"
uninstall:
rm -f $(BINDIR)/$(BIN)
rm -f $(LIBDIR)/machine_runtime.o
rm -f $(INCDIR)/machine_runtime.h
rm -f $(LIBDIR)/machine_pointer.c
rm -f $(INCDIR)/machine_runtime_freestanding.h
rm -f $(LIBDIR)/machine_runtime_freestanding.c
rm -f $(LIBDIR)/machine_runtime_freestanding_entry.S
rm -f $(INCDIR)/machine_runtime_baremetal.h
rm -f $(LIBDIR)/machine_runtime_baremetal.c
rm -f $(LIBDIR)/machine_runtime_baremetal_entry.S
rm -f $(LIBDIR)/machine_runtime_baremetal_link.ld
rm -f $(MACHINE_VIMDIR)/ftdetect/machine.vim $(MACHINE_VIMDIR)/syntax/machine.vim $(MACHINE_VIMDIR)/ftplugin/machine.vim
rm -f $(SHARE_VIMDIR)/ftdetect/machine.vim $(SHARE_VIMDIR)/syntax/machine.vim $(SHARE_VIMDIR)/ftplugin/machine.vim
rm -f $(addprefix $(DOCDIR)/,$(DOC_FILES))
rm -f $(addprefix $(EXAMPLESDIR)/,$(notdir $(EXAMPLE_FILES)))
@echo "Removed installed Machine files"
clean:
rm -f $(OBJ) $(BIN)
rm -rf $(BUILD_DIR)
test: $(BIN) $(RUNTIME_OBJ)
@set -e; for src in test/*.mne; do case "$$src" in test/baremetal_hello.mne|test/baremetal_smoke.mne) continue ;; esac; out="$${src%.mne}"; echo "Testing $$src"; ./$(BIN) "$$src" -o "$$out"; "./$$out"; rm -f "$$out"; done
verify: clean Compilation test asm-demo freestanding-demo baremetal-demo
@echo "Verification complete: compiler build, tests, asm, freestanding, and baremetal outputs all succeeded without warnings"