-
Notifications
You must be signed in to change notification settings - Fork 6
/
dreambbs.mk
207 lines (157 loc) · 7.34 KB
/
dreambbs.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
## Common BSD make rules for DreamBBS Project
## Toolchain settings
CC = clang
RANLIB = ranlib
CPROTO = cproto -E"$(CC) -pipe -E" -I$$(SRCROOT)/include
INSTALL = install -o $(BBSUSR)
.if "$(DREAMBBS_MK)" == ""
DREAMBBS_MK := 1
REALSRCROOT ?= $(SRCROOT)
ARCHI != getconf LONG_BIT
OPSYS != uname -o
BUILDTIME != date '+%s'
## To be expanded
CFLAGS_WARN = -Wall -Wpointer-arith -Wcast-qual -Wwrite-strings -Werror=format
CFLAGS_MK = -ggdb3 -O0 -pipe $(CFLAGS_WARN) -I$$(SRCROOT)/include $(CFLAGS_ARCHI) $(CFLAGS_COMPAT)
LDFLAGS_MK = -L$$(SRCROOT)/lib -ldao -lcrypt $(LDFLAGS_ARCHI)
## Tool functions
## Called with $(function$(para1::=arg1)$(para2::=arg2)...)
UNQUOTE = S/^"//:S/"$$//
VALUEIF = "\#ifdef $(conf)$(.newline)$(conf:M*)$(.newline)\#else$(.newline)$(default:M*)$(.newline)\#endif"
DEFVAR = "\#undef $(exconf:M*)$(.newline)\#define $(exconf:M*) $($(exconf:M*):M*)"
DEFCONF = "\#undef $(exconf:M*)$(.newline)\#define $(exconf:M*) $(exvalue:M*)"
GETVAR = [ "$(var:M*:$(UNQUOTE))" ] && echo "$(var:M*:$(UNQUOTE))" || $(else_var)
GETCONFS = echo "" | $(CC) -x c -dM -E -P $(hdr:@v@-imacros "$v"@) - 2>/dev/null
GETVALUE = { echo $(VALUEIF$(conf::= $(conf:M*:$(UNQUOTE)))$(default::= $(default:M*))) | $(CC) -x c -E -P $(hdr:@v@-imacros "$v"@) - | xargs; } 2>/dev/null
EXPORTVAR = echo $(DEFVAR$(exconf::= $(exconf:M*))) >> $(EXPORT_FILE)
EXPORTCONF = echo $(DEFCONF$(exconf::= $(exconf:M*))$(exvalue::= $(exvalue:M*))) >> $(EXPORT_FILE)
# Read variables from the configuration C files
BBSCONF := $(REALSRCROOT)/dreambbs.conf
BBSCONF_ORIGIN := $(REALSRCROOT)/include/config.h
EXPORT_MAPLE := $(REALSRCROOT)/maple/make_export.conf
EXPORT_VERINFO := $(REALSRCROOT)/verinfo_export.conf
!= touch $(EXPORT_MAPLE)
CFLAGS_MK += -imacros "$(EXPORT_VERINFO)"
# User names and group names
BBSUSR != $(GETVAR$(var::= "$(BBSUSR)")$(else_var::= $(GETVALUE$(conf::= "BBSUSR")$(default::= "$(:!id -un!)")$(hdr::= $(BBSCONF_ORIGIN)))))
BBSGROUP != $(GETVAR$(var::= "$(BBSGROUP)")$(else_var::= $(GETVALUE$(conf::= "BBSGROUP")$(default::= "$(:!id -gn!)")$(hdr::= $(BBSCONF_ORIGIN)))))
WWWGROUP != $(GETVAR$(var::= "$(WWWGROUP)")$(else_var::= $(GETVALUE$(conf::= "WWWGROUP")$(default::= "www-data")$(hdr::= $(BBSCONF_ORIGIN)))))
# UIDs and GIDs
ID_DEFAULT = 9999
ID_FALLBACK = 2>/dev/null || echo $(ID_DEFAULT)
BBSUID != $(GETVAR$(var::= "$(BBSUID)")$(else_var::= $(GETVALUE$(conf::= "BBSUID")$(default::= "$(:!id -u $(BBSUSR) $(ID_FALLBACK)!)")$(hdr::= $(BBSCONF)))))
BBSGROUP_GID != getent group $(BBSGROUP) | cut -d: -f3
BBSGROUP_GID != $(GETVAR$(var::= "$(BBSGROUP_GID)")$(else_var::= echo $(ID_DEFAULT)))
BBSGID != $(GETVAR$(var::= "$(BBSGID)")$(else_var::= $(GETVALUE$(conf::= "BBSGID")$(default::= "$(BBSGROUP_GID)")$(hdr::= $(BBSCONF)))))
WWWGROUP_GID != getent group $(WWWGROUP) | cut -d: -f3
WWWGROUP_GID != $(GETVAR$(var::= "$(WWWGROUP_GID)")$(else_var::= echo $(ID_DEFAULT)))
WWWGID != $(GETVAR$(var::= "$(WWWGID)")$(else_var::= $(GETVALUE$(conf::= "WWWGID")$(default::= "$(WWWGROUP_GID)")$(hdr::= $(BBSCONF)))))
## BBS path prefixes and suffixes
BBSVER != $(GETVALUE$(conf::= "BBSVER_SUFFIX")$(default::= "")$(hdr::= $(BBSCONF_ORIGIN)))
BBSUSR_HOME != getent passwd $(BBSUSR) | cut -d: -f6
BBSHOME != $(GETVAR$(var::= "$(BBSHOME)")$(else_var::= $(GETVALUE$(conf::= "BBSHOME")$(default::= "$(BBSUSR_HOME)")$(hdr::= $(BBSCONF)))))
## Numeric local timezone
BBSUTCZONE != $(GETVAR$(var::= "$(BBSUTCZONE)")$(else_var::= $(GETVALUE$(conf::= "BBSUTCZONE")$(default::= "$(:!date +%z!)")$(hdr::= $(BBSCONF)))))
## `mruby-config` executable path for building BBS-Ruby with mruby
MRB_CONFIG_PATH != which mruby-config
MRB_CONFIG != $(GETVAR$(var::= "$(MRB_CONFIG)")$(else_var::= $(GETVALUE$(conf::= "MRB_CONFIG")$(default::= "$(MRB_CONFIG_PATH)")$(hdr::= $(BBSCONF_ORIGIN)))))
## The project root directory of bbs-sshd
BBS_SSHD_ROOT != $(GETVAR$(var::= "$(BBS_SSHD_ROOT)")$(else_var::= $(GETVALUE$(conf::= "BBS_SSHD_ROOT")$(default::= "$(BBSHOME)/bbs-sshd")$(hdr::= $(BBSCONF)))))
# rules ref: PttBBS: mbbsd/Makefile
DEF_LIST != sh -c '$(GETCONFS$(hdr::= $(BBSCONF)))'
DEF_TEST = [ $(DEF_LIST:M$(conf:M*:S/"//g:N")) ] # Balance the quotes
DEF_YES := && echo "YES" || echo ""
USE_PMORE != sh -c '$(DEF_TEST$(conf::= "M3_USE_PMORE")) $(DEF_YES)'
USE_PFTERM != sh -c '$(DEF_TEST$(conf::= "M3_USE_PFTERM")) $(DEF_YES)'
USE_BBSLUA != sh -c '$(DEF_TEST$(conf::= "M3_USE_BBSLUA")) $(DEF_YES)'
USE_BBSRUBY != sh -c '$(DEF_TEST$(conf::= "M3_USE_BBSRUBY")) $(DEF_YES)'
USE_LUAJIT != sh -c '$(DEF_TEST$(conf::= "BBSLUA_USE_LUAJIT")) $(DEF_YES)'
USE_MRUBY != sh -c '$(DEF_TEST$(conf::= "BBSRUBY_USE_MRUBY")) $(DEF_YES)'
# Flags for disabling shared objects
NO_SO_CLI := $("$(NO_SO_CLI)" != "" :? $(NO_SO_CLI) : $(NO_SO:DYES:UNO))
NO_SO_CONF != sh -c '$(DEF_TEST$(conf::= "NO_SO")) $(DEF_YES)'
NO_SO_CONF != $(GETVALUE$(conf::= "NO_SO")$(default::= "0")$(hdr::= $(EXPORT_MAPLE)))
NO_SO = $(NO_SO_CLI:S/NO//g)$(NO_SO_CONF:S/0//g)
CC_HASFLAGS = echo "" | $(CC) -x c -E $(flags:M*) -Werror - >/dev/null 2>&1
# Prevent `-Wformat-overflow=` warnings from halting the compilation
.if $(CC:Mgcc*)
CFLAGS_WARN = -Wno-format-overflow -Wno-error=format-overflow -Wformat-overflow
.endif
.if $(CC:Mclang*)
CFLAGS_WARN += -Wno-invalid-source-encoding
.endif
# Architecture information
MULTIARCH != $(CC) -dumpmachine | sed 's/^\(.*\)-\(.*\)-\(.*\)-\(.*\)$$/\1-\3-\4/'
.if $(ARCHI)=="64"
CFLAGS_ARCHI += -fPIC
.endif
.if $(OPSYS) == "GNU/Linux"
LDFLAGS_ARCHI += -lresolv -ldl -rdynamic
.endif
.if $(OPSYS) == "FreeBSD"
LDFLAGS_ARCHI += -Wl,-export-dynamic
.endif
.if $(NO_SO)
CFLAGS_MAPLE += -DNO_SO
CFLAGS_SO += -DNO_SO
.else
CFLAGS_MAPLE += -DNO_SO=0
CFLAGS_SO += -DNO_SO=0
.endif
.if $(CC:M*++) || $(CC:M*++-*)
CFLAGS_COMPAT += -x c++
.else
CFLAGS_WARN += -Wstrict-prototypes -Werror=incompatible-pointer-types -Werror=int-conversion
# Prevent `-Wincompatible-pointer-types-discards-qualifiers` warnings from halting the compilation
.if $(CC:Mclang*)
CFLAGS_WARN += -Wno-incompatible-pointer-types-discards-qualifiers -Wno-error=incompatible-pointer-types-discards-qualifiers -Wincompatible-pointer-types-discards-qualifiers -Werror=pointer-to-int-cast
.endif
.endif
CC_HAS_W_UNREACHABLE_CODE_AGGRESSIVE != $(CC_HASFLAGS$(flags::= -Wunreachable-code-aggressive)) $(DEF_YES)
.if $(CC_HAS_W_UNREACHABLE_CODE_AGGRESSIVE)
CFLAGS_COMPAT += -Wunreachable-code-aggressive
.else
CFLAGS_COMPAT += -Wunreachable-code
.endif
CC_HAS_F_COLOR_DIAGNOSTICS != $(CC_HASFLAGS$(flags::= -fcolor-diagnostics)) $(DEF_YES)
.if $(CC_HAS_F_COLOR_DIAGNOSTICS)
CFLAGS_COMPAT += -fcolor-diagnostics
.endif
# BBS-Lua & BBS-Ruby make rule definitions
.if $(USE_BBSLUA)
.if $(OPSYS) == "FreeBSD"
LUA_LDFLAGS_ARCHI = -Wl,--no-as-needed
.endif
.if $(USE_LUAJIT)
LUA_PKG_NAME ?= luajit
.else
.if $(OPSYS) == "FreeBSD"
LUA_PKG_NAME ?= lua-5.1
.else
LUA_PKG_NAME ?= lua5.1
.endif
.endif
LUA_CFLAGS != pkg-config --cflags $(LUA_PKG_NAME)
LUA_LDFLAGS != pkg-config --libs $(LUA_PKG_NAME)
.endif
.if $(USE_BBSRUBY)
.if $(OPSYS) == "FreeBSD"
RUBY_LDFLAGS_ARCHI = -Wl,--no-as-needed
.endif
.if $(USE_MRUBY)
MRB_CFLAGS != "$(MRB_CONFIG)" --cflags
MRB_LDFLAGS != "$(MRB_CONFIG)" --ldflags
RUBY_CFLAGS = $(MRB_CFLAGS)
RUBY_LDFLAGS = $(MRB_LDFLAGS) -lmruby -lm
.else
RUBY_CFLAGS != pkg-config --cflags ruby-2.2
RUBY_LDFLAGS != pkg-config --libs ruby-2.2
.endif
.endif
.endif # .ifndef DREAMBBS_MK
## Expand `SRCROOT`
.ifdef SRCROOT
CPROTO := $(CPROTO)
CFLAGS := $(CFLAGS_MK)
LDFLAGS := $(LDFLAGS_MK)
.endif