-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
104 lines (85 loc) · 2.76 KB
/
Makefile
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
DIR := $(shell pwd)
GCC := $(shell which gcc)
DEFAULT_CC = $(CC)
CFLAGS = -g -Ofast -I$(DIR)/internal/obj/libffi/include
LDFLAGS = -L$(DIR)/internal/obj/libffi/lib $(DIR)/internal/obj/libffi/lib/libffi.a -lm
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
ACLOCAL_PATH := /usr/share/aclocal
INSTALL_PATH := /usr/bin
endif
ifeq ($(UNAME_S),Darwin)
ACLOCAL_PATH := /usr/local/share/aclocal
INSTALL_PATH := /usr/local/bin
GCC := $(shell which gcc-14)
endif
# Check if CC is defined
ifneq ($(origin CC), undefined)
# Check if CC is not clang
ifneq ($(CC), clang)
# Check if the compiler is actually GCC by looking for "GCC" in the version output
GCC_CHECK := $(shell $(CC) --version 2>/dev/null | head -n 1 | grep -i "gcc")
ifneq ($(GCC_CHECK),)
CFLAGS += -fopenmp
LDFLAGS += -fopenmp
endif
endif
endif
# Default compiler fallback to GCC if GCC environment variable is set
ifneq ($(GCC),)
CC = $(GCC)
endif
.PHONY: all tau libffi install profile run
all: libffi tau
libffi:
if [ ! -d libffi ] || [ $$(ls -1q libffi | wc -l) -eq 0 ]; then \
git submodule init; \
git submodule update --recursive; \
fi
CC=$(CC) cd libffi && \
ACLOCAL_PATH=$(ACLOCAL_PATH) autoreconf -i && \
./configure --prefix=$(DIR)/internal/obj/libffi --disable-shared --enable-static --disable-multi-os-directory && \
make install CC=$(CC)
libffi-windows:
if [ ! -d libffi ] || [ $$(ls -1q libffi | wc -l) -eq 0 ]; then \
git submodule init; \
git submodule update --recursive; \
fi
CC=$(CC) cd libffi && \
ACLOCAL_PATH=$(ACLOCAL_PATH) autoreconf -i && \
./configure --host=x86_64-w64-mingw32 --prefix=$(DIR)/internal/obj/libffi --disable-shared --enable-static --disable-multi-os-directory && \
make install CC=x86_64-w64-mingw32-gcc AR=x86_64-w64-mingw32-ar RANLIB=x86_64-w64-mingw32-ranlib
tau:
cd cmd/tau && \
CC=$(CC) \
CGO_CFLAGS="$(CFLAGS)" \
CGO_LDFLAGS="$(LDFLAGS)" \
go build -o $(DIR)/tau
tau-windows:
cd cmd/tau && \
CC=x86_64-w64-mingw32-gcc \
RANLIB=x86_64-w64-mingw32-ranlib \
CGO_ENABLED=1 \
CGO_CFLAGS="$(CFLAGS)" \
CGO_LDFLAGS="$(LDFLAGS)" \
GOOS=windows \
GOARCH=amd64 \
go build -o $(DIR)/tau.exe
windows: libffi-windows tau-windows
debug:
cd cmd/tau && \
CC=$(CC) CGO_CFLAGS="$(CFLAGS) -DDEBUG" CGO_LDFLAGS="$(LDFLAGS)" go build -o $(DIR)/tau
gc-debug:
cd cmd/tau && \
CC=$(CC) CGO_CFLAGS="$(CFLAGS) -DGC_DEBUG" CGO_LDFLAGS="$(LDFLAGS)" go build -o $(DIR)/tau
install:
mkdir -p ~/.local/bin
mkdir -p ~/.local/lib/tau
cp tau ~/.local/bin/tau
cp -r stdlib/* ~/.local/lib/tau
profile:
CC=$(CC) CGO_CFLAGS="$(CFLAGS)" CGO_LDFLAGS="$(LDFLAGS)" go build profile.go
test:
CC=$(CC) CGO_CFLAGS="$(CFLAGS) -DDEBUG -DGC_DEBUG" CGO_LDFLAGS="$(LDFLAGS)" go test ./...
run: all
./tau