-
Notifications
You must be signed in to change notification settings - Fork 11
/
common.mk
110 lines (93 loc) · 3.44 KB
/
common.mk
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
#############################################################################
# File [ common.mk ]
# Author [ littleshamoo ]
# Synopsis [ project layout ]
# Date [ 2010/10/07 created ]
#############################################################################
#############################################################################
# Block [ external header files and libraries ]
# Synopsis [ 'EXTINCLOC': paths of external headers
# 'EXTOPTLIBLOC': paths of external optimized libraries
# 'EXTDBGLIBLOC': paths of external debug libraries
# ]
#############################################################################
EXTINCLOC =
EXTOPTLIBLOC =
EXTDBGLIBLOC =
# directory names
SRCDIR = src
PKGDIR = pkg
LIBDIR = lib
DBGDIR = dbg
OPTDIR = opt
INCDIR = include
BINDIR = bin
# System constant variables
SHELL = /bin/sh
# mode
MODE = opt
# Path for source makefiles
G_PKGDIR = ../../$(PKGDIR)
G_LIBDIR = ../../$(LIBDIR)
G_INCDIR = ../../$(INCDIR)
G_BINDIR = ../../$(BINDIR)
G_DBGDIR = ../../$(LIBDIR)/$(DBGDIR)
G_OPTDIR = ../../$(LIBDIR)/$(OPTDIR)
# C and C++ Sources
CSRCS = $(wildcard $(SRCDIR)/*.cpp) $(wildcard $(SRCDIR)/*.c)
CHDRS = $(wildcard $(SRCDIR)/*.h)
BASECSRCS = $(notdir $(CSRCS))
BASECHDRS = $(notdir $(CHDRS))
CDEPS = $(addsuffix .d, $(basename $(addprefix \
$(LIBDIR)/$(MODE)/, $(BASECSRCS))))
COBJS = $(addsuffix .o, $(basename $(addprefix \
$(LIBDIR)/$(MODE)/, $(BASECSRCS))))
# package libraries
CLIBS = $(wildcard $(LIBDIR)/$(MODE)/*.a) \
$(wildcard $(LIBDIR)/$(MODE)/*.so)
BASECLIBS = $(notdir $(CLIBS))
# lex and yacc
LNYDIR = lex_n_yacc
LSRCS = $(wildcard $(SRCDIR)/*.l)
BASELSRCS = $(notdir $(LSRCS))
LDEPS = $(addsuffix .yy.d, $(basename $(addprefix \
$(LIBDIR)/$(MODE)/$(LNYDIR)/, $(BASELSRCS))))
LSECS = $(addsuffix .yy.cpp, $(basename $(addprefix \
$(LIBDIR)/$(MODE)/$(LNYDIR)/, $(BASELSRCS))))
LOBJS = $(addsuffix .yy.o, $(basename $(addprefix \
$(LIBDIR)/$(MODE)/$(LNYDIR)/, $(BASELSRCS))))
YSRCS = $(wildcard $(SRCDIR)/*.y)
BASEYSRCS = $(notdir $(YSRCS))
BASEYHDRS = $(addsuffix .tab.h, $(basename $(BASEYSRCS)))
YDEPS = $(addsuffix .tab.d, $(basename $(addprefix \
$(LIBDIR)/$(MODE)/$(LNYDIR)/, $(BASEYSRCS))))
YSECS = $(addsuffix .tab.cpp, $(basename $(addprefix \
$(LIBDIR)/$(MODE)/$(LNYDIR)/, $(BASEYSRCS)))) \
$(addsuffix .tab.hpp, $(basename $(addprefix \
$(LIBDIR)/$(MODE)/$(LNYDIR)/, $(BASEYSRCS))))
YOBJS = $(addsuffix .tab.o, $(basename $(addprefix \
$(LIBDIR)/$(MODE)/$(LNYDIR)/, $(BASEYSRCS))))
# Compiler variables
LEX = flex
YACC = bison
CXX = g++ -std=c++11
CC = gcc
OBJS = $(COBJS) $(LOBJS) $(YOBJS)
DEPS = $(CDEPS) $(LDEPS) $(YDEPS)
INCLOC = -I$(SRCDIR) -I$(G_INCDIR) -I$(LIBDIR)/$(MODE)/$(LNYDIR) \
$(addprefix -I,$(EXTINCLOC))
ifeq "$(MODE)" "$(DBGDIR)"
CFLAGS = -Wall -g -D DEBUG
LIBLOC = -L$(G_DBGDIR) $(addprefix -L,$(EXTDBGLIBLOC))
else
CFLAGS = -Wall -O3 -Wno-stringop-truncation -Wno-restrict -Wno-format-overflow
LIBLOC = -L$(G_OPTDIR) $(addprefix -L,$(EXTOPTLIBLOC))
endif
# Archive variables
AR = ar
ARFLAGS = cr
# Self-defined functions
reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)), $(1)))) \
$(firstword $(1))
finddep = $(if $(word 1, $(1)), $(word 1, $(1)) $(call finddep, \
$(wordlist 2, $(words $(1)), $(1)) $($(word 1, $(1))_DEP)), )