-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
102 lines (88 loc) · 2.8 KB
/
Makefile
File metadata and controls
102 lines (88 loc) · 2.8 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
CFLAGS ?= -g -std=gnu11 -Wall -Wextra -Werror -Wno-shadow -fsanitize=address -fsanitize=undefined -fstack-protector-all -fno-omit-frame-pointer
LDLIBS ?= -lm
CLANG = clang
GCC_NATIVE = gcc-15
GCC_DOCKER = docker run --rm -v "$(shell pwd)":/src -w /src gcc:15.2.0
compiler ?= $(СС)
RUN_CMD = ./build/main
# Set CC and CFLAGS based on the selected compiler.
ifeq ($(compiler), clang)
CC = $(CLANG)
else ifeq ($(compiler), gcc)
CC = $(GCC_NATIVE)
CFLAGS += -fanalyzer -D_FORTIFY_SOURCE=2
else ifeq ($(compiler), docker)
CC = $(GCC_DOCKER) gcc
CFLAGS += -fanalyzer -D_FORTIFY_SOURCE=2
RUN_CMD = $(GCC_DOCKER) ./build/main
endif
# Preload mimalloc if available.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
MIMALLOC_LIB := $(shell ls /opt/homebrew/lib/libmimalloc.dylib /usr/local/lib/libmimalloc.dylib 2>/dev/null | head -1)
ifneq ($(MIMALLOC_LIB),)
MIMALLOC_PRELOAD := DYLD_INSERT_LIBRARIES=$(MIMALLOC_LIB)
endif
else ifeq ($(UNAME_S),Linux)
MIMALLOC_LIB := $(shell ls /usr/lib/libmimalloc.so /usr/local/lib/libmimalloc.so 2>/dev/null | head -1)
ifneq ($(MIMALLOC_LIB),)
MIMALLOC_PRELOAD := LD_PRELOAD=$(MIMALLOC_LIB)
endif
endif
inspect:
go run ./cmd/inspect -- $(path)
test:
@go test ./so/...
@go test ./internal/...
dist:
@rm -rf dist
@mkdir -p dist/solod/bin
@go build -o dist/solod/bin/so ./cmd/so
@tar -czf dist/solod.tar.gz -C dist solod
@echo "Created dist/solod.tar.gz"
run-cases:
@make run-cases-by pattern="testdata/lang/*/ testdata/std/*/"
run-cases-windows:
@make run-cases-by CFLAGS="-g -std=gnu11 -Wall -Wextra -Werror -Wno-shadow -lm" pattern="testdata/lang/*/"
run-cases-by:
@failed=0; \
for dir in $(pattern); do \
name=$${dir#testdata/}; \
name=$${name%/}; \
if make run-case name=$$name > /tmp/so_test_out.txt 2>&1; then \
echo "PASS $$name"; \
else \
echo "FAIL $$name"; \
cat /tmp/so_test_out.txt; \
failed=1; \
fi; \
done; \
rm -f /tmp/so_test_out.txt; \
if [ $$failed -eq 0 ]; then \
echo "PASS"; \
else \
echo "FAIL"; \
exit 1; \
fi
run-case:
@rm -rf generated/$(name)
@mkdir -p generated/$(name)
@cp testdata/$(name)/dst/*.ext.[ch] generated/$(name)/ 2>/dev/null || true
@go run ./cmd/so translate -o generated/$(name) testdata/$(name)/src
@make run-c path=generated/$(name)
run-example:
@mkdir -p example/$(name)/generated
@rm -rf example/$(name)/generated/*
@go run ./cmd/so translate -o example/$(name)/generated example/$(name)
@rm -rf example/$(name)/generated/so
run-c:
@mkdir -p build
@$(CC) -O1 $(CFLAGS) -I$(path) -o build/main $(shell find $(path) -name "*.c") $(LDLIBS)
@$(RUN_CMD)
@rm -f build/main
.PHONY: bench
bench:
@cd bench/$(name) && go test -bench=.
@CFLAGS="-Ofast -march=native -flto -funroll-loops -DNDEBUG" \
$(MIMALLOC_PRELOAD) \
go run ./cmd/so run ./bench/$(name)