summaryrefslogtreecommitdiff
path: root/confninja.sh
blob: c60bf1c2a1aa30797a564292ed7d61a97aa753a2 (plain)
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
set -eu

cat <<'END'
# File generated by confninja.sh; DO NOT EDIT!

ninja_required_version = 1.11

rule cargo
  command = cd $extractrs_dir && cargo build $rust_mode && cp $rs_bin ../bin
  description = CARGO $out

rule scss
  command = sass --load-path=node_modules/ $scss_mode $in $out
  description = SCSS $out

rule bundle
  command = esbuild --log-level=warning --bundle $bundle_mode --outfile=$out $in
  description = BUNDLE $out

rule instexec
  command = install $in $out
  description = INSTEXEC $out

rule instdata
  command = install -m0644 $in $out
  description = INSTDATA $out

rule perltest
  command = prove -l t/
  description = PERLTEST

rule perlman
  command = pod2man $in >$out
  description = POD2MAN $out

rule configure
  command = ./configure $confargs
  description = CONFIGURE
  generator = 1

build test: perltest extract
END

# CONFIGURE

echo "confargs = $CONFARGS"
echo "build build.ninja lib/JWebmail/Config.pm: configure configure confninja.sh lib/JWebmail/Config.pm.in"

case "$JWM_MODE" in
    (development)
        echo 'bundle_mode = --sourcemap'
        echo 'rs_bin = target/debug/jwebmail-extract'
        ;;
    (production)
        echo 'bundle_mode = --minify'
        echo 'sass_mode = --style=compress --no-source-maps'
        echo 'rust_mode = --profile release-small --target x86_64-unknown-linux-musl -q'
        echo 'rs_bin = target/x86_64-unknown-linux-musl/release-small/jwebmail-extract'
        ;;
esac

# EXTRACTRS

case "$MAILDIR_EXTRACTOR_NAME" in
    (extractrs)
        echo "extractrs_dir = $JWM_EXTRACTRS_DIR"
        echo -n 'build bin/jwebmail-extract: cargo $extractrs_dir/Cargo.toml'
        FILES_RS='arguments.rs cmd.rs error.rs main.rs rfc822.rs cmd/count.rs cmd/folders.rs cmd/list.rs cmd/raw.rs'
        for f in $FILES_RS
        do
            echo -n " \$extractrs_dir/src/$f"
        done
        echo
        echo "build extract: phony bin/jwebmail-extract"
        ;;
    (extractpl) echo "build extract: phony script/extract.pl";;
    (extractpy) echo "build extract: phony script/extract.py";;
esac

# PUBLIC

FILES_JS='src/displayheaders.js src/rendermail.js'
if [ "$LOGIN_SCHEME" = cram_md5 ]
then FILES_JS="$FILES_JS src/login_cram.js"
fi

PUBLIC=
for f in $FILES_JS
do case "$JWM_MODE" in
    (development)
        echo "build public/$f | public/$f.map: bundle $f"
        PUBLIC="$PUBLIC public/$f public/$f.map"
        ;;
    (production)
        echo "build public/$f: bundle $f"
        PUBLIC="$PUBLIC public/$f"
        ;;
esac
done

for f in my_bulma
do case "$JWM_MODE" in
    (development)
        echo "build public/css/$f.css | public/css/$f.css.map: scss scss/$f.scss"
        PUBLIC="$PUBLIC public/css/$f.css public/css/$f.css.map"
        ;;
    (production)
        echo "build public/css/$f.css: scss scss/$f.scss"
        PUBLIC="$PUBLIC public/css/$f.css"
        ;;
esac
done

echo "build public: phony $PUBLIC"

# INSTALL

install_file () { echo "build \$destdir/$2/$4: $1 $3/$4"; ALL_INST="$ALL_INST \$destdir/$2/$4"; }

echo "destdir = $DESTDIR"

echo "prefix = $PREFIX"
echo "bindir = \$prefix/bin"
echo "scriptdir = \$prefix/bin"
echo "perldir = $PERL_PATH"
if [ "$PREFIX" = usr ]
then echo "confdir = \$prefix/../etc"
else echo "confdir = \$prefix/etc"
fi
echo "datadir = \$prefix/share/jwebmail"
echo "docdir = \$prefix/share/doc/jwebmail"
echo "man3dir = \$prefix/share/man/man3"

ALL_INST=

case "$MAILDIR_EXTRACTOR_NAME" in
    (extractrs) install_file instexec \$bindir bin jwebmail-extract;;
    (extractpy) install_file instexec \$scriptdir script extract.py;;
    (extractpl) install_file instexec \$scriptdir script extract.pl;;
esac

install_file instexec \$scriptdir script jwebmail
install_file instexec \$scriptdir script testauthenticator.pl

while read f
do install_file instdata \$perldir lib "$f"
done <<'END'
JWebmail/Controller/Webmail.pm
JWebmail/I18N/de.pm
JWebmail/I18N/en.pm
JWebmail/Model/ReadMails/QMailAuthuser.pm
JWebmail/Model/ReadMails/Role.pm
JWebmail/Model/WriteMails.pm
JWebmail/Plugin/I18N2/INI.pm
JWebmail/Plugin/I18N2/Maketext.pm
JWebmail/Plugin/I18N2/Role.pm
JWebmail/Plugin/I18N2.pm
JWebmail/Plugin/Paginate.pm
JWebmail/Plugin/ServerSideSessionData.pm
JWebmail/Plugin/TOMLConfig.pm
JWebmail/View/RenderMail.pm
JWebmail/View/Webmail.pm
JWebmail/Config.pm
JWebmail/I18N.pm
JWebmail.pm
END

while read f
do
    manname="$(echo -n "${f%.pm}"| sed 's!/!$:$:!g').3perl"
    echo "build \$destdir/\$man3dir/$manname: perlman lib/$f"
    ALL_INST="$ALL_INST \$destdir/\$man3dir/$manname"
done <<'END'
JWebmail/Controller/Webmail.pm
JWebmail/I18N/de.pm
JWebmail/Model/ReadMails/QMailAuthuser.pm
JWebmail/Model/ReadMails/Role.pm
JWebmail/Model/WriteMails.pm
JWebmail/Plugin/I18N2/Role.pm
JWebmail/Plugin/I18N2.pm
JWebmail/Plugin/INIConfig.pm
JWebmail/Plugin/Paginate.pm
JWebmail/Plugin/ServerSideSessionData.pm
JWebmail/Plugin/TOMLConfig.pm
JWebmail/View/RenderMail.pm
JWebmail/View/Webmail.pm
JWebmail/Config.pm
JWebmail/I18N.pm
JWebmail.pm
END
#JWebmail/I18N/en.pm
#JWebmail/Plugin/I18N2/Maketext.pm
#JWebmail/Plugin/I18N2/INI.pm

install_file instdata \$datadir . public/css/my_bulma.css
[ "$JWM_MODE" = development ] && install_file instdata \$datadir . public/css/my_bulma.css.map
install_file instdata \$datadir . public/src/displayheaders.js
[ "$JWM_MODE" = development ] && install_file instdata \$datadir . public/src/displayheaders.js.map
install_file instdata \$datadir . public/src/rendermail.js
[ "$JWM_MODE" = development ] && install_file instdata \$datadir . public/src/rendermail.js.map

if [ "$LOGIN_SCHEME" = cram_md5 ]
then
    install_file instdata \$datadir . public/src/login_cram.js
    [ "$JWM_MODE" = development ] && install_file instdata \$datadir . public/src/login_cram.js.map
fi

while read f
do install_file instdata \$datadir . "$f"
done <<'END'
templates/displayheaders/_bot_nav.html.ep
templates/displayheaders/_folders.html.ep
templates/displayheaders/_main_table.html.ep
templates/displayheaders/_pagination1.html.ep
templates/displayheaders/_pagination2.html.ep
templates/displayheaders/_pagination3.html.ep
templates/displayheaders/_top_nav.html.ep
templates/layouts/mainlayout.html.ep
templates/webmail/about.html.ep
templates/webmail/displayheaders.html.ep
templates/webmail/login.html.ep
templates/webmail/readmail.html.ep
templates/webmail/writemail.html.ep
templates/exception_.html.ep
templates/not_found.html.ep
END

install_file instdata \$confdir . jwebmail.development.toml
install_file instdata \$confdir . jwebmail.production.toml

for f in CHANGES.md LICENSE README.md
do install_file instdata \$docdir . "$f"
done

if [ "$JWM_INIT" = systemd ]
then
    case "$PREFIX" in
        (usr)       install_file instdata etc/systemd/system install jwebmail.service;;
        (usr/local) install_file instdata usr/local/lib/systemd/system install jwebmail.service;;
        (*)         echo 'unknown prefix' >&2; exit 1;;
    esac
    install_file instdata etc/sysusers.d install jwebmail-sysusers.conf
fi

echo "build install: phony $ALL_INST"

# DEFAULT

echo "default extract public"