-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
133 lines (107 loc) · 4.27 KB
/
Makefile
File metadata and controls
133 lines (107 loc) · 4.27 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
# ============================================================================
# AstroScript Compiler Build System
# ----------------------------------------------------------------------------
# This Makefile formalizes the same pipeline implemented by:
# - scripts/build_compiler.sh
# - scripts/build_compiler.ps1
#
# Build stages:
# 1) Generate lexer with Flex
# 2) Generate parser with Bison
# 3) Compile compiler binary with g++ (C++17)
# 4) Sync platform binary into web/src/server/compiler
# ============================================================================
# Detect OS for platform-specific commands
ifeq ($(OS),Windows_NT)
RM := del /F /Q
CP := copy_binary.bat
MKDIR := mkdir
CHMOD := @rem
else
RM := rm -f
CP := cp
MKDIR := mkdir -p
CHMOD := chmod +x
endif
# Toolchain
FLEX ?= flex
BISON ?= bison
CXX ?= g++
OBJDUMP ?= objdump
# Some Windows GNU Make distributions set a cross-compiler as built-in CXX.
# Prefer local MinGW g++ unless the user explicitly overrides CXX.
ifeq ($(origin CXX), default)
CXX := g++
endif
# Paths
COMPILER_DIR := backend/compiler
BUILD_DIR := $(COMPILER_DIR)/build
SERVER_COMPILER_DIR := web/src/server/compiler
# Grammar sources
LEXER_SRC := $(COMPILER_DIR)/lexer/lexer.l
PARSER_SRC := $(COMPILER_DIR)/parser/parser.y
# Generated files
LEXER_OUT := $(BUILD_DIR)/lex.yy.c
PARSER_OUT := $(BUILD_DIR)/parser.tab.c
PARSER_HDR := $(BUILD_DIR)/parser.tab.h
# Compiler sources
CPP_SRCS := \
$(COMPILER_DIR)/semantic/symbol_table.cpp \
$(COMPILER_DIR)/ir/tac.cpp \
$(COMPILER_DIR)/main.cpp
# Binaries
LINUX_BINARY := $(BUILD_DIR)/astroscript
WINDOWS_BINARY := $(BUILD_DIR)/astroscript.exe
SYNCED_LINUX_BINARY := $(SERVER_COMPILER_DIR)/astroscript-linux
SYNCED_WINDOWS_BINARY := $(SERVER_COMPILER_DIR)/astroscript-windows.exe
CXX_STD := -std=c++17
INCLUDES := -I$(COMPILER_DIR) -I$(BUILD_DIR)
.NOTPARALLEL:
.PHONY: help all linux windows check-glibc sync-linux sync-windows clean clean-generated
help:
@echo "AstroScript Makefile targets:"
@echo " make linux Build Linux binary and sync to web server path"
@echo " make windows Build Windows binary and sync to web server path"
@echo " make all Build both Linux and Windows variants"
@echo " make clean Remove generated lexer/parser and binaries"
all: linux windows
$(BUILD_DIR):
@$(MKDIR) $(BUILD_DIR)
$(SERVER_COMPILER_DIR):
@$(MKDIR) $(SERVER_COMPILER_DIR)
$(LEXER_OUT): $(LEXER_SRC) | $(BUILD_DIR)
@echo "==> Running Flex (lexer)..."
$(FLEX) -o$(LEXER_OUT) $(LEXER_SRC)
$(PARSER_OUT) $(PARSER_HDR): $(PARSER_SRC) | $(BUILD_DIR)
@echo "==> Running Bison (parser)..."
$(BISON) -d -o$(PARSER_OUT) $(PARSER_SRC)
$(LINUX_BINARY): $(LEXER_OUT) $(PARSER_OUT) $(PARSER_HDR) $(CPP_SRCS) | $(SERVER_COMPILER_DIR)
@echo "==> Compiling AstroScript compiler (Linux target)..."
$(CXX) $(LEXER_OUT) $(PARSER_OUT) $(CPP_SRCS) $(INCLUDES) $(CXX_STD) -o $(LINUX_BINARY)
check-glibc: $(LINUX_BINARY)
@if command -v $(OBJDUMP) >/dev/null 2>&1; then \
if $(OBJDUMP) -T $(LINUX_BINARY) | grep -qE '\(GLIBC_2\.(3[8-9]|[4-9][0-9])\)'; then \
echo "ERROR: Linux binary requires GLIBC >= 2.38 and is not Vercel-compatible."; \
echo "Rebuild on an older Linux baseline or update toolchain settings before deployment."; \
exit 1; \
fi; \
fi
sync-linux: $(LINUX_BINARY) | $(SERVER_COMPILER_DIR)
@$(CP) $(LINUX_BINARY) $(SYNCED_LINUX_BINARY)
@$(CHMOD) $(SYNCED_LINUX_BINARY)
linux: $(LINUX_BINARY) check-glibc sync-linux
@echo "==> Build complete: $(LINUX_BINARY)"
@echo "==> Synced Linux binary to: $(SYNCED_LINUX_BINARY)"
$(WINDOWS_BINARY): $(LEXER_OUT) $(PARSER_OUT) $(PARSER_HDR) $(CPP_SRCS) | $(SERVER_COMPILER_DIR)
@echo "==> Compiling AstroScript compiler (Windows target)..."
$(CXX) $(LEXER_OUT) $(PARSER_OUT) $(CPP_SRCS) $(INCLUDES) $(CXX_STD) -o $(WINDOWS_BINARY)
sync-windows: $(WINDOWS_BINARY) | $(SERVER_COMPILER_DIR)
@$(CP) $(WINDOWS_BINARY) $(SYNCED_WINDOWS_BINARY)
windows: $(WINDOWS_BINARY) sync-windows
@echo "==> Build complete: $(WINDOWS_BINARY)"
@echo "==> Synced Windows binary to: $(SYNCED_WINDOWS_BINARY)"
clean-generated:
@$(RM) $(LEXER_OUT) $(PARSER_OUT) $(PARSER_HDR)
clean: clean-generated
@$(RM) $(LINUX_BINARY) $(WINDOWS_BINARY) $(SYNCED_LINUX_BINARY) $(SYNCED_WINDOWS_BINARY)
@echo "==> Cleaned generated files and binaries"