-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
70 lines (60 loc) · 1.8 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
## application names
TSTCODE := ternary_st
LIBNAME := libternary_st
TESTCPY := tst_test_cpy
TESTREF := tst_test_ref
TESTVAL := tst_validate
## compiler
CC := gcc
CCLD := $(CC)
## output/object/include/source directories
BINDIR := bin
OBJDIR := obj
INCLUDE := include
SRCDIR := src
## compiler and linker flags
CFLAGS := -Wall -Wextra -pedantic -finline-functions -std=c11 -Wshadow
CFLAGS += -I$(INCLUDE)
ifeq ($(debug),-DDEBUG)
CFLAGS += -g
else
CFLAGS += -Ofast
endif
LDFLAGS :=
## libraries
LIBS :=
## source/include/object variables
SOURCES := $(wildcard $(SRCDIR)/tst*.c)
INCLUDES := $(wildcard $(INCLUDE)/*.h)
OBJECTS := $(OBJDIR)/$(TSTCODE).o
all: $(TESTCPY) $(TESTREF) $(TESTVAL) $(LIBNAME)
$(TESTCPY): $(OBJECTS)
@mkdir -p $(@D)/$(BINDIR)
$(CCLD) -o $(BINDIR)/$(TESTCPY) $(SRCDIR)/$(TESTCPY).c $(OBJDIR)/$(TSTCODE).o $(CFLAGS) $(LDFLAGS) $(LIBS)
$(TESTREF): $(OBJECTS)
@mkdir -p $(@D)/$(BINDIR)
$(CCLD) -o $(BINDIR)/$(TESTREF) $(SRCDIR)/$(TESTREF).c $(OBJDIR)/$(TSTCODE).o $(CFLAGS) $(LDFLAGS) $(LIBS)
$(TESTVAL): $(OBJECTS)
@mkdir -p $(@D)/$(BINDIR)
$(CCLD) -o $(BINDIR)/$(TESTVAL) $(SRCDIR)/$(TESTVAL).c $(OBJDIR)/$(TSTCODE).o $(CFLAGS) $(LDFLAGS) $(LIBS)
## strip only if -DDEBUG not set
ifneq ($(debug),-DDEBUG)
strip -s $(BINDIR)/*
endif
$(LIBNAME):
# call shared-object lib makefile
$(MAKE) -f Makefile.lib
## define object file for $(TSTCODE)
$(OBJDIR)/$(TSTCODE).o: $(INCLUDE)/$(TSTCODE).h
## create object dir/compile objects
$(OBJECTS): $(SRCDIR)/$(TSTCODE).c
@mkdir -p $(OBJDIR)
$(CC) $(CFLAGS) -c -o $(OBJDIR)/$(TSTCODE).o $(SRCDIR)/$(TSTCODE).c
## install library
install:
$(MAKE) -f Makefile.lib install
## clean source directory
clean:
if [ -d $(BINDIR) ]; then rm -rf $(BINDIR); fi
if [ -d $(OBJDIR) ]; then rm -rf $(OBJDIR); fi
$(MAKE) -f Makefile.lib clean