-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMakefile
More file actions
180 lines (140 loc) · 7.08 KB
/
Copy pathMakefile
File metadata and controls
180 lines (140 loc) · 7.08 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
169
170
171
172
173
174
175
176
177
178
179
180
# Bootstrap build file
VERSION := $(shell if test -f manifest.wake; then sed -n "/publish releaseAs/ s/^[^']*'\([^']*\)'.*/\1/p" manifest.wake; else git describe --tags --dirty --match='v*' | cut -c 2- | tr -d '\n' | sed 's/$$/-bootstrap/'; fi)
CC := cc -std=c11
CXX := c++
CXX_VERSION := -std=c++17
CFLAGS := -Wall -Wno-format-security -O2 -DVERSION=$(VERSION)
LDFLAGS := -lpthread
DESTDIR ?= /usr/local
LOCAL_CFLAGS := -Ivendor -Isrc
FUSE_CFLAGS := $(shell pkg-config --silence-errors --cflags fuse)
CORE_CFLAGS := $(shell pkg-config --silence-errors --cflags sqlite3) \
$(shell pkg-config --silence-errors --cflags gmp) \
$(shell pkg-config --silence-errors --cflags re2) \
$(shell pkg-config --silence-errors --cflags-only-I ncurses)
FUSE_LDFLAGS := $(shell pkg-config --silence-errors --libs fuse || echo -lfuse)
# Detect if -lstdc++fs is needed (GCC < 9)
# On Linux, both GCC and Clang use libstdc++, so check GCC version
FILESYSTEM_LIB := $(shell test "$$(g++ -dumpversion 2>/dev/null | cut -d. -f1)" -lt 9 2>/dev/null && echo -lstdc++fs)
CORE_LDFLAGS := $(shell pkg-config --silence-errors --libs sqlite3 || echo -lsqlite3) \
$(shell pkg-config --silence-errors --libs gmp || echo -lgmp) \
$(shell pkg-config --silence-errors --libs re2 || echo -lre2) \
$(shell pkg-config --silence-errors --libs ncurses tinfo || pkg-config --silence-errors --libs ncurses || echo -lncurses) \
$(FILESYSTEM_LIB)
COMMON_DIRS := src/compat src/util src/json src/wcl
COMMON_C := $(foreach dir,$(COMMON_DIRS),$(wildcard $(dir)/*.c)) \
vendor/whereami/whereami.c
COMMON_CPP := $(foreach dir,$(COMMON_DIRS),$(wildcard $(dir)/*.cpp))
COMMON_OBJS := src/json/jlexer.o \
$(patsubst %.cpp,%.o,$(COMMON_CPP)) $(patsubst %.c,%.o,$(COMMON_C))
# BLAKE3 platform detection
UNAME_M := $(shell uname -m)
# BLAKE3 C files (always compiled)
BLAKE3_C_COMMON := vendor/blake3/blake3.c vendor/blake3/blake3_portable.c vendor/blake3/blake3_dispatch.c
# BLAKE3 platform-specific files and flags
ifeq ($(UNAME_M),x86_64)
# x86_64: Use SSE2/SSE4.1/AVX2/AVX-512 assembly implementations
BLAKE3_ASM := vendor/blake3/blake3_sse2_x86-64_unix.S \
vendor/blake3/blake3_sse41_x86-64_unix.S \
vendor/blake3/blake3_avx2_x86-64_unix.S \
vendor/blake3/blake3_avx512_x86-64_unix.S
BLAKE3_C := $(BLAKE3_C_COMMON)
BLAKE3_CFLAGS :=
else ifeq ($(UNAME_M),aarch64)
# ARM64: Use NEON implementation (requires BLAKE3_USE_NEON=1 for dispatch)
BLAKE3_ASM :=
BLAKE3_C := $(BLAKE3_C_COMMON) vendor/blake3/blake3_neon.c
BLAKE3_CFLAGS := -DBLAKE3_USE_NEON=1
else
# Other platforms: Use portable implementation only
BLAKE3_ASM :=
BLAKE3_C := $(BLAKE3_C_COMMON)
BLAKE3_CFLAGS :=
endif
BLAKE3_ASM_OBJS := $(patsubst %.S,%.o,$(BLAKE3_ASM))
BLAKE3_OBJS := $(patsubst %.c,%.o,$(BLAKE3_C)) $(BLAKE3_ASM_OBJS)
# CAS objects needed by fuse-waked for storing job outputs
CAS_CPP := $(wildcard src/cas/*.cpp)
CAS_OBJS := $(patsubst %.cpp,%.o,$(CAS_CPP)) $(BLAKE3_OBJS)
WAKE_DIRS := $(COMMON_DIRS) src/cas src/dst src/optimizer src/parser src/runtime src/types src/wcl tools/wake
WAKE_C := $(foreach dir,$(WAKE_DIRS),$(wildcard $(dir)/*.c)) \
$(BLAKE3_C) vendor/utf8proc/utf8proc.c \
vendor/siphash/siphash.c vendor/whereami/whereami.c \
vendor/gopt/gopt.c vendor/gopt/gopt-errors.c vendor/gopt/gopt-arg.c
WAKE_CPP := $(foreach dir,$(WAKE_DIRS),$(wildcard $(dir)/*.cpp))
WAKE_OBJS := src/parser/lexer.o src/parser/parser.o src/json/jlexer.o \
$(patsubst %.cpp,%.o,$(WAKE_CPP)) $(patsubst %.c,%.o,$(WAKE_C)) $(BLAKE3_ASM_OBJS)
WAKE_ENV := WAKE_PATH=$(shell dirname $(shell which $(firstword $(CC))))
all: wake.db
$(WAKE_ENV) BOOTSTRAP_WAKE=true ./bin/wake build default
clean:
rm -rf .build/* bin/* lib/wake/* */*.o */*/*.o src/json/jlexer.cpp src/parser/lexer.cpp src/parser/parser.cpp src/parser/parser.h src/version.h wake.db
touch bin/stamp lib/wake/stamp
wake.db: bin/wake bin/wakebox lib/wake/fuse-waked lib/wake/shim-wake lib/wake/wake-hash bin/wake-migrate
test -f $@ || $(WAKE_ENV) ./bin/wake --init .
install: all
$(WAKE_ENV) ./bin/wake install $(DESTDIR)
# Formats all .h and .cpp file under the current directory
# It assumes clang is available on the PATH and will fail otherwise
formatAll:
@clang-format -i --style=file $(shell ./scripts/which_clang_files all)
@bin/wake-format.native-cpp17-release --auto --in-place
# Formats all changed or staged .h or .cpp files
# It assumes clang is available on the PATH and will fail otherwise
format:
# || true is added after the if expression since it resolves with false when false
# and we don't want make to report that as an error
@FILES=$$(./scripts/which_clang_files changed) && \
if [ "$$FILES" ]; then \
clang-format -i --style=file $$FILES; \
fi || true && \
FILES=$$(./scripts/which_wake_files changed) && \
if [ "$$FILES" ]; then \
bin/wake-format.native-cpp17-release -i $$FILES; \
fi || true
test: wake.db
$(WAKE_ENV) ./bin/wake --in test_wake runTests
# We need to bootstrap job-cache to run the tests
unittest: all
$(WAKE_ENV) ./bin/wake --in test_wake runUnitTests
remoteCacheTests: all
$(WAKE_ENV) ./bin/wake -d -x 'testPostgres Unit'
tarball: wake.db
$(WAKE_ENV) ./bin/wake build tarball
vscode: wake.db
$(WAKE_ENV) ./bin/wake vscode
wasm: wake.db
$(WAKE_ENV) ./bin/wake build wasm
static: wake.db
$(WAKE_ENV) ./bin/wake static
bin/wake: $(WAKE_OBJS)
$(CXX) $(CFLAGS) $(CXX_VERSION) -o $@ $^ $(LDFLAGS) $(CORE_LDFLAGS)
bin/wakebox: tools/wakebox/main.cpp src/wakefs/*.cpp vendor/gopt/*.c $(COMMON_OBJS)
$(CXX) $(CFLAGS) $(LOCAL_CFLAGS) $(CXX_VERSION) $^ -o $@ $(LDFLAGS) $(CORE_LDFLAGS)
lib/wake/fuse-waked: tools/fuse-waked/main.cpp $(COMMON_OBJS) $(CAS_OBJS)
$(CXX) $(CFLAGS) $(LOCAL_CFLAGS) $(FUSE_CFLAGS) $(CXX_VERSION) $^ -o $@ $(LDFLAGS) $(CORE_LDFLAGS) $(FUSE_LDFLAGS)
lib/wake/shim-wake: tools/shim-wake/main.o $(COMMON_OBJS) $(CAS_OBJS)
$(CXX) $(CFLAGS) -o $@ $^ $(LOCAL_CFLAGS) $(CXX_VERSION) $(LDFLAGS) $(CORE_LDFLAGS)
lib/wake/wake-hash: tools/wake-hash/main.o $(COMMON_OBJS) $(CAS_OBJS)
$(CXX) $(CFLAGS) -o $@ $^ $(LOCAL_CFLAGS) $(CXX_VERSION) $(LDFLAGS) $(CORE_LDFLAGS)
bin/wake-migrate: tools/wake-migrate/main.o $(COMMON_OBJS)
$(CXX) $(CFLAGS) -o $@ $^ $(LOCAL_CFLAGS) $(CXX_VERSION) $(LDFLAGS) $(CORE_LDFLAGS) -lsqlite3
%.o: %.cpp $(filter-out src/parser/parser.h,$(wildcard */*/*.h)) | src/parser/parser.h
$(CXX) $(CFLAGS) $(LOCAL_CFLAGS) $(CORE_CFLAGS) $(CXX_VERSION) -o $@ -c $<
%.o: %.c $(filter-out src/version.h,$(wildcard */*.h))
$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -o $@ -c $<
# C rule for BLAKE3 files (needs BLAKE3_CFLAGS for NEON on aarch64)
vendor/blake3/%.o: vendor/blake3/%.c
$(CC) $(CFLAGS) $(LOCAL_CFLAGS) $(BLAKE3_CFLAGS) -o $@ -c $<
# Assembly rule for BLAKE3 SIMD implementations
vendor/blake3/%.o: vendor/blake3/%.S
$(CC) $(CFLAGS) -o $@ -c $<
# Rely on wake to recreate this file if re2c is available
%.cpp: %.cpp.gz
gzip -dc $^ > $@.tmp
mv -f $@.tmp $@
%.h: %.h.gz
gzip -dc $^ > $@.tmp
mv -f $@.tmp $@
.PRECIOUS: src/parser/lexer.cpp src/parser/parser.cpp src/parser/parser.h src/json/jlexer.cpp
.SUFFIXES: