configure (9959B) download
1#!/bin/bash
2
3ENABLED=
4MK_BINARIES='ZZZ chpst envuidgid finit fsvc fsvs halt init modules-load pgrphack poweroff reboot seedrng setlock setuidgid shutdown sigremap softlimit vlogger zzz'
5
6MK_INSTALL_PREFIX=/
7MK_INSTALL_SBIN=/sbin
8MK_INSTALL_SHARE=/usr/share
9MK_INSTALL_MAN8=/usr/share/man/man8
10MK_INSTALL_DOCS=/usr/share/doc/fiss
11MK_INSTALL_ETC=/etc
12
13# Compiler Options
14MK_CC=${CC:-gcc}
15MK_CFLAGS=${CFLAGS:--g -Wall -Wextra -Wpedantic -Wno-gnu-zero-variadic-macro-arguments}
16MK_LDFLAGS=${LDFLAGS:--fPIE}
17
18# Utilities
19MK_SED=sed
20MK_PYTHON=python3
21MK_AWK=awk
22MK_MAKE_DOCS='tools/make-docs.py'
23MK_MAKE_MAN='tools/make-man.py'
24
25MK_VERBOSE=
26
27H_STOP_TIMEOUT=5 # seconds
28H_NAME_MAX=128 # chars
29H_FAIL_MAX=32 # times
30H_SERVICE_MAX=128 # services
31H_BOOT_SERVICE="boot"
32H_CHECK_INTERVAL=3 # seconds
33H_PARAM_FILE_LINE_MAX=1024 # bytes
34H_ENV_FILE_LINE_MAX=1024 # bytes
35H_RESCUE_SHELL="/bin/bash"
36H_DEPENDENCY_MAX=128 # times
37H_ARGUMENTS_MAX=16 # lines
38H_ENV_MAX=16 # lines
39H_LOG_DIR="/var/log/fiss"
40H_USER_BUFFER=256 # chars
41H_USER_GROUP_MAX=32 # groups
42H_VLOGGER_BUFFER=1024
43H_STATUS_WAIT=5 # seconds
44
45
46enable() {
47 if [ -z "$ENABLED" ]; then
48 ENABLED=y
49 MK_BINARIES=
50 fi
51 MK_BINARIES="$MK_BINARIES $1"
52}
53
54print_help() {
55 cat <<EOF
56./configure sets the compilation environment with given arguments
57 and run some requirement-tests
58
59Usage: ./configure [options]
60
61--verbose ............... enables verbose command printing in make
62
63--using-cc .............. sets the C-compiler (default: \$CC or gcc)
64--using-sed ............. sets the sed-preprocessor (default: sed)
65--using-python .......... sets the python-interpreter (default: python3)
66--using-awk ............. sets the awk-interpreter (default: awk)
67--using-mkdocs .......... sets the docs generator (default: tools/mk-docs.py)
68--using-mkman ........... sets the man generator (default: tools/mk-man.py)
69
70--cflags ................ sets the C flags (default: \$CFLAGS or '-Wall -Wextra -Wpendantic -g')
71--ldflags ............... sets the linker flags (default: \$LDFLAGS)
72
73--prefix ................ sets the root-prefix (default: /)
74--install-bin ........... sets the binary-destination (default: /sbin)
75--install-etc ........... sets the config-destination (default: /etc)
76--install-share ......... sets the share-destination (default: /usr/share)
77--install-man ........... sets the man8-destination (default: /usr/share/man/man8)
78--install-docs .......... sets the docs-destination (default: /usr/share/doc)
79
80--disable-install-bin ... disabling installing binary
81--disable-install-etc ... disabling installing config
82--disable-install-share . disabling installing share
83--disable-install-man ... disabling installing man8
84--disable-install-docs .. disabling installing docs
85
86--enable-ZZZ ............ enable ZZZ
87--enable-chpst .......... enable chpst
88--enable-envuidgid ...... enable envuidgid
89--enable-finit .......... enable finit
90--enable-fsvc ........... enable fsvc
91--enable-fsvs ........... enable fsvs
92--enable-halt ........... enable halt
93--enable-init ........... enable init
94--enable-modules-load ... enable modules-load
95--enable-pgrphack ....... enable pgrphack
96--enable-poweroff ....... enable poweroff
97--enable-reboot ......... enable reboot
98--enable-seedrng ........ enable seedrng
99--enable-setlock ........ enable setlock
100--enable-setuidgid ...... enable setuidgid
101--enable-shutdown ....... enable shutdown
102--enable-sigremap ....... enable sigremap
103--enable-softlimit ...... enable softlimit
104--enable-vlogger ........ enable vlogger
105--enable-zzz ............ enable zzz
106
107--stop-timeout .......... sets the timeout whenever service must be killed
108--fail-limit ............ sets the limit a service may failed before it is declared as dead
109--service-name-limit .... sets the limit of a service name
110--service-limit ......... sets the limit of services
111--default-runlevel ...... sets the default runlevel started by finit
112--check-interval ........ sets the interval services are read and checked
113--total-depends-limit ... sets the limit of total dependencies
114--log-directory ......... sets the default log directory (default: /var/log/fiss)
115--default-fsvc-timeout .. sets the timeout fsvc is wating for status update (default: 5)
116--vlogger-buffer ........ sets the buffer vlogger is using (1024 bytes)
117--param-line-limit ...... sets the limit of a line in ./param
118--param-limit ........... sets the limit of lines in ./params
119--env-line-limit ........ sets the limit of a line in ./env
120--env-limit ............. sets the limit of lines in ./env
121--user-file-limit ....... sets the limit of characters in ./user
122--group-limit ........... sets the limit of groups in ./user
123
124--help .................. prints this and exits
125EOF
126
127 exit $1
128}
129
130panic() {
131 echo "error:" $@
132 exit 1
133}
134
135while [ -n "$1" ]; do
136 case $1 in
137 --using-cc) MK_CC=$2; shift 2;;
138 --using-sed) MK_SED=$2; shift 2;;
139 --using-python) MK_SED=$2; shift 2;;
140 --using-awk) MK_AWK=$2; shift 2;;
141 --using-mkdocs) MK_MAKE_DOCS=$2; shift 2;;
142 --using-mkman) MK_MAKE_MAN=$2; shift 2;;
143
144 --verbose) MK_VERBOSE=y; shift;;
145 --cflags) MK_CFLAGS=$2; shift 2;;
146 --ldflags) MK_LDFLAGS=$2; shift 2;;
147 --prefix) MK_INSTALL_PREFIX=$2; shift 2;;
148
149 --install-bin) MK_INSTALL_SBIN=$2; shift 2;;
150 --install-etc) MK_INSTALL_ETC=$2; shift 2;;
151 --install-share) MK_INSTALL_SHARE=$2; shift 2;;
152 --install-man) MK_INSTALL_MAN8=$2; shift 2;;
153 --install-docs) MK_INSTALL_DOCS=$2; shift 2;;
154
155 --disable-install-bin) MK_INSTALL_SBIN=; shift;;
156 --disable-install-etc) MK_INSTALL_ETC=; shift;;
157 --disable-install-share) MK_INSTALL_SHARE=; shift;;
158 --disable-install-man) MK_INSTALL_MAN8=; shift;;
159 --disable-install-docs) MK_INSTALL_DOCS=; shift;;
160
161 --enable-ZZZ) enable ZZZ; shift;;
162 --enable-chpst) enable chpst; shift;;
163 --enable-envuidgid) enable envuidgid; shift;;
164 --enable-finit) enable finit; shift;;
165 --enable-fsvc) enable fsvc; shift;;
166 --enable-fsvs) enable fsvs; shift;;
167 --enable-halt) enable halt; shift;;
168 --enable-init) enable init; shift;;
169 --enable-modules-load) enable modules-load; shift;;
170 --enable-pgrphack) enable pgrphack; shift;;
171 --enable-poweroff) enable poweroff; shift;;
172 --enable-reboot) enable reboot; shift;;
173 --enable-seedrng) enable seedrng; shift;;
174 --enable-setlock) enable setlock; shift;;
175 --enable-setuidgid) enable setuidgid; shift;;
176 --enable-shutdown) enable shutdown; shift;;
177 --enable-sigremap) enable sigremap; shift;;
178 --enable-softlimit) enable softlimit; shift;;
179 --enable-vlogger) enable vlogger; shift;;
180 --enable-zzz) enable zzz; shift;;
181
182 --stop-timeout) H_STOP_TIMEOUT=$2; shift 2;;
183 --fail-limit) H_FAIL_MAX=$2; shift 2;;
184 --service-name-limit) H_NAME_MAX=$2; shift 2;;
185 --service-limit) H_SERVICE_MAX=$2; shift 2;;
186 --boot-service) H_BOOT_SERVICE=$2; shift 2;;
187 --check-interval) H_CHECK_INTERVAL=$2; shift 2;;
188 --rescure-shell) H_RESCUE_SHELL=$2; shift 2;;
189 --total-depends-limit) H_DEPENDENCY_MAX=$2; shift 2;;
190 --log-directory) H_LOG_DIR=$2; shift 2;;
191 --default-fsvc-timeout) H_STATUS_WAIT=$2; shift 2;;
192 --vlogger-buffer) H_VLOGGER_BUFFER=$2; shift 2;;
193 --param-line-limit) H_PARAM_FILE_LINE_MAX=$2; shift 2;;
194 --env-line-limit) H_ENV_FILE_LINE_MAX=$2; shift 2;;
195 --param-limit) H_ARGUMENTS_MAX=$2; shift 2;;
196 --env-limit) H_ENV_MAX=$2; shift 2;;
197 --user-file-limit) H_USER_BUFFER=$2; shift 2;;
198 --group-limit) H_USER_GROUP_MAX=$2; shift 2;;
199
200 --help) print_help 0;;
201 *) echo "error: unknown option '$1'"; print_help 1;;
202 esac
203done
204
205command -v $MK_CC 2>&1 > /dev/null || panic "$MK_CC is not a valid executable"
206command -v $MK_SED 2>&1 > /dev/null || panic "$MK_SED is not a valid executable"
207command -v $MK_PYTHON 2>&1 > /dev/null || panic "$MK_PYTHON is not a valid executable"
208command -v $MK_AWK 2>&1 > /dev/null || panic "$MK_AWK is not a valid executable"
209[ -r $MK_MAKE_DOCS ] || panic "$MK_MAKE_DOCS is not found"
210[ -r $MK_MAKE_MAN ] || panic "$MK_MAKE_MAN is not found"
211
212H_SERVICE_DIR="$MK_INSTALL_ETC/service.d"
213H_START_EXEC="$MK_INSTALL_SHARE/fiss/start"
214H_STOP_EXEC="$MK_INSTALL_SHARE/fiss/stop"
215H_SUSPEND_EXEC="$MK_INSTALL_SHARE/fiss/suspend"
216H_RESUME_EXEC="$MK_INSTALL_SHARE/fiss/resume"
217
218cat > config.mk <<EOF
219BINARIES := $MK_BINARIES
220INSTALL_PREFIX := $MK_INSTALL_PREFIX
221INSTALL_SBIN := $MK_INSTALL_SBIN
222INSTALL_SHARE := $MK_INSTALL_SHARE
223INSTALL_MAN8 := $MK_INSTALL_MAN8
224INSTALL_DOCS := $MK_INSTALL_DOCS
225INSTALL_ETC := $MK_INSTALL_ETC
226
227CC := $MK_CC
228CFLAGS := $MK_CFLAGS
229LDFLAGS := $MK_LDFLAGS
230
231SED := $MK_SED
232PYTHON := $MK_PYTHON
233AWK := $MK_AWK
234MAKE_DOCS := $MK_MAKE_DOCS
235MAKE_MAN := $MK_MAKE_MAN
236
237VERBOSE := $MK_VERBOSE
238EOF
239
240cat > config.h <<EOF
241// generated by ./configure
242
243#pragma once
244
245#define SV_STOP_TIMEOUT $H_STOP_TIMEOUT
246#define SV_NAME_MAX $H_NAME_MAX
247#define SV_FAIL_MAX $H_FAIL_MAX
248#define SV_SERVICE_MAX $H_SERVICE_MAX
249#define SV_CHECK_INTERVAL $H_CHECK_INTERVAL
250#define SV_PARAM_FILE_LINE_MAX $H_PARAM_FILE_LINE_MAX
251#define SV_ENV_FILE_LINE_MAX $H_ENV_FILE_LINE_MAX
252#define SV_DEPENDENCY_MAX $H_DEPENDENCY_MAX
253#define SV_ARGUMENTS_MAX $H_ARGUMENTS_MAX
254#define SV_ENV_MAX $H_ENV_MAX
255#define SV_USER_BUFFER $H_USER_BUFFER
256#define SV_USER_GROUP_MAX $H_USER_GROUP_MAX
257#define SV_VLOGGER_BUFFER $H_VLOGGER_BUFFER
258#define SV_STATUS_WAIT $H_STATUS_WAIT
259#define SV_BOOT_SERVICE "$H_BOOT_SERVICE"
260#define SV_LOG_DIR "$H_LOG_DIR"
261#define SV_RESCUE_SHELL "$H_RESCUE_SHELL"
262#define SV_SERVICE_DIR "$H_SERVICE_DIR"
263#define SV_START_EXEC "$H_START_EXEC"
264#define SV_STOP_EXEC "$H_STOP_EXEC"
265#define SV_SUSPEND_EXEC "$H_SUSPEND_EXEC"
266#define SV_RESUME_EXEC "$H_RESUME_EXEC"
267EOF
268
269echo 'Configuring succeed!'