-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
54 lines (37 loc) · 1.18 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
.DEFAULT_GOAL = build
CC = gcc
MAKE = make
SRC_DIR = ./src
INC_DIR = ./h ./mem-pool/include
OBJ_DIR = ./obj
LIB = libmessage_queue.so
STATIC_LIB = libmessage_queue.a
$(OBJ_DIR):
@mkdir -p $@
INC_FLAGS = $(addprefix -I,$(INC_DIR))
CCFLAGS = $(INC_FLAGS)
CCFLAGS += -Wall -Wextra -Werror -Wmissing-prototypes -g -Wshadow -Wundef -Wcast-align -Wunreachable-code -O1 -std=c11
mem_pool = mem-pool/*.o
$(mem_pool):
@cd mem-pool && $(MAKE)
SUBMOD_OBJS = $(mem_pool)
clean_submod:
cd mem-pool && rm -f *.o *.so
@echo sub-module cleaned.
_OBJS = message_queue.o
OBJS = $(patsubst %,$(OBJ_DIR)/%,$(_OBJS))
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)
$(CC) $(CCFLAGS) -fpic -c -o $@ $<
$(LIB) : $(mem_pool) $(OBJS)
$(CC) -shared -fpic -o $@ $^ -lpthread
$(STATIC_LIB) : $(mem_pool) $(OBJS)
ar rcs $@ $^
build: $(LIB) $(STATIC_LIB)
@echo build complete
LDFLAGS = -l:libev.a -l:$(STATIC_LIB)
example : $(STATIC_LIB)
$(CC) $(CCFLAGS) -c -o obj/example.o src/example.c
LIBRARY_PATH=. $(CC) $(CCFLAGS) obj/example.o -o $@ $(LDFLAGS)
clean: clean_submod
rm -rf $(OBJ_DIR)
rm -f $(LIB) $(STATIC_LIB)