blob: fe25fa22c07102e29bc17283689cbd29b2d4ffe1 (
plain)
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
|
CC := clang
MAJOR_VERSION := "$(shell git -c safe.directory='*' describe --tags --abbrev=0)"
GIT_COMMIT := "$(shell git -c safe.directory='*' describe --tags --abbrev=0)-$(shell git -c safe.directory='*' describe --always --match 'NOT A TAG')"
version ?= 5.4
install_version = $(version)
ifeq ($(version),jit)
install_version = 5.1
endif
CFLAGS := -D_GNU_SOURCE -Wall -fPIC -DGIT_COMMIT='$(GIT_COMMIT)' -DMAJOR_VERSION='$(MAJOR_VERSION)' `pkg-config --cflags lua$(version)`
LFLAGS := -lm -shared -lcrypto -lssl
LINKER := $(CC)
TARGET := lullaby.so
INSTALL := /usr/local/lib/lua/
DEBUG_CFLAGS := -ggdb3 -fno-omit-frame-pointer -fno-optimize-sibling-calls
RELEASE_FLAGS := -O3
SRCS := $(wildcard src/*.c) $(wildcard src/*/*.c)
OBJS := $(SRCS:.c=.o)
ifeq ($(OS),Windows_NT)
CFLAGS += -I/mingw64/include
LFLAGS += -L/mingw64/bin -llua54 -lws2_32
TARGET := $(TARGET:.so=.dll)
else
CFLAGS += -fPIC
endif
.PHONY: all
all: $(TARGET)
release: CFLAGS += $(RELEASE_FLAGS)
release: all
.PHONY: install
install::
mkdir $(INSTALL)$(install_version) -p
cp $(TARGET) $(INSTALL)$(install_version)/$(TARGET)
# ok so im pretty sure asan should be linked too, however dlclose needs to be masked anyways
# and since libasan needs to be the first thing to load, you'll have to add it anyways
# run with something like 'LD_PRELOAD="/usr/lib/gcc/x86_64-pc-linux-gnu/14/libasan.so ./fakedlclose.so" lua5.4 ...'
# fakedlclose.so should be something as simple as the following:
#
# "
# #include <stdio.h>
# int dlclose(void *handle) {;}
# "
#
# code (& fix) courtesy of
# https://github.com/google/sanitizers/issues/89#issuecomment-406316683
#
# this also requires lua to be built with asan
debug: CFLAGS += $(DEBUG_CFLAGS)
debug: all
san: CFLAGS += -static-libasan -fsanitize=address -fsanitize=undefined $(DEBUG_CFLAGS)
san: all
tsan: CFLAGS += -static-libasan -fsanitize=thread -fsanitize=undefined $(DEBUG_CFLAGS)
tsan: all
reg:
rm src/reg.o
reg: all
%.o: %.c
$(CC) -c $< -o $@ $(CFLAGS)
$(TARGET): $(OBJS)
$(LINKER) $(OBJS) -o $(TARGET) $(LFLAGS)
.PHONY: clean
clean:
rm -f $(OBJS)
|