forked from PKD667/cutils
-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile
51 lines (36 loc) · 932 Bytes
/
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
#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 targetall: directories $(LIBRARY)
all: directories $(LIBRARY)
# Create the necessary directories
directories:
mkdir -p $(OBJ_DIR)
mkdir -p $(BIN_DIR)
# Build the object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c -o $@ $< -D MEMCHECK=$(MEMCHECK)
# Build the library
$(LIBRARY): $(OBJECTS)
ar rcs $(LIBRARY).a $(OBJECTS)
check:
$(CC) $(CFLAGS) -o $(BIN_DIR)/test test.c $(LIBRARY).a -D MEMCHECK=1
bin/test
clean:
rm -f $(OBJ_DIR)/*.o
rm -f $(LIBRARY).a