-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
62 lines (49 loc) · 1.28 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
# simle makefile used to build csv dynamic | static library
##include Config.mk
ifeq ($(CC),)
CC=gcc
endif
ifeq ($(AR),)
AR=ar
endif
CC_FILES = csv.c
SHARED_DIR = ./shared
STATIC_DIR = ./static
TEST_DIR = ./test
SHARED_OBJ := $(CC_FILES:%.c=$(SHARED_DIR)/%.o)
STATIC_OBJ := $(CC_FILES:%.c=$(STATIC_DIR)/%.o)
SHARED_LIB := $(SHARED_DIR)/csv.so
STATIC_LIB := $(STATIC_DIR)/csv.a
TEST_BIN := $(TEST_DIR)/test
CFLAGS= -O3 -Wall -ansi -pedantic -g
DEFINES = -D_FILE_OFFSET_BITS=64
# make both, shared and static + test
all: make_outdir $(SHARED_LIB) $(STATIC_LIB) $(TEST_BIN) runtest
shared: make_outdir $(SHARED_LIB)
static: make_outdir $(STATIC_LIB)
make_outdir:
$(shell mkdir -p $(SHARED_DIR) $(STATIC_DIR))
# shared library target
$(SHARED_LIB): CFLAGS += -fPIC
$(SHARED_LIB): $(SHARED_OBJ)
$(CC) $^ -shared -o $@
$(STATIC_LIB): $(STATIC_OBJ)
$(AR) rcs $@ $^
# compile test binary
$(TEST_BIN): CFLAGS=-O3 -Wall -pedantic
$(TEST_BIN): test.c
$(CC) $(CFLAGS) $^ $(STATIC_LIB) -lrt -o $@
# all shared objs pass
$(SHARED_DIR)/%.o: %.c
$(CC) $^ $(CFLAGS) -c -o $@
# all static
$(STATIC_DIR)/%.o: %.c
$(CC) $^ $(CFLAGS) -c -o $@
# runtests
runtest:
./test/runtest.sh
# try clean both static and dynamic
clean:
rm -fR $(SHARED_DIR)
rm -fR $(STATIC_DIR)
rm -f $(TEST_BIN) $(TEST_DIR)/*.csv