This repository has been archived by the owner on May 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
executable file
·78 lines (60 loc) · 1.67 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
.PHONY: all clean profile tests
DEBUG = 0
HOST = $(OS)
HOSTCC = $(CC)
LUA = lua5.4
TARGET ?= $(OS)
ifeq ($(DEBUG), 1)
# deep debug
CCFLAGS = -Wall -Wextra -Wunused-macros -Og -DLUA_DEBUG -DLUA_USE_APICHECK -DLUAI_ASSERT
LDFLAGS = -g -fsanitize=undefined # for debugging
else ifeq ($(DEBUG), 2)
# profiling route
CCFLAGS = -Wall -Wextra -Wunused -O1 #-Wc++-compat
LDFLAGS = -g0 -pg -fprofile-arcs # for profiling
else
# release
CCFLAGS = -Wall -Wextra -Wunused -O3
LDFLAGS = -flto -g0 -s
endif
# target platform checks
ifeq ($(TARGET),Windows_NT)
# windows
EXEC = luatest.exe
ifneq ($(OS), $(TARGET))
# unix -> windows case => use mingw compiler
HOSTCC = x86_64-w64-mingw32-cc
endif
else
# unix way
EXEC = luatest
ifneq ($(OS), $(TARGET))
$(error Winows to Unix compilation is not implemented)
endif
endif
all : $(EXEC)
NOPACK = 0
ifeq ($(NOPACK), 0)
lua.c : ./source/*
cd ./source && $(LUA) make.lua
$(EXEC) : lua.c test.c lualib.c
$(HOSTCC) -I. $^ -o $@ $(CCFLAGS) -lm $(LDFLAGS)
else
CCFLAGS += -DLUAI_FUNC='' -I./source -DNOPACK
./build/%.o: ./source/%.c
mkdir -p $(dir $@)
$(HOSTCC) -I. -c $< -o $@ $(CCFLAGS) $(LDFLAGS)
CFILES = $(shell find ./source/ -name '*.c')
OFILES = $(CFILES:./source/%.c=./build/%.o)
$(EXEC) : $(OFILES) test.c
$(HOSTCC) -I. $^ -o $@ $(CCFLAGS) -lm $(LDFLAGS)
endif
callgrind.out: all
cd tests && valgrind --tool=callgrind --collect-systime=nsec --dump-instr=yes --callgrind-out-file=../callgrind.out -v ../luatest ./all.lua
profile: callgrind.out
cd tests && callgrind_annotate ../callgrind.out ../*.c ../*.h > ../profiler.out
gvim ./profiler.out & disown
tests: all
cd tests && ../luatest ./all.lua
clean :
rm -f ./luatest