forked from msteveb/jimtcl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-bootstrap-jim
executable file
·138 lines (122 loc) · 3.23 KB
/
make-bootstrap-jim
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
#!/bin/sh
# This script writes to stdout, a single source file (e.g. jimsh0.c)
# which can be compiled to provide a bootstrap version of jimsh.
# e.g. cc -o jimsh0 jimsh0.c
makeext()
{
source="$1"
basename=`basename "$source" .tcl`
cat <<EOF
int Jim_${basename}Init(Jim_Interp *interp)
{
if (Jim_PackageProvide(interp, "$basename", "1.0", JIM_ERRMSG))
return JIM_ERR;
return Jim_EvalSource(interp, "$source", 1,
EOF
# Note: Keep newlines so that line numbers match in error messages
sed -e 's/^[ ]*#.*//' -e 's@\\@\\\\@g' -e 's@"@\\"@g' -e 's@^\(.*\)$@"\1\\n"@' $source
echo ");"
echo "}"
}
makeloadexts()
{
cat <<EOF
int Jim_InitStaticExtensions(Jim_Interp *interp)
EOF
echo "{"
for ext in $*; do
echo "extern int Jim_${ext}Init(Jim_Interp *);"
done
for ext in $*; do
echo "Jim_${ext}Init(interp);"
done
echo "return JIM_OK;"
echo "}"
}
cexts="aio readdir regexp file exec clock array"
tclexts="bootstrap initjimsh glob stdlib tclcompat"
# Note ordering
allexts="bootstrap aio readdir regexp file glob exec clock array stdlib tclcompat"
echo "/* This is single source file, bootstrap version of Jim Tcl. See http://jim.tcl.tk/ */"
# define some core features
for i in JIM_TCL_COMPAT JIM_ANSIC JIM_REGEXP HAVE_NO_AUTOCONF _JIMAUTOCONF_H; do
echo "#define $i"
done
echo '#define TCL_LIBRARY "."'
# and extensions
for i in $allexts; do
echo "#define jim_ext_$i"
done
cat <<EOF
#if defined(_MSC_VER)
#define TCL_PLATFORM_OS "windows"
#define TCL_PLATFORM_PLATFORM "windows"
#define TCL_PLATFORM_PATH_SEPARATOR ";"
#define HAVE_MKDIR_ONE_ARG
#define HAVE_SYSTEM
#elif defined(__MINGW32__)
#define TCL_PLATFORM_OS "mingw"
#define TCL_PLATFORM_PLATFORM "windows"
#define TCL_PLATFORM_PATH_SEPARATOR ";"
#define HAVE_MKDIR_ONE_ARG
#define HAVE_SYSTEM
#define HAVE_SYS_TIME_H
#define HAVE_DIRENT_H
#define HAVE_UNISTD_H
#define HAVE_UMASK
#include <sys/stat.h>
#ifndef S_IRWXG
#define S_IRWXG 0
#endif
#ifndef S_IRWXO
#define S_IRWXO 0
#endif
#else
#define TCL_PLATFORM_OS "unknown"
#define TCL_PLATFORM_PLATFORM "unix"
#define TCL_PLATFORM_PATH_SEPARATOR ":"
#ifdef _MINIX
#define vfork fork
#define _POSIX_SOURCE
#else
#define _GNU_SOURCE
#endif
#define HAVE_VFORK
#define HAVE_WAITPID
#define HAVE_ISATTY
#define HAVE_MKSTEMP
#define HAVE_LINK
#define HAVE_SYS_TIME_H
#define HAVE_DIRENT_H
#define HAVE_UNISTD_H
#define HAVE_UMASK
#endif
EOF
# get JIM_VERSION from auto.def
sed -n -e 's/^\(define JIM_VERSION.*\)/#\1/p' auto.def
outputsource()
{
sed -e '/#include.*jim/d' -e '/#include.*utf8/d' \
-e '/^#.*if.*JIM_BOOTSTRAP/,/^#endif.*JIM_BOOTSTRAP/d' \
-e 's/[ ]*\/\*.*\*\///' -e '/^[ ]*\/\*/,/\*\//d' $1
}
# Now output header files, removing references to jim header files
for i in jim-win32compat.h utf8.h jim.h jim-subcmd.h jimregexp.h jim-signal.h jimiocompat.h; do
outputsource $i
done
# Now extension source code
for i in $tclexts; do
makeext $i.tcl
done
for i in $cexts; do
outputsource jim-$i.c
done
makeloadexts $allexts
# And finally the core source code
for i in jim.c jim-subcmd.c utf8.c jim-format.c jimregexp.c jimiocompat.c jim-win32compat.c jim-nosignal.c; do
outputsource $i
done
echo "#ifndef JIM_BOOTSTRAP_LIB_ONLY"
outputsource jim-interactive.c
outputsource jimsh.c
echo "#endif"