-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakefile
61 lines (47 loc) · 1.15 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
CC = gcc
CFLAG = -I ./include -Wall -Wextra -Wno-unused-value -g
CMD = $(CC) $(CFLAG)
OUT = build
SRC = $(wildcard ./src/*.c)
_OBJ = $(subst ./src/,$(OUT)/objects/,$(SRC))
OBJ = $(_OBJ:.c=.o)
DIR_GUARD=mkdir -p $(@D)
# mingw in windows
ifeq ($(OS),Windows_NT)
CC = cl
DIR_GUARD=powershell New-Item -ItemType Directory -Force -Path $(@D)
else
endif
all: $(OBJ)
$(DIR_GUARD)
$(info creating shared object)
$(CMD) -shared -o $(OUT)/libcpy.so $(OBJ)
$(info creating static library)
ar rcs $(OUT)/libcpy.a $(OBJ)
$(OUT)/objects/%.o: ./src/%.c
$(DIR_GUARD)
$(info compiling $^)
$(CMD) -c -fpic -o $@ $^
script: all
ifeq ($(file),)
$(info script file is empty)
exit 1
endif
ifeq ($(link),shared)
$(info compiling script dynamically)
$(CMD) -fsanitize=address -L $(OUT) -o $(OUT)/a.out $(file) -lcpy
else ifeq ($(link),static)
$(info compiling script statically)
$(CMD) -static -L $(OUT) -o $(OUT)/a.out $(file) -lcpy
endif
$(info running script)
LD_LIBRARY_PATH=$(OUT) $(OUT)/a.out
clean:
@rm $(OBJ)
@rm $(OUT)/libcpy.a
@rm $(OUT)/libcpy.so
@rm -f $(OUT)/a.out
@rmdir $(OUT)/objects
@rmdir $(OUT)
$(info removed all compiled outputs)
.PHONY: clean