~ubuntu-branches/ubuntu/karmic/mksh/karmic

« back to all changes in this revision

Viewing changes to Build.sh

  • Committer: Bazaar Package Importer
  • Author(s): Thorsten Glaser
  • Date: 2007-04-25 11:36:42 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070425113642-84xnxqdkzau1qrlf
Tags: 29.2-1
* New upstream formal release; summary of changes:
  + a plethora of UTF-8 fixes:
  - display control characters U+0080..U+009F the same as U+0000..U+001F,
    i.e. a caret followed by the character corresponding to the control
    character XOR 0x0040, treat their width as 2 subsequently
  - fix crash (cpu hog in spinning loop) on meta-tab + backspace
  - strip off UTF-8 byte order mark at beginning of input
  - if a BOM is encountered, switch on utf-8 command line editing mode
  + in utf-8 command line editing mode, handle invalid input more strictly:
  - if in x_literal(), i.e. the ^V mode (bind to quote), allow it as before
  - if it's the start of an invalid multibyte sequence, reject with a beep
    (e.g. if trying to input latin1 chars)
  - if it's an invalid or partial multibyte sequence, reject silently
  -> this makes command line editing much more robust
  + other bug fixes:
  - in a rare condition (error path), the wrong function was used to copy
    a string that could contain embedded NULs (encoded format), leading to
    memory access past malloc'd area
  - in the same path, fix an out-of-bounds access inherited from openbsd ksh
  -> discovered on Debian GNU/Linux experimental ia64, glibc 2.5-beta
  + new functionality:
  - if execve() fails, before passing the file to $EXECSHELL, open it and
    try to parse a shebang line; if we find one, do it ourselves
    (the good part of this is that it even works when there is a UTF-8 BOM
    before the shebang magic sequence)
  - for shebang processing, not only NUL or LF but also CR terminate the line
  - enhancements to the "dot.mkshrc" sample file (which is now regularily
    used upstream as well)
  - if the internal function exchild() fails, don't just tell the user that
    it failed, tell him WHAT failed (unless -DMKSH_SMALL)
  + code cleanup changes:
  - remove unused functions, macros
  - fix typos, errors, etc.
  - shut up gcc 4.1.2 warnings
  - Build.sh cygwin vs unix cleanup/simplification
  - shrink manual page to 39 DIN A4 pages when output as postscript
  + reliability changes:
  - if $CC supports -fstack-protector-all, add it to $CFLAGS
  - if $CC supports -fno-tree-vrp, add it to $CFLAGS if $CC is subject to
    the bug http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30785
  - add mirtoconf check for "large file support", requested by bsiegert@,
    needed for some *nix, idea and implementation hints from GNU autoconf
  - add zsh workaround to Build.sh, just in case (untested)
* disable the possible workaround mentioned in the changes for 28.9.20070309
  because I was unable to verify/test it; maybe it only applies to the glibc
  in experimental anyway, we'll see to that later
* add a comment about the regression test needing openpty() to debian/rules
* remove non-ASCII (i.e. high-bit7) characters from diff/changelog
* slightly enhance package description
* properly indent homepage link in description, thanks KiBi (kfreebsd team)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/sh
2
 
# $MirOS: src/bin/mksh/Build.sh,v 1.54 2006/08/28 01:37:29 tg Exp $
 
2
# $MirOS: src/bin/mksh/Build.sh,v 1.169 2007/04/23 11:33:25 tg Exp $
3
3
#-
4
 
# Environment: CC, CFLAGS, CPPFLAGS, LDFLAGS, LIBS, NROFF
 
4
# Environment used: CC CFLAGS CPP CPPFLAGS LDFLAGS LIBS NOWARN NROFF TARGET_OS
 
5
# CPPFLAGS recognised: MKSH_SMALL MKSH_ASSUME_UTF8 MKSH_NEED_MKNOD MKSH_NOPWNAM
5
6
 
6
7
v()
7
8
{
9
10
        eval "$@"
10
11
}
11
12
 
12
 
addcppf()
13
 
{
 
13
vq()
 
14
{
 
15
        eval "$@"
 
16
}
 
17
 
 
18
if test -d /usr/xpg4/bin/. >/dev/null 2>&1; then
 
19
        # Solaris: some of the tools have weird behaviour, use portable ones
 
20
        PATH=/usr/xpg4/bin:$PATH
 
21
        export PATH
 
22
fi
 
23
 
 
24
if test -n "${ZSH_VERSION+x}" && (emulate sh) >/dev/null 2>&1; then
 
25
        emulate sh
 
26
        NULLCMD=:
 
27
fi
 
28
 
 
29
if test -t 1; then
 
30
        bi=`printf '\033[1m'`
 
31
        ui=`printf '\033[4m'`
 
32
        ao=`printf '\033[0m'`
 
33
else
 
34
        bi=
 
35
        ui=
 
36
        ao=
 
37
fi
 
38
 
 
39
allu=QWERTYUIOPASDFGHJKLZXCVBNM
 
40
alll=qwertyuiopasdfghjklzxcvbnm
 
41
alln=0123456789
 
42
alls=______________________________________________________________
 
43
nl='
 
44
'
 
45
tcbo=
 
46
tcfn=no
 
47
 
 
48
upper()
 
49
{
 
50
        echo :"$@" | sed 's/^://' | tr $alll $allu
 
51
}
 
52
 
 
53
# pipe .c | ac_test[n] label [!] checkif[!]0 [setlabelifcheckis[!]0] useroutput
 
54
ac_testn()
 
55
{
 
56
        f=$1
 
57
        fu=`upper $f`
 
58
        fc=0
 
59
        if test x"$2" = x""; then
 
60
                ft=1
 
61
        else
 
62
                if test x"$2" = x"!"; then
 
63
                        fc=1
 
64
                        shift
 
65
                fi
 
66
                eval ft=\$HAVE_`upper $2`
 
67
                shift
 
68
        fi
 
69
        fd=$3
 
70
        test x"$fd" = x"" && fd=$f
 
71
        eval fv=\$HAVE_$fu
 
72
        if test 0 = "$fv"; then
 
73
                $e "$bi==> $fd...$ao ${ui}no$ao (cached)"
 
74
                return
 
75
        fi
 
76
        if test 1 = "$fv"; then
 
77
                $e "$bi==> $fd...$ao ${ui}yes$ao (cached)"
 
78
                return
 
79
        fi
 
80
        if test $fc = "$ft"; then
 
81
                fv=$2
 
82
                eval HAVE_$fu=$fv
 
83
                test 0 = "$fv" && fv=no
 
84
                test 1 = "$fv" && fv=yes
 
85
                $e "$bi==> $fd...$ao $ui$fv$ao (implied)"
 
86
                return
 
87
        fi
 
88
        $e ... $fd
 
89
        cat >scn.c
 
90
        eval 'v "$CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN -I'\''$srcdir'\' \
 
91
            'scn.c $LIBS" 2>&'$h | sed 's/^/] /'
 
92
        test x"$tcfn" = x"no" && test -f a.out && tcfn=a.out
 
93
        test x"$tcfn" = x"no" && test -f a.exe && tcfn=a.exe
 
94
        test x"$tcbo" = x"1" && return
 
95
        if test -f $tcfn; then
 
96
                eval HAVE_$fu=1
 
97
                $e "$bi==> $fd...$ao ${ui}yes$ao"
 
98
        else
 
99
                eval HAVE_$fu=0
 
100
                $e "$bi==> $fd...$ao ${ui}no$ao"
 
101
        fi
 
102
        rm -f scn.c $tcfn
 
103
}
 
104
 
 
105
ac_test()
 
106
{
 
107
        ac_testn "$@"
 
108
        eval CPPFLAGS=\"\$CPPFLAGS -DHAVE_$fu=\$HAVE_$fu\"
 
109
}
 
110
 
 
111
# ac_flags add varname flags [text]
 
112
ac_flags()
 
113
{
 
114
        fa=$1
 
115
        vn=$2
 
116
        f=$3
 
117
        ft=$4
 
118
        test x"$ft" = x"" && ft="if $f can be used"
 
119
        save_CFLAGS=$CFLAGS
 
120
        CFLAGS="$CFLAGS $f"
 
121
        ac_testn can_$vn '' "$ft" <<-'EOF'
 
122
                int main(void) { return (0); }
 
123
        EOF
 
124
        eval fv=\$HAVE_CAN_`upper $vn`
 
125
        test 11 = $fa$fv || CFLAGS=$save_CFLAGS
 
126
}
 
127
 
 
128
# ac_header header [prereq ...]
 
129
ac_header()
 
130
{
 
131
        hf=$1; shift
 
132
        hv=`echo "$hf" | tr -d '\012\015' | tr -c $alll$allu$alln $alls`
14
133
        for i
15
134
        do
16
 
                eval CPPFLAGS=\"\$CPPFLAGS -D$i=\$$i\"
 
135
                echo "#include <$i>" >>x
17
136
        done
18
 
}
 
137
        echo "#include <$hf>" >>x
 
138
        echo 'int main(void) { return (0); }' >>x
 
139
        ac_test "$hv" "" "<$hf>" <x
 
140
        rm -f x
 
141
}
 
142
 
 
143
addsrcs()
 
144
{
 
145
        eval i=\$$1
 
146
        test 0 = $i && case " $SRCS " in
 
147
        *\ $2\ *)       ;;
 
148
        *)              SRCS="$SRCS $2" ;;
 
149
        esac
 
150
}
 
151
 
19
152
 
20
153
if test -d mksh; then
21
154
        echo "$0: Error: ./mksh is a directory!" >&2
22
155
        exit 1
23
156
fi
24
157
 
25
 
: ${CFLAGS='-O2 -fno-strict-aliasing -fno-strength-reduce -Wall'}
26
 
: ${CC=gcc} ${NROFF=nroff}
27
 
curdir=`pwd` srcdir=`dirname "$0"`
28
 
echo | $NROFF -v 2>&1 | grep GNU >&- 2>&- && NROFF="$NROFF -c"
 
158
: ${CC=gcc} ${CPP=false} ${NROFF=nroff}
 
159
curdir=`pwd` srcdir=`dirname "$0"` check_categories=pdksh
29
160
 
30
161
e=echo
31
 
q=0
 
162
h=1
32
163
r=0
33
 
x=0
 
164
s=def
34
165
 
35
166
for i
36
167
do
37
168
        case $i in
38
169
        -d)
39
 
                LDSTATIC=
 
170
                s=dyn
 
171
                ;;
 
172
        -nd)
 
173
                s=sta
40
174
                ;;
41
175
        -q)
42
176
                e=:
43
 
                q=1
 
177
                h=-
44
178
                ;;
45
179
        -r)
46
180
                r=1
47
181
                ;;
48
 
        -x)
49
 
                x=1
50
 
                ;;
51
182
        *)
52
183
                echo "$0: Unknown option '$i'!" >&2
53
184
                exit 1
55
186
        esac
56
187
done
57
188
 
58
 
if test $x = 0; then
59
 
        LDSTATIC=-static
60
 
        SRCS=
61
 
        sigseen=
62
 
        NOWARN=-Wno-error
63
 
fi
64
 
SRCS="$SRCS alloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c"
 
189
SRCS="alloc.c edit.c eval.c exec.c expr.c funcs.c histrap.c"
65
190
SRCS="$SRCS jobs.c lex.c main.c misc.c shf.c syn.c tree.c var.c"
66
191
 
67
 
test $x = 1 || case `uname -s 2>/dev/null || uname` in
 
192
test $r = 0 && echo | $NROFF -v 2>&1 | grep GNU >/dev/null 2>&1 && \
 
193
    NROFF="$NROFF -c"
 
194
 
 
195
 
 
196
test x"$TARGET_OS" = x"" && TARGET_OS=`uname -s 2>/dev/null || uname`
 
197
warn=
 
198
case $TARGET_OS in
68
199
CYGWIN*)
69
 
        LDSTATIC=
70
 
        SRCS="$SRCS compat.c"
71
 
        CPPFLAGS="$CPPFLAGS -DNEED_COMPAT"
72
 
        sigseen=:
 
200
        test def = $s && s=pam
73
201
        ;;
74
202
Darwin)
75
 
        LDSTATIC=
76
 
        CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
 
203
        test def = $s && s=pam
 
204
        ;;
 
205
DragonFly)
 
206
        ;;
 
207
FreeBSD)
 
208
        ;;
 
209
GNU)
 
210
        CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
 
211
        ;;
 
212
GNU/kFreeBSD)
 
213
        CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
77
214
        ;;
78
215
Interix)
79
 
        CPPFLAGS="$CPPFLAGS -D_ALL_SOURCE -DNEED_COMPAT"
 
216
        CPPFLAGS="$CPPFLAGS -D_ALL_SOURCE"
80
217
        ;;
81
218
Linux)
82
 
        SRCS="$SRCS compat.c strlfun.c"
83
 
        CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=2 -D_BSD_SOURCE -D_GNU_SOURCE"
84
 
        CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -DNEED_COMPAT"
85
 
        LDSTATIC=
86
 
        sigseen=:
 
219
        CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
 
220
        test def = $s && s=pam
 
221
        : ${HAVE_REVOKE=0}
 
222
        ;;
 
223
Minix)
 
224
        CPPFLAGS="$CPPFLAGS -D_MINIX -D_POSIX_SOURCE"
 
225
        warn=' and will currently not work'
 
226
#       warn=" but might work with the GNU tools"
 
227
#       warn="$warn$nl but not with ACK - /usr/bin/cc - yet)"
 
228
        ;;
 
229
MirBSD)
 
230
        ;;
 
231
NetBSD)
 
232
        ;;
 
233
OpenBSD)
87
234
        ;;
88
235
SunOS)
89
 
        SRCS="$SRCS compat.c"
90
 
        CPPFLAGS="$CPPFLAGS -D_BSD_SOURCE -D_POSIX_C_SOURCE=200112L"
91
 
        CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__"
92
 
        CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -DNEED_COMPAT"
93
 
        LDSTATIC=
94
 
        sigseen=:
 
236
        CPPFLAGS="$CPPFLAGS -D_BSD_SOURCE -D__EXTENSIONS__"
 
237
        test def = $s && s=pam
95
238
        r=1
96
239
        ;;
 
240
*)
 
241
        warn='; it may or may not work'
 
242
        ;;
97
243
esac
98
244
 
99
 
if test x"$sigseen" = x:; then
100
 
        $e Generating list of signal names
101
 
        NSIG=`printf %d "\`(echo '#include <signal.h>';echo mksh_cfg: NSIG) | \
102
 
            $CC $CPPFLAGS -E - | grep mksh_cfg | sed 's/^mksh_cfg: //'\`" 2>&-`
 
245
if test -n "$warn"; then
 
246
        echo "Warning: mksh has not yet been ported to or tested on your" >&2
 
247
        echo "operating system '$TARGET_OS'$warn. If you can provide" >&2
 
248
        echo "a shell account to the developer, this may improve; please" >&2
 
249
        echo "drop us a success or failure notice or even send in diffs." >&2
 
250
fi
 
251
 
 
252
CPPFLAGS="$CPPFLAGS -I'$curdir'"
 
253
 
 
254
 
 
255
#
 
256
# Begin of mirtoconf checks
 
257
#
 
258
rm -f scn.c a.out a.exe x no lft
 
259
$e ${ao}Scanning for functions... please ignore any errors.
 
260
 
 
261
#
 
262
# Compiler: works as-is, with -Wno-error and -Werror
 
263
#
 
264
test x"$NOWARN" = x"" && NOWARN=-Wno-error
 
265
save_NOWARN=$NOWARN
 
266
NOWARN=
 
267
ac_flags 0 compiler_works '' 'if the compiler works'
 
268
test 1 = $HAVE_CAN_COMPILER_WORKS || exit 1
 
269
ac_flags 0 wnoerror "$save_NOWARN"
 
270
test 1 = $HAVE_CAN_WNOERROR || save_NOWARN=
 
271
ac_flags 0 werror "-Werror"
 
272
 
 
273
# The following tests are run with -Werror if possible
 
274
test 1 = $HAVE_CAN_WERROR && NOWARN=-Werror
 
275
 
 
276
#
 
277
# Compiler: check for stuff that only generates warnings
 
278
#
 
279
ac_test attribute '' 'if we have __attribute__((...)) at all' <<-'EOF'
 
280
        #include <stdlib.h>
 
281
        void fnord(void) __attribute__((noreturn));
 
282
        int main(void) { fnord(); }
 
283
        void fnord(void) { exit(0); }
 
284
EOF
 
285
 
 
286
ac_test attribute_bounded attribute 0 'for __attribute__((bounded))' <<-'EOF'
 
287
        #include <string.h>
 
288
        int xcopy(const void *, void *, size_t)
 
289
            __attribute__((bounded (buffer, 1, 3)))
 
290
            __attribute__((bounded (buffer, 2, 3)));
 
291
        int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); }
 
292
        int xcopy(const void *s, void *d, size_t n) {
 
293
                memmove(d, s, n); return (n);
 
294
        }
 
295
EOF
 
296
 
 
297
ac_test attribute_used attribute 0 'for __attribute__((used))' <<-'EOF'
 
298
        static const char fnord[] __attribute__((used)) = "42";
 
299
        int main(void) { return (0); }
 
300
EOF
 
301
 
 
302
# End of tests run with -Werror
 
303
NOWARN=$save_NOWARN
 
304
 
 
305
#
 
306
# Compiler: extra flags (-O2 -f* -W* etc.)
 
307
#
 
308
i=`echo :"$CFLAGS" | sed 's/^://' | tr -c -d $alll$allu$alln-`
 
309
test x"$i" = x"" && ac_flags 1 otwo "-O2"
 
310
ac_flags 0 fnotreevrp "-fno-tree-vrp"
 
311
if test 1 = $HAVE_CAN_FNOTREEVRP; then
 
312
        tcbo=1
 
313
        ac_testn need_fnotreevrp '' "if to use it to prevent a gcc bug" <<-'EOF'
 
314
                typedef unsigned size_t;
 
315
                char *strncpy(char *, const char *, size_t);
 
316
                char *
 
317
                strncpy(char *d, const char *s, size_t n)
 
318
                {
 
319
                        if (!d || !s) {
 
320
                                if (d)
 
321
                                        *d = n;
 
322
                                return (d);
 
323
                        }
 
324
                        return (*d = 1, d);
 
325
                }
 
326
                int
 
327
                main(void)
 
328
                {
 
329
                        char a[] = "t";
 
330
                        strncpy(a, (void *)0, 2);
 
331
                        return (*a);
 
332
                }
 
333
        EOF
 
334
        tcbo=
 
335
        if test -f $tcfn; then
 
336
                ./$tcfn >/dev/null 2>&1
 
337
                rv=$?
 
338
                rs=no
 
339
        else
 
340
                rv=0
 
341
                rs="yes (assumed; cannot run ./$tcfn)"
 
342
        fi
 
343
        test 1 = $rv && rs=yes
 
344
        test 2 = $rv || CFLAGS="$CFLAGS -fno-tree-vrp"
 
345
        $e "$bi==> $fd...$ao ${ui}$rs$ao"
 
346
        rm -f scn.c $tcfn
 
347
fi
 
348
ac_flags 1 fnostrictaliasing "-fno-strict-aliasing"
 
349
ac_flags 1 fstackprotectorall "-fstack-protector-all"
 
350
ac_flags 1 fwholepgm "-fwhole-program --combine"
 
351
ac_flags 1 fwrapv "-fwrapv"
 
352
# I'd use -std=c99 but this wrecks havoc on glibc and cygwin based
 
353
# systems (at least) because their system headers are so broken...
 
354
ac_flags 1 stdg99 "-std=gnu99" 'if -std=gnu99 (ISO C99) can be used'
 
355
ac_flags 1 wall "-Wall"
 
356
 
 
357
#
 
358
# mksh: flavours (full/small mksh, omit certain stuff)
 
359
#
 
360
ac_testn mksh_full '' "if we're building without MKSH_SMALL" <<-'EOF'
 
361
        #ifdef MKSH_SMALL
 
362
        #error OK, we are building an extra small mksh.
 
363
        #endif
 
364
        int main(void) { return (0); }
 
365
EOF
 
366
 
 
367
ac_testn mksh_defutf8 '' "if we assume UTF-8 is enabled" <<-'EOF'
 
368
        #ifndef MKSH_ASSUME_UTF8
 
369
        #error Nope, we shall check with setlocale() and nl_langinfo(CODESET)
 
370
        #endif
 
371
        int main(void) { return (0); }
 
372
EOF
 
373
 
 
374
ac_testn mksh_need_mknod '!' mksh_full 1 'if we still want c_mknod()' <<-'EOF'
 
375
        #ifndef MKSH_NEED_MKNOD
 
376
        #error Nope, the user really wants it teensy.
 
377
        #endif
 
378
        int main(void) { return (0); }
 
379
EOF
 
380
 
 
381
ac_testn mksh_nopam mksh_full 1 'if the user wants to omit getpwnam()' <<-'EOF'
 
382
        #ifndef MKSH_NOPWNAM
 
383
        #error No, the user wants to pull in getpwnam.
 
384
        #endif
 
385
        int main(void) { return (0); }
 
386
EOF
 
387
 
 
388
if test 0 = $HAVE_MKSH_FULL; then
 
389
        ac_flags 1 fnoinline "-fno-inline"
 
390
 
 
391
        : ${HAVE_SETLOCALE_CTYPE=0}
 
392
        check_categories=$check_categories,smksh
 
393
fi
 
394
 
 
395
#
 
396
# Environment: headers
 
397
#
 
398
ac_header sys/param.h
 
399
ac_header sys/mkdev.h
 
400
ac_header sys/mman.h sys/types.h
 
401
ac_header sys/sysmacros.h
 
402
ac_header libgen.h
 
403
ac_header paths.h
 
404
ac_header stdbool.h
 
405
ac_header stdint.h
 
406
ac_header grp.h sys/types.h
 
407
ac_header ulimit.h
 
408
ac_header values.h
 
409
 
 
410
#
 
411
# Environment: definitions
 
412
#
 
413
cat >lft.c <<-'EOF'
 
414
        #include <sys/types.h>
 
415
        /* check that off_t can represent 2^63-1 correctly, thx FSF */
 
416
        #define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
 
417
        int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 &&
 
418
            LARGE_OFF_T % 2147483647 == 1) ? 1 : -1];
 
419
        int main(void) { return (0); }
 
420
EOF
 
421
ac_testn can_lfs '' "if we support large files" <lft.c
 
422
save_CPPFLAGS=$CPPFLAGS
 
423
CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
 
424
ac_testn can_lfs_sus '!' can_lfs 0 "... with -D_FILE_OFFSET_BITS=64" <lft.c
 
425
if test 1 = $HAVE_CAN_LFS_SUS; then
 
426
        HAVE_CAN_LFS=1
 
427
else
 
428
        CPPFLAGS=$save_CPPFLAGS
 
429
fi
 
430
CPPFLAGS="$CPPFLAGS _LARGE_FILES=1"
 
431
ac_testn can_lfs_aix '!' can_lfs 0 "... with -D_LARGE_FILES=1" <lft.c
 
432
test 1 = $HAVE_CAN_LFS_AIX || CPPFLAGS=$save_CPPFLAGS
 
433
rm -f lft.c     # end of large file support test
 
434
 
 
435
#
 
436
# Environment: types
 
437
#
 
438
ac_test rlim_t <<-'EOF'
 
439
        #include <sys/types.h>
 
440
        #include <sys/time.h>
 
441
        #include <sys/resource.h>
 
442
        #include <unistd.h>
 
443
        int main(void) { return ((int)(rlim_t)0); }
 
444
EOF
 
445
 
 
446
# only testn: added later below
 
447
ac_testn sig_t <<-'EOF'
 
448
        #include <sys/types.h>
 
449
        #include <signal.h>
 
450
        int main(void) { return ((int)(sig_t)0); }
 
451
EOF
 
452
 
 
453
ac_testn sighandler_t '!' sig_t 0 <<-'EOF'
 
454
        #include <sys/types.h>
 
455
        #include <signal.h>
 
456
        int main(void) { return ((int)(sighandler_t)0); }
 
457
EOF
 
458
if test 1 = $HAVE_SIGHANDLER_T; then
 
459
        CPPFLAGS="$CPPFLAGS -Dsig_t=sighandler_t"
 
460
        HAVE_SIG_T=1
 
461
fi
 
462
 
 
463
ac_testn __sighandler_t '!' sig_t 0 <<-'EOF'
 
464
        #include <sys/types.h>
 
465
        #include <signal.h>
 
466
        int main(void) { return ((int)(__sighandler_t)0); }
 
467
EOF
 
468
if test 1 = $HAVE___SIGHANDLER_T; then
 
469
        CPPFLAGS="$CPPFLAGS -Dsig_t=__sighandler_t"
 
470
        HAVE_SIG_T=1
 
471
fi
 
472
 
 
473
CPPFLAGS="$CPPFLAGS -DHAVE_SIG_T=$HAVE_SIG_T"
 
474
 
 
475
#
 
476
# Environment: signals
 
477
#
 
478
test x"NetBSD" = x"$TARGET_OS" && $e Ignore the compatibility warning.
 
479
 
 
480
ac_test mksh_signame '' 'our own list of signal names' <<-'EOF'
 
481
        #include <stdlib.h>     /* for NULL */
 
482
        #define MKSH_SIGNAMES_CHECK
 
483
        #include "signames.c"
 
484
        int main(void) { return (mksh_sigpairs[0].nr); }
 
485
EOF
 
486
 
 
487
ac_test sys_signame '!' mksh_signame 0 'the sys_signame[] array' <<-'EOF'
 
488
        extern const char *const sys_signame[];
 
489
        int main(void) { return (sys_signame[0][0]); }
 
490
EOF
 
491
 
 
492
ac_test _sys_signame '!' sys_signame 0 'the _sys_signame[] array' <<-'EOF'
 
493
        extern const char *const _sys_signame[];
 
494
        int main(void) { return (_sys_signame[0][0]); }
 
495
EOF
 
496
 
 
497
if test 000 = $HAVE_SYS_SIGNAME$HAVE__SYS_SIGNAME$HAVE_MKSH_SIGNAME; then
 
498
        NEED_MKSH_SIGNAME=1
 
499
else
 
500
        NEED_MKSH_SIGNAME=0
 
501
fi
 
502
 
 
503
# only testn: added later below
 
504
ac_testn sys_siglist '' 'the sys_siglist[] array' <<-'EOF'
 
505
        extern const char *const sys_siglist[];
 
506
        int main(void) { return (sys_siglist[0][0]); }
 
507
EOF
 
508
 
 
509
ac_testn _sys_siglist '!' sys_siglist 0 'the _sys_siglist[] array' <<-'EOF'
 
510
        extern const char *const _sys_siglist[];
 
511
        int main(void) { return (_sys_siglist[0][0]); }
 
512
EOF
 
513
if test 1 = $HAVE__SYS_SIGLIST; then
 
514
        CPPFLAGS="$CPPFLAGS -Dsys_siglist=_sys_siglist"
 
515
        HAVE_SYS_SIGLIST=1
 
516
fi
 
517
CPPFLAGS="$CPPFLAGS -DHAVE_SYS_SIGLIST=$HAVE_SYS_SIGLIST"
 
518
 
 
519
ac_test strsignal '!' sys_siglist 0 <<-'EOF'
 
520
        #include <string.h>
 
521
        #include <signal.h>
 
522
        int main(void) { return (strsignal(1)[0]); }
 
523
EOF
 
524
 
 
525
#
 
526
# Environment: library functions
 
527
#
 
528
ac_test arc4random <<-'EOF'
 
529
        #include <stdlib.h>
 
530
        int main(void) { return (arc4random()); }
 
531
EOF
 
532
 
 
533
ac_test arc4random_push arc4random 0 <<-'EOF'
 
534
        #include <stdlib.h>
 
535
        int main(void) { arc4random_push(1); return (0); }
 
536
EOF
 
537
 
 
538
ac_test flock_ex '' 'flock and LOCK_EX' <<-'EOF'
 
539
        #include <sys/types.h>
 
540
        #include <sys/file.h>
 
541
        #include <fcntl.h>
 
542
        int main(void) { return (flock(0, LOCK_EX)); }
 
543
EOF
 
544
 
 
545
ac_test setlocale_ctype '!' mksh_defutf8 0 'setlocale(LC_CTYPE, "")' <<-'EOF'
 
546
        #include <locale.h>
 
547
        #include <stddef.h>
 
548
        int main(void) { return ((ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); }
 
549
EOF
 
550
 
 
551
ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF'
 
552
        #include <langinfo.h>
 
553
        #include <stddef.h>
 
554
        int main(void) { return ((ptrdiff_t)(void *)nl_langinfo(CODESET)); }
 
555
EOF
 
556
 
 
557
ac_test revoke mksh_full 0 <<-'EOF'
 
558
        #include <unistd.h>
 
559
        int main(int ac, char *av[]) { return (ac + revoke(av[0])); }
 
560
EOF
 
561
 
 
562
ac_test setmode mksh_need_mknod 1 <<-'EOF'
 
563
        #if defined(__MSVCRT__) || defined(__CYGWIN__)
 
564
        #error Win32 setmode() is different from what we need
 
565
        #endif
 
566
        #include <unistd.h>
 
567
        int main(int ac, char *av[]) { return (getmode(setmode(av[0]), ac)); }
 
568
EOF
 
569
 
 
570
ac_test setresugid <<-'EOF'
 
571
        #include <sys/types.h>
 
572
        #include <unistd.h>
 
573
        int main(void) { setresuid(0,0,0); return (setresgid(0,0,0)); }
 
574
EOF
 
575
 
 
576
ac_test setgroups setresugid 0 <<-'EOF'
 
577
        #include <sys/types.h>
 
578
        #if HAVE_GRP_H
 
579
        #include <grp.h>
 
580
        #endif
 
581
        #include <unistd.h>
 
582
        int main(void) { gid_t gid = 0; return (setgroups(0, &gid)); }
 
583
EOF
 
584
 
 
585
ac_test strcasestr <<-'EOF'
 
586
        #include <stddef.h>
 
587
        #include <string.h>
 
588
        int main(int ac, char *av[]) {
 
589
                return ((ptrdiff_t)(void *)strcasestr(*av, av[ac]));
 
590
        }
 
591
EOF
 
592
 
 
593
ac_test strlcpy <<-'EOF'
 
594
        #include <string.h>
 
595
        int main(int ac, char *av[]) { return (strlcpy(*av, av[1], ac)); }
 
596
EOF
 
597
 
 
598
#
 
599
# other checks
 
600
#
 
601
ac_test persistent_history mksh_full 0 'if to use persistent history' <<-'EOF'
 
602
        #if !HAVE_FLOCK_EX || defined(MKSH_SMALL)
 
603
        #error No, some prerequisites are missing.
 
604
        #endif
 
605
        int main(void) { return (0); }
 
606
EOF
 
607
test 1 = $HAVE_PERSISTENT_HISTORY || \
 
608
    check_categories=$check_categories,no-histfile
 
609
 
 
610
# Should be the _last_ one
 
611
ac_test multi_idstring '' 'if we can use __RCSID(x) multiple times' <<-'EOF'
 
612
        #define HAVE_MULTI_IDSTRING 1
 
613
        #include "sh.h"
 
614
        __RCSID("one");
 
615
        __RCSID("two");
 
616
        int main(void) { return (0); }
 
617
EOF
 
618
 
 
619
#
 
620
# Compiler: Praeprocessor (only if needed)
 
621
#
 
622
if test 1 = $NEED_MKSH_SIGNAME; then
 
623
        $e ... checking how to run the C Preprocessor
 
624
        save_CPP=$CPP
 
625
        for i in "$save_CPP" "$CC -E -" "cpp" "/usr/libexec/cpp" "/lib/cpp"; do
 
626
                CPP=$i
 
627
                test x"$CPP" = x"false" && continue
 
628
                eval '( ( echo "#if (23 * 2 - 2) == (fnord + 2)"
 
629
                    echo mksh_rules: fnord
 
630
                    echo "#endif"
 
631
                  ) | v "$CPP $CPPFLAGS -Dfnord=42 >x" ) 2>&'$h | \
 
632
                    sed 's/^/] /'
 
633
                grep '^mksh_rules:.*42' x >/dev/null 2>&1 || CPP=false
 
634
                rm -f x
 
635
                test x"$CPP" = x"false" || break
 
636
        done
 
637
        $e "$bi==> checking how to run the C Preprocessor...$ao $ui$CPP$ao"
 
638
        test x"$CPP" = x"false" && exit 1
 
639
fi
 
640
 
 
641
#
 
642
# End of mirtoconf checks
 
643
#
 
644
$e ... done.
 
645
 
 
646
# Some operating systems have ancient versions of ed(1) writing
 
647
# the character count to standard output; cope for that
 
648
echo wq >x
 
649
ed x <x 2>/dev/null | grep 3 >/dev/null 2>&1 && \
 
650
    check_categories=$check_categories,oldish-ed
 
651
rm -f x
 
652
 
 
653
if test 1 = $NEED_MKSH_SIGNAME; then
 
654
        $e Generating list of signal names...
 
655
        sigseen=:
 
656
        NSIG=`( echo '#include <signal.h>'; echo '#ifndef NSIG'; \
 
657
            echo '#define NSIG _NSIG'; echo '#endif'; echo mksh_cfg: NSIG ) | \
 
658
            vq "$CPP $CPPFLAGS" | grep mksh_cfg: | \
 
659
            sed 's/^mksh_cfg: \([0-9x]*\).*$/\1/'`
 
660
        NSIG=`printf %d "$NSIG" 2>/dev/null`
 
661
        test $h = 1 && printf "NSIG=$NSIG ... "
103
662
        test $NSIG -gt 1 || exit 1
104
 
        echo '#include <signal.h>' | $CC $CPPFLAGS -E -dD - | \
 
663
        echo '#include <signal.h>' | vq "$CPP $CPPFLAGS -dD" | \
105
664
            grep '[      ]SIG[A-Z0-9]*[  ]' | \
106
665
            sed 's/^\(.*[        ]SIG\)\([A-Z0-9]*\)\([  ].*\)$/\2/' | \
107
666
            while read name; do
108
 
                ( echo '#include <signal.h>'; echo "mksh_cfg: SIG$name" ) | \
109
 
                    $CC $CPPFLAGS -E - | grep mksh_cfg: | \
110
 
                    sed 's/^mksh_cfg: \([0-9]*\).*$/\1:'$name/
 
667
                ( echo '#include <signal.h>'; echo mksh_cfg: SIG$name ) | \
 
668
                    vq "$CPP $CPPFLAGS" | grep mksh_cfg: | \
 
669
                    sed 's/^mksh_cfg: \([0-9x]*\).*$/\1:'$name/
111
670
        done | grep -v '^:' | while IFS=: read nr name; do
112
 
                nr=`printf %d "$nr" 2>&-`
113
 
                test $nr -gt 0 && test $nr -lt $NSIG || continue
 
671
                nr=`printf %d "$nr" 2>/dev/null`
 
672
                test $nr -gt 0 && test $nr -le $NSIG || continue
114
673
                case $sigseen in
115
674
                *:$nr:*) ;;
116
675
                *)      echo "          { $nr, \"$name\" },"
117
676
                        sigseen=$sigseen$nr:
 
677
                        test $h = 1 && printf "$nr " >&2
118
678
                        ;;
119
679
                esac
120
 
        done >signames.inc
121
 
        test -f signames.inc || exit 1
122
 
fi
123
 
 
124
 
$e Scanning for functions...
125
 
 
126
 
test 0 = "$HAVE_ARC4RANDOM" || test 1 = "$HAVE_ARC4RANDOM" ||
127
 
{
128
 
        $e ... arc4random
129
 
        cat >scn.c <<-'EOF'
130
 
                #include <stdlib.h>
131
 
                int main() { arc4random(); return (0); }
132
 
        EOF
133
 
        $CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN scn.c $LIBS
134
 
        if test -f a.out || test -f a.exe; then
135
 
                HAVE_ARC4RANDOM=1
136
 
                $e "==> arc4random... yes"
137
 
        else
138
 
                HAVE_ARC4RANDOM=0
139
 
                $e "==> arc4random... no"
140
 
        fi
141
 
        rm -f scn.c a.out a.exe
142
 
}
143
 
 
144
 
test 0 = "$HAVE_ARC4RANDOM_PUSH" || test 1 = "$HAVE_ARC4RANDOM_PUSH" ||
145
 
if test 1 = "$HAVE_ARC4RANDOM"; then
146
 
        $e ... arc4random_push
147
 
        cat >scn.c <<-'EOF'
148
 
                #include <stdlib.h>
149
 
                int main() { arc4random_push(1); return (0); }
150
 
        EOF
151
 
        $CC $CFLAGS $CPPFLAGS $LDFLAGS $NOWARN scn.c $LIBS
152
 
        if test -f a.out || test -f a.exe; then
153
 
                HAVE_ARC4RANDOM_PUSH=1
154
 
                $e "==> arc4random_push... yes"
155
 
        else
156
 
                HAVE_ARC4RANDOM_PUSH=0
157
 
                $e "==> arc4random_push... no"
158
 
        fi
159
 
        rm -f scn.c a.out a.exe
160
 
else
161
 
        HAVE_ARC4RANDOM_PUSH=0
162
 
fi
163
 
 
164
 
$e ... done.
165
 
addcppf HAVE_ARC4RANDOM HAVE_ARC4RANDOM_PUSH
166
 
 
167
 
(v "cd '$srcdir' && exec $CC $CFLAGS -I'$curdir' $CPPFLAGS" \
168
 
    "$LDFLAGS $LDSTATIC -o '$curdir/mksh' $SRCS $LIBS") || exit 1
 
680
        done 2>&1 >signames.inc
 
681
        grep ', ' signames.inc >/dev/null 2>&1 || exit 1
 
682
        $e done.
 
683
fi
 
684
 
 
685
addsrcs HAVE_SETMODE setmode.c
 
686
addsrcs HAVE_STRLCPY strlcpy.c
 
687
CPPFLAGS="$CPPFLAGS -DHAVE_CONFIG_H -DCONFIG_H_FILENAME=\\\"sh.h\\\""
 
688
 
 
689
case $s:$HAVE_MKSH_NOPAM in
 
690
def:*|sta:*|pam:1)
 
691
        LDFLAGS="$LDFLAGS -static" ;;
 
692
esac
 
693
(v "cd '$srcdir' && exec $CC $CFLAGS $CPPFLAGS" \
 
694
    "$LDFLAGS -o '$curdir/mksh' $SRCS $LIBS") || exit 1
169
695
result=mksh
170
696
test -f mksh.exe && result=mksh.exe
171
697
test -f $result || exit 1
172
698
test $r = 1 || v "$NROFF -mdoc <'$srcdir/mksh.1' >mksh.cat1" || \
173
699
    rm -f mksh.cat1
174
 
test $q = 1 || v size $result
175
 
echo "#!$curdir/mksh" >test.sh
 
700
test $h = 1 && v size $result
 
701
case $curdir in
 
702
*\ *)   echo "#!./mksh" >test.sh ;;
 
703
*)      echo "#!$curdir/mksh" >test.sh ;;
 
704
esac
176
705
echo "exec perl '$srcdir/check.pl' -s '$srcdir/check.t'" \
177
 
    "-p '$curdir/mksh' -C pdksh \$*" >>test.sh
 
706
    "-p '$curdir/mksh' -C $check_categories \$*" >>test.sh
178
707
chmod 755 test.sh
179
708
i=install
180
709
test -f /usr/ucb/$i && i=/usr/ucb/$i
181
710
$e
182
711
$e Installing the shell:
183
712
$e "# $i -c -s -o root -g bin -m 555 mksh /bin/mksh"
184
 
$e "# grep -qx /bin/mksh /etc/shells || echo /bin/mksh >>/etc/shells"
 
713
$e "# grep -x /bin/mksh /etc/shells >/dev/null || echo /bin/mksh >>/etc/shells"
185
714
$e "# $i -c -o root -g bin -m 444 dot.mkshrc /usr/share/doc/mksh/examples/"
186
715
$e
187
716
$e Installing the manual: