-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
119 lines (89 loc) · 2.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# Choose compiler (currently only gcc) using FLAVOUR= when
# invoking make or get the default of gcc
FLAVOUR ?= gcc
VARIANT = $(FLAVOUR)
SRCDIR = src
OBJDIR = obj_$(FLAVOUR)
LIBDIR = lib
INCDIR = include
EXTINC = ../extension/include
# Support for multiple compiler flags
ifeq (gcc,$(findstring gcc,$(FLAVOUR)))
CC = gcc
CFLAGS_ALL = -I$(INCDIR) -I$(SRCDIR) -I$(EXTINC) -fPIC -g
CFLAGS_OPT = -O3
CFLAGS_DBG = -g -O0 -DSDF_DEBUG_ALL -D_XOPEN_SOURCE=600
CFLAGS_DBG += -Wall -Wextra -Wno-unused-function -pedantic
CFLAGS_DBG += -Wno-unused-parameter -std=c99
CFLAGS_PROF = -p
endif
# utils
ECHO = echo
RM = rm
MKDIR = mkdir
CP = cp
# compiler & archiver
AR = ar
RANLIB = ranlib
# default mode (max. optimization)
mode = opt
CFLAGS = $(CFLAGS_ALL)
# add flags for debugging if requested
ifeq (dbg,$(findstring dbg,$(mode)))
CFLAGS += $(CFLAGS_DBG)
endif
# add flags for profiling if requested
ifeq (pro,$(findstring pro,$(mode)))
CFLAGS += $(CFLAGS_PROF)
endif
# add flags for optimization if requested
ifeq (opt,$(findstring opt,$(mode)))
CFLAGS += $(CFLAGS_OPT)
endif
# objectlist file
include Makefile-objs
# target name
LIB = $(LIBDIR)/libsdfc.a
VPATH = $(SRCDIR):$(OBJDIR):$(LIBDIR):$(INCDIR)
# target
all: $(LIB)
FORCE:
# Not real file targets
.PHONY: Makefile Makefile-objs all clean cleanall help FORCE
.SUFFIXES: .o .c .h
# implicit rules
%.o: %.c
$(CC) -c $(CFLAGS) -o $(OBJDIR)/$@ $<
commit_info.h: FORCE
@cd $(SRCDIR) && sh gen_commit_string.sh . || true
$(LIB): $(OBJS)
$(RM) -f $@
$(AR) -rsu $@ $(addprefix $(OBJDIR)/,$(OBJS))
$(RANLIB) $@
$(LIB2): $(LIB)
$(CP) $(LIB) $(LIB2)
$(OBJS): | $(OBJDIR)
$(OBJDIR):
$(MKDIR) -p $(OBJDIR)
$(LIB): | $(LIBDIR)
$(LIBDIR):
$(MKDIR) -p $(LIBDIR)
# cleanup
clean:
$(RM) -rf $(OBJDIR)
cleanall:
$(RM) -rf obj_* $(LIBDIR) $(SRCDIR)/commit_info.h
# help page
help:
@$(ECHO) "Defined targets:"
@$(ECHO) " all : build targets (default)"
@$(ECHO) " clean : cleanup"
@$(ECHO) "Defined modes:"
@$(ECHO) " opt: enable flags for optimization (default)"
@$(ECHO) " dbg: enable flags for debugging"
@$(ECHO) " pro: enable flags for profiling"
@$(ECHO) "Example:"
@$(ECHO) " type \`make mode=dbg+pro' to enable dbg and pro flags"
# dependencies file
#include Makefile-deps
sdf_control.o: commit_info.h