-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile.headless
More file actions
168 lines (139 loc) · 5.09 KB
/
Copy pathMakefile.headless
File metadata and controls
168 lines (139 loc) · 5.09 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Makefile for headless (native) build
# Builds a command-line emulator using the system C compiler.
# Supports automatic header dependency tracking via -MMD -MP.
# -- Compiler --
CC ?= gcc
CFLAGS_BASE := -Wall -Wextra -std=c11 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L -MMD -MP
# -- Build mode (release | debug | sanitize | fast) --
MODE ?= release
ifeq ($(MODE),debug)
CFLAGS_MODE := -g -O0 -DDEBUG -DGS_DEBUG
else ifeq ($(MODE),sanitize)
CFLAGS_MODE := -g -O1 -DGS_DEBUG -fsanitize=address,undefined -fno-omit-frame-pointer
LDFLAGS_MODE := -fsanitize=address,undefined
else ifeq ($(MODE),fast)
# Benchmarking profile: GS_ASSERT/invariant walks and libc assert compiled
# out (perf proposal P4). NOT the default — the headless binary is the
# debugging tool and CI runs the assert-enabled build.
CFLAGS_MODE := -O2 -DGS_FAST -DNDEBUG
else
# No -DNDEBUG: keep assertions active in the headless test/debug tool
CFLAGS_MODE := -O2
endif
# -- Directories --
# fast mode builds into its own tree: CFLAGS changes don't retrigger object
# rebuilds, so sharing build/headless would silently mix assert-enabled and
# assert-free objects.
ifeq ($(MODE),fast)
BUILD_DIR := build/headless-fast
else
BUILD_DIR := build/headless
endif
CORE_DIR := src/core
MACHINES_DIR := src/machines
PLATFORM_DIR := src/platform/headless
PEELER_DIR := src/peeler
# -- Include paths --
# Platform headers come first so platform.h overrides are picked up.
INCLUDES := -I$(PLATFORM_DIR) \
-I$(CORE_DIR) \
-I$(CORE_DIR)/cpu \
-I$(CORE_DIR)/memory \
-I$(CORE_DIR)/peripherals \
-I$(CORE_DIR)/peripherals/nubus \
-I$(CORE_DIR)/peripherals/nubus/cards \
-I$(CORE_DIR)/scheduler \
-I$(CORE_DIR)/debug \
-I$(CORE_DIR)/storage \
-I$(CORE_DIR)/network \
-I$(CORE_DIR)/shell \
-I$(CORE_DIR)/object \
-I$(CORE_DIR)/vfs \
-I$(MACHINES_DIR) \
-I$(MACHINES_DIR)/runtime \
-I$(MACHINES_DIR)/mac030 \
-I$(MACHINES_DIR)/glue \
-I$(MACHINES_DIR)/mdu \
-I$(MACHINES_DIR)/oss \
-I$(MACHINES_DIR)/compact \
-I$(MACHINES_DIR)/lisa \
-I$(PEELER_DIR)/include \
-I$(PEELER_DIR)/lib
# -- Source discovery --
# Wildcard patterns auto-discover new .c files in each subdirectory.
# Core emulator sources (platform-agnostic)
CORE_SRC := $(wildcard $(CORE_DIR)/*.c) \
$(wildcard $(CORE_DIR)/cpu/*.c) \
$(wildcard $(CORE_DIR)/memory/*.c) \
$(wildcard $(CORE_DIR)/peripherals/*.c) \
$(wildcard $(CORE_DIR)/peripherals/nubus/*.c) \
$(wildcard $(CORE_DIR)/peripherals/nubus/cards/*.c) \
$(wildcard $(CORE_DIR)/scheduler/*.c) \
$(wildcard $(CORE_DIR)/debug/*.c) \
$(wildcard $(CORE_DIR)/storage/*.c) \
$(wildcard $(CORE_DIR)/network/*.c) \
$(wildcard $(CORE_DIR)/shell/*.c) \
$(wildcard $(CORE_DIR)/object/*.c) \
$(wildcard $(CORE_DIR)/vfs/*.c) \
$(shell find $(MACHINES_DIR) -name '*.c')
# Platform-specific sources
PLATFORM_SRC := $(wildcard $(PLATFORM_DIR)/*.c)
# Peeler library sources
PEELER_SRC := $(PEELER_DIR)/lib/peeler.c \
$(PEELER_DIR)/lib/err.c \
$(PEELER_DIR)/lib/util.c \
$(PEELER_DIR)/lib/formats/bin.c \
$(PEELER_DIR)/lib/formats/cpt.c \
$(PEELER_DIR)/lib/formats/hqx.c \
$(PEELER_DIR)/lib/formats/sit.c \
$(PEELER_DIR)/lib/formats/sit3.c \
$(PEELER_DIR)/lib/formats/sit13.c \
$(PEELER_DIR)/lib/formats/sit15.c
# All sources
SRC := $(CORE_SRC) $(PLATFORM_SRC) $(PEELER_SRC)
# Object and dependency files (mirror source tree under BUILD_DIR)
OBJ := $(patsubst %.c,$(BUILD_DIR)/%.o,$(SRC))
DEP := $(OBJ:.o=.d)
# Output binary
OUTPUT := $(BUILD_DIR)/gs-headless
# -- Combined flags --
CFLAGS := $(CFLAGS_BASE) $(CFLAGS_MODE) $(INCLUDES) $(EXTRA_CFLAGS)
LDFLAGS := $(LDFLAGS_MODE) -lpthread -lm
# -- Targets --
.PHONY: all debug sanitize clean info FORCE
all: $(OUTPUT)
# Compile each .c -> .o with automatic dependency generation
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
# Force-rebuild build_id.o so __DATE__/__TIME__ stay current
FORCE:
$(BUILD_DIR)/$(CORE_DIR)/build_id.o: FORCE
# Link all objects into the headless binary
$(OUTPUT): $(OBJ)
@mkdir -p $(dir $@)
$(CC) $(OBJ) -o $@ $(LDFLAGS)
@echo "Built: $@"
# Include auto-generated header dependency files
-include $(DEP)
# Convenience build-mode shortcuts
debug:
$(MAKE) MODE=debug
sanitize:
$(MAKE) MODE=sanitize
# Clean build artifacts
clean:
rm -rf $(BUILD_DIR)
# Show build configuration
info:
@echo "CC: $(CC)"
@echo "MODE: $(MODE)"
@echo "CFLAGS: $(CFLAGS)"
@echo "LDFLAGS: $(LDFLAGS)"
@echo "OUTPUT: $(OUTPUT)"
@echo ""
@echo "Sources:"
@echo " Core: $(words $(CORE_SRC)) files"
@echo " Platform: $(words $(PLATFORM_SRC)) files"
@echo " Peeler: $(words $(PEELER_SRC)) files"
@echo " Total: $(words $(SRC)) files"