-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
104 lines (70 loc) · 2.46 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
CC = gcc
CFLAGS = -Wall -g -Iinclude -std=c11
BIN = bin/
SRC = lib/src/
LIB = -shared
FILE = DynamicStringAPI.so
# to determine which os
UNAME := $(shell uname)
ifeq ($(UNAME), Linux)
CCFLAGS += -std=gnu11
LIB = -shared
FILE = DynamicStringAPI.so
endif
ifeq ($(UNAME), Darwin)
CCFLAGS += -std=c11
LIB = -dynamiclib
FILE = DynamicStringAPI-Mac.so
endif
# to run you program
program: createSharedLib createProgram runProgram
createProgram:
$(CC) $(CFLAGS) src/*.c lib/$(FILE) -o bin/runProgram -lm
runProgram:
./bin/runProgram
# shared library
lib: createSharedLib createStaticLibrary cleanObject
createSharedLib: $(BIN)DynamicString.o $(BIN)ArrayMap.o $(BIN)Tokenizer.o $(BIN)LinkedList.o
$(CC) $(LIB) -o lib/$(FILE) $(BIN)DynamicString.o $(BIN)ArrayMap.o $(BIN)Tokenizer.o $(BIN)LinkedList.o
$(BIN)DynamicString.o: $(SRC)DynamicString.c
$(CC) $(CFLAGS) -fpic -Iinclude -c $(SRC)DynamicString.c -o $(BIN)DynamicString.o
$(BIN)ArrayMap.o: $(SRC)ArrayMap.c
$(CC) $(CFLAGS) -fpic -Iinclude -c $(SRC)ArrayMap.c -o $(BIN)ArrayMap.o
$(BIN)Tokenizer.o: $(SRC)Tokenizer.c
$(CC) $(CFLAGS) -fpic -Iinclude -c $(SRC)Tokenizer.c -o $(BIN)Tokenizer.o
$(BIN)LinkedList.o: $(SRC)LinkedList.c
$(CC) $(CFLAGS) -fpic -Iinclude -c $(SRC)LinkedList.c -o $(BIN)LinkedList.o
# test command
testing: createStaticLibrary createTest runTest
testingValgrind: createStaticLibrary createTest runTestValgrind
createTest:
$(CC) $(CFLAGS) test/test.c lib/*.a -o bin/runTest -lm
runTestValgrind:
valgrind --leak-check=full ./bin/runTest
runTest:
./bin/runTest
# creating a static library
createStaticLibrary: DynamicString.o Tokenizer.o ArrayMap.o LinkedList.o libraryCreate cleanObject
createObject: DynamicString.o Tokenizer.o ArrayMap.o LinkedList.o
DynamicString.o: lib/src/DynamicString.c
$(CC) $(CFLAGS) -fpic -c lib/src/DynamicString.c -o bin/DynamicString.o
Tokenizer.o: lib/src/Tokenizer.c
$(CC) $(CFLAGS) -fpic -c lib/src/Tokenizer.c -o bin/Tokenizer.o
ArrayMap.o: lib/src/ArrayMap.c
$(CC) $(CFLAGS) -fpic -c lib/src/ArrayMap.c -o bin/ArrayMap.o
LinkedList.o: lib/src/LinkedList.c
$(CC) $(CFLAGS) -fpic -c lib/src/LinkedList.c -o bin/LinkedList.o
libraryCreate:
ar rc lib/DynamicStringAPI.a bin/DynamicString.o bin/Tokenizer.o bin/ArrayMap.o bin/LinkedList.o
#ranlib DynamicStringAPI.a
# --show-leak-kinds=all
# other command
valgrind: createProgram runValgrind
runValgrind:
valgrind --leak-check=full ./bin/runProgram
cleanLibrary:
rm lib/*.a
cleanObject:
rm bin/*.o
clean:
rm bin/*