-
Notifications
You must be signed in to change notification settings - Fork 3
/
makefile
59 lines (43 loc) · 1.03 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
#The target library
LIBRARY = cutils
# The directories containing source files
SRC_DIR = src
# The directory for object files
OBJ_DIR = obj
# The directory for the built binary
BIN_DIR = bin
# The C compiler to use
CC = gcc
# The C flags to use
CFLAGS = -Iinclude -fPIC -g
# The source files
SOURCES = $(wildcard $(SRC_DIR)/*.c)
# The object files
OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
# memory checking
MEMCHECK = 0
# The default target
all: $(LIBRARY)
# Build the library
$(LIBRARY): $(OBJECTS)
ar rcs $(LIBRARY).a $(OBJECTS)
# Build the object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c -o $@ $< -D MEMCHECK=$(MEMCHECK)
bundle:
cat $(SOURCES) > cutils.c
test:
$(CC) -DMEMCHECK=1 $(CFLAGS) -o $(BIN_DIR)/test test.c $(LIBRARY).a
bin/test
test_all:
$(CC) $(CFLAGS) -o $(BIN_DIR)/test_all test.c $(LIBRARY).a
./$(BIN_DIR)/test_all
if [ $$? -eq 0 ]; then \
echo "All tests passed successfully!"; \
else \
echo "Some tests failed."; \
exit 1; \
fi
clean:
rm -f $(OBJ_DIR)/*.o
rm -f $(LIBRARY).a