-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
83 lines (67 loc) · 1.96 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
# libcfg2 Makefile for GCC
MAKEFILE = Makefile
CC = gcc
AR = ar
ARFLAGS = rs
CFLAGS = -c -Wall -std=c89 -pedantic -I./include/
LDFLAGS =
ifneq ($(RELEASE), 1)
CFLAGS += -g
endif
SRCPATH = ./src
OBJPATH = ./obj
SRCFILES = $(wildcard $(SRCPATH)/*.c)
_OBJ = $(patsubst %.c,%.o,$(SRCFILES))
OBJ = $(patsubst $(SRCPATH)/%,$(OBJPATH)/%,$(_OBJ))
OBJ_DYN = $(patsubst %.o,%.dyn.o,$(OBJ))
HEADERS = ./include/cfg2.h ./scr/defines.h
TESTSRC = ./test/test.c
TESTOBJ = ./obj/test.o
LIBNAME = libcfg2
LIBPATH = ./lib
LIBFILE = $(LIBPATH)/$(LIBNAME).a
TESTPATH = ./test
VPATH = $(SRCPATH)
ifeq ($(OS),Windows_NT)
NULLDEVICE = NUL
DLLFILE = ./lib/$(LIBNAME).dll
LIBFILE_DYN = $(DLLFILE).a
TESTEXE = test.exe
DLLLINK = -Wl,--out-implib,$(LIBFILE_DYN)
TESTPATH_EXE = $(TESTPATH)/$(TESTEXE)
else
NULLDEVICE = /dev/null
CFLAGS += -fPIC
DLLFILE = ./lib/$(LIBNAME).so
LIBFILE_DYN =
TESTEXE = ./test
DLLLINK =
TESTPATH_EXE = $(TESTPATH)/$(TESTEXE)
endif
all: $(LIBFILE) $(DLLFILE) $(TESTPATH_EXE)
$(LIBFILE): $(OBJ)
@echo building $(LIBFILE)
@$(AR) $(ARFLAGS) $(LIBFILE) $(OBJ) > $(NULLDEVICE) 2>&1
$(DLLFILE): $(OBJ_DYN)
@echo building $(DLLFILE)
@$(CC) -shared $(OBJ_DYN) -o $(DLLFILE) $(DLLLINK)
$(OBJ): $(TESTSRC) $(MAKEFILE)
$(OBJPATH)/%.o: $(SRCPATH)/%.c
@echo building $@
@$(CC) -c $< $(CFLAGS) -DCFG_LIB_BUILD -DCFG_LIB_STATIC -o $@
$(OBJ_DYN): $(TESTSRC) $(MAKEFILE)
$(OBJPATH)/%.dyn.o: $(SRCPATH)/%.c
@echo building $@
@$(CC) -c $< $(CFLAGS) -DCFG_LIB_BUILD -DCFG_LIB_DYNAMIC -o $@
$(TESTPATH_EXE): $(LIBFILE) $(TESTOBJ)
@echo building $(TESTPATH_EXE)
@$(CC) $(TESTOBJ) -o $(TESTPATH_EXE) -L./lib -static -lcfg2
$(TESTOBJ): $(TESTSRC) $(MAKEFILE)
@echo building $(TESTOBJ)
@$(CC) $(CFLAGS) $(TESTSRC) -DCFG_LIB_STATIC -o $(TESTOBJ)
lib: $(LIBFILE) $(DLLFILE)
test: $(TESTPATH_EXE)
run: $(TESTPATH_EXE)
cd $(TESTPATH) && $(TESTEXE) && cd ..
clean:
rm -f $(OBJ) $(OBJ_DYN) $(LIBFILE) $(LIBFILE_DYN) $(DLLFILE) $(TESTPATH_EXE) $(TESTOBJ)