Add support for "-commands" to many commands
[jimtcl.git] / auto.def
blobc7d9e5788748466c0985db103f3d7e486ff1e9b0
1 # vim:se syn=tcl:
4 define JIM_VERSION 77
6 # Note: modules which support options *must* be included before 'options'
7 use cc cc-shared cc-db cc-lib pkg-config
8 use local
10 options {
11 utf8 => "include support for utf8-encoded strings"
12 lineedit=1 => "disable line editing"
13 references=1 => "disable support for references"
14 math => "include support for math functions"
15 ssl => "include ssl/tls support in the aio extension"
16 ipv6 => "include ipv6 support in the aio extension"
17 maintainer => {enable the [debug] command and JimPanic}
18 full => "Enable some optional features: ipv6, ssl, math, utf8, binary, oo, tree"
19 with-jim-shared shared => "build a shared library instead of a static library"
20 jim-regexp=1 => "prefer POSIX regex if over the the built-in (Tcl-compatible) regex"
21 docs=1 => "don't build or install the documentation"
22 docdir:path => "path to install docs (if built)"
23 random-hash => "randomise hash tables. more secure but hash table results are not predicable"
24 with-jim-ext: {with-ext:"ext1 ext2 ..."} => {
25 Specify additional jim extensions to include.
26 These are enabled by default:
28 aio - ANSI I/O, including open and socket
29 eventloop - after, vwait, update
30 array - Tcl-compatible array command
31 clock - Tcl-compatible clock command
32 exec - Tcl-compatible exec command
33 file - Tcl-compatible file command
34 glob - Tcl-compatible glob command
35 history - Tcl access to interactive history
36 readdir - Required for glob
37 package - Package management with the package command
38 load - Load binary extensions at runtime with load or package
39 posix - Posix APIs including os.fork, os.wait, pid
40 regexp - Tcl-compatible regexp, regsub commands
41 signal - Signal handling
42 stdlib - Built-in commands including lassign, lambda, alias
43 syslog - System logging with syslog
44 tclcompat - Tcl compatible read, gets, puts, parray, case, ...
45 namespace - Tcl compatible namespace support
47 These are disabled by default:
49 oo - Jim OO extension
50 tree - OO tree structure, similar to tcllib ::struct::tree
51 binary - Tcl-compatible 'binary' command
52 readline - Interface to libreadline
53 rlprompt - Tcl wrapper around the readline extension
54 mk - Interface to Metakit
55 tclprefix - Support for the tcl::prefix command
56 sqlite3 - Interface to sqlite3
57 zlib - Interface to zlib
58 win32 - Interface to win32
60 with-out-jim-ext: {without-ext:"default|ext1 ext2 ..."} => {
61 Specify jim extensions to exclude.
62 If 'default' is given, the default extensions will not be added.
64 with-jim-extmod: {with-mod:"ext1 ext2 ..."} => {
65 Specify jim extensions to build as separate modules (either C or Tcl).
66 Note that not all extensions can be built as loadable modules.
68 # To help out openocd with automake
69 install-jim=1
72 # Save the user-specified LIBS
73 # We add detected libs to LDLIBS explicitly
74 set LIBS [get-define LIBS]
76 cc-check-types "long long"
78 define CCOPTS ""
79 define CXXOPTS ""
80 if {[cctest -cflags -fno-unwind-tables]} {
81 define-append CCOPTS -fno-unwind-tables
83 if {[cctest -cflags -fno-asynchronous-unwind-tables]} {
84 define-append CCOPTS -fno-asynchronous-unwind-tables
87 cc-check-includes sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h
88 cc-check-includes sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h
90 define LDLIBS ""
92 # Haiku needs -lnetwork, Solaris needs -lnsl
93 if {[cc-check-function-in-lib inet_ntop {nsl network}]} {
94 # This does nothing if no libs are needed
95 cc-with [list -libs [get-define lib_inet_ntop]]
96 define-append LDLIBS [get-define lib_inet_ntop]
98 # Solaris needs -lsocket, Windows needs -lwsock32
99 if {[cc-check-function-in-lib socket socket]} {
100 define-append LDLIBS [get-define lib_socket]
103 cc-check-functions ualarm lstat fork vfork system select execvpe
104 cc-check-functions backtrace geteuid mkstemp realpath strptime isatty
105 cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist isascii
106 cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
107 cc-check-functions shutdown socketpair isinf isnan link symlink fsync dup
109 if {[cc-check-functions sysinfo]} {
110 cc-with {-includes sys/sysinfo.h} {
111 cc-check-members "struct sysinfo.uptime"
115 cc-with {-includes fcntl.h} {
116 cc-check-types "struct flock"
119 cc-check-lfs
120 cc-check-functions fseeko ftello
122 define TCL_LIBRARY [get-define prefix]/lib/jim
124 lassign [split [get-define host] -] host_cpu host_vendor host_os
125 # Scrub revision from the host_os
126 regsub -all {[0-9.]} $host_os {} host_os
128 switch -glob -- $host_os {
129 mingw* {
130 # We provide our own implementation of dlopen for mingw32
131 define-feature dlopen-compat
132 define-feature winconsole
133 define TCL_PLATFORM_OS $host_os
134 define TCL_PLATFORM_PLATFORM windows
135 define TCL_PLATFORM_PATH_SEPARATOR {;}
137 default {
138 # Note that cygwin is considered a unix platform
139 define TCL_PLATFORM_OS $host_os
140 define TCL_PLATFORM_PLATFORM unix
141 define TCL_PLATFORM_PATH_SEPARATOR :
145 # Find some tools
146 cc-check-tools ar ranlib strip
147 define tclsh [info nameofexecutable]
149 if {![cc-check-functions _NSGetEnviron]} {
150 msg-checking "Checking environ declared in unistd.h..."
151 if {[cctest -cflags {-D_GNU_SOURCE -D_POSIX_SOURCE} -includes unistd.h -code {char **ep = environ;}]} {
152 define NO_ENVIRON_EXTERN
153 msg-result "yes"
154 } else {
155 msg-result "no"
159 # Windows has a mkdir with no permission arg
160 cc-check-includes sys/types.h sys/stat.h
161 msg-checking "Checking for mkdir with one arg..."
162 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
163 define HAVE_MKDIR_ONE_ARG
164 msg-result yes
165 } else {
166 msg-result no
169 set extra_objs {}
170 set jimregexp 0
172 # Returns 1 if either the given option is enabled, or
173 # --full is enabled and the option isn't explicitly disabled
175 proc opt-bool-or-full {opt} {
176 if {[opt-bool $opt]} {
177 return 1
179 if {[opt-bool full] && [opt-bool -nodefault $opt] != 0} {
180 return 1
182 return 0
185 if {[opt-bool-or-full utf8]} {
186 msg-result "Enabling UTF-8"
187 define JIM_UTF8
188 define-append CCOPTS -DUSE_UTF8
189 define PARSE_UNIDATA_FLAGS ""
190 incr jimregexp
191 } else {
192 define JIM_UTF8 0
194 if {[opt-bool maintainer]} {
195 msg-result "Enabling maintainer settings"
196 define JIM_MAINTAINER
198 # If --math or --full and not --disable-math
199 if {[opt-bool-or-full math]} {
200 msg-result "Enabling math functions"
201 define JIM_MATH_FUNCTIONS
202 cc-check-function-in-lib sin m
203 define-append LDLIBS [get-define lib_sin]
205 if {[opt-bool-or-full ipv6]} {
206 msg-result "Enabling IPv6"
207 define JIM_IPV6
209 if {[opt-bool-or-full ssl]} {
210 if {[pkg-config-init 0]} {
211 foreach pkg {openssl libssl} {
212 if {[pkg-config $pkg]} {
213 define JIM_SSL
214 define-append LDLIBS [pkg-config-get $pkg LIBS]
215 define-append LDFLAGS [pkg-config-get $pkg LDFLAGS]
216 define-append CCOPTS [pkg-config-get $pkg CFLAGS]
217 msg-result "Enabling SSL ($pkg)"
218 break
222 if {![is-defined JIM_SSL]} {
223 if {[cc-check-includes openssl/ssl.h] && [cc-check-function-in-lib ERR_error_string crypto] && [cc-check-function-in-lib TLSv1_2_method ssl]} {
224 msg-result "Enabling SSL"
225 define JIM_SSL
226 define-append LDLIBS [get-define lib_ERR_error_string] [get-define lib_TLSv1_2_method]
227 } elseif {[opt-bool ssl]} {
228 user-error "SSL support requires OpenSSL"
232 if {[opt-bool-or-full lineedit]} {
233 if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
234 msg-result "Enabling line editing"
235 define USE_LINENOISE
236 define-append CCOPTS -DNO_COMPLETION
237 define-append PARSE_UNIDATA_FLAGS -width
238 lappend extra_objs linenoise.o
241 if {[opt-bool references]} {
242 msg-result "Enabling references"
243 define JIM_REFERENCES
245 if {[opt-bool shared with-jim-shared]} {
246 msg-result "Building shared library"
247 } else {
248 msg-result "Building static library"
249 define JIM_STATICLIB
251 define LIBSOEXT [format [get-define SH_SOEXTVER] [format %.2f [expr {[get-define JIM_VERSION] / 100.0}]]]
252 define JIM_INSTALL [opt-bool install-jim]
253 define JIM_DOCS [opt-bool docs]
254 define JIM_RANDOMISE_HASH [opt-bool random-hash]
255 if {[opt-val docdir] ne ""} {
256 define docdir [opt-val docdir]
257 } else {
258 define docdir {${prefix}/docs/jim}
261 # Attributes of the extensions
262 # tcl=Pure Tcl extension
263 # static=Can't be built as a module
264 # optional=Not selected by default
265 # cpp=Is a C++ extension
266 global extdb
267 dict set extdb attrs {
268 aio { static }
269 array {}
270 binary { tcl }
271 clock {}
272 eventloop { static }
273 exec { static }
274 file {}
275 glob { tcl }
276 history {}
277 interp { }
278 load { static }
279 mk { cpp optional }
280 namespace { static }
281 nshelper { tcl optional }
282 oo { tcl }
283 pack {}
284 package { static }
285 posix {}
286 readdir {}
287 readline { optional }
288 regexp {}
289 rlprompt { tcl optional }
290 sdl { optional }
291 signal { static }
292 sqlite3 { optional }
293 zlib { optional }
294 stdlib { tcl static }
295 syslog {}
296 tclcompat { tcl static }
297 tclprefix {}
298 tree { tcl }
299 win32 { optional }
302 # Additional information about certain extensions
303 # dep=list of extensions which are required for this extension
304 # check=[expr] expression to evaluate to determine if the extension can be used
305 # libdep=list of 'define' symbols for dependent libraries
306 dict set extdb info {
307 binary { dep pack }
308 exec { check {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]} }
309 glob { dep readdir }
310 load { check {[have-feature dlopen-compat] || [cc-check-function-in-lib dlopen dl]} libdep lib_dlopen }
311 mk { check {[check-metakit]} libdep lib_mk }
312 namespace { dep nshelper }
313 posix { check {[have-feature waitpid]} }
314 readdir { check {[have-feature opendir]} }
315 readline { pkg-config readline check {[cc-check-function-in-lib readline readline]} libdep lib_readline}
316 rlprompt { dep readline }
317 tree { dep oo }
318 sdl { pkg-config SDL_gfx check {[cc-check-function-in-lib SDL_SetVideoMode SDL] && [cc-check-function-in-lib rectangleRGBA SDL_gfx]}
319 libdep {lib_SDL_SetVideoMode lib_rectangleRGBA}
321 signal { check {[have-feature sigaction] && [have-feature vfork]} }
322 sqlite3 { pkg-config sqlite3 check {[cc-check-function-in-lib sqlite3_prepare_v2 sqlite3]} libdep lib_sqlite3_prepare_v2 }
323 zlib { pkg-config zlib check {[cc-check-function-in-lib deflate z]} libdep lib_deflate }
324 syslog { check {[have-feature syslog]} }
325 tree { dep oo }
326 win32 { check {[have-feature windows]} }
329 # autosetup cc-check-function-in-library can't handle C++ libraries
330 proc check-metakit {} {
331 set found 0
332 msg-checking "Checking for Metakit..."
333 cc-with {-lang c++} {
334 if {[cctest -includes mk4.h -libs -lmk4 -code {c4_Storage dummy();}]} {
335 msg-result ok
336 define lib_mk -lmk4
337 incr found
338 } else {
339 msg-result "not found"
342 return $found
345 # Set up the withinfo array based on what the user selected
346 global withinfo
347 set withinfo(without) [join [opt-val {without-ext with-out-jim-ext}]]
348 set withinfo(ext) [join [opt-val {with-ext with-jim-ext}]]
349 set withinfo(mod) [join [opt-val {with-mod with-jim-extmod}]]
350 set withinfo(nodefault) 0
351 if {$withinfo(without) eq "default"} {
352 set withinfo(without) {}
353 set withinfo(nodefault) 1
356 # Now go check everything - see autosetup/local.tcl
357 array set extinfo [check-extensions]
359 # Now special checks
360 if {[have-feature windows]} {
361 lappend extra_objs jim-win32compat.o
363 if {[llength $extinfo(module-c)] && [get-define JIM_STATICLIB]} {
364 user-error "cygwin/mingw require --shared for dynamic modules"
367 if {[have-feature termios.h]} {
368 lappend extra_objs jim-tty.o
371 if {[ext-get-status regexp] in {y m}} {
372 if {![have-feature regcomp]} {
373 # No regcomp means we need to use the built-in version
374 incr jimregexp
378 if {$jimregexp || [opt-bool jim-regexp]} {
379 msg-result "Using built-in regexp"
380 define JIM_REGEXP
382 # If the built-in regexp overrides the system regcomp, etc.
383 # jim must be built shared so that the correct symbols are found
384 if {[ext-get-status regexp] eq "m" && [get-define JIM_STATICLIB] && [have-feature regcomp]} {
385 user-error "Must use --shared with regexp module and built-in regexp"
389 if {[ext-get-status load] eq "n"} {
390 # If we don't have load, no need to support shared objects
391 define SH_LINKFLAGS ""
394 msg-result "Jim static extensions: [lsort [concat $extinfo(static-tcl) $extinfo(static-c)]]"
395 if {[llength $extinfo(module-tcl)]} {
396 msg-result "Jim Tcl extensions: [lsort $extinfo(module-tcl)]"
398 if {[llength $extinfo(module-c)]} {
399 msg-result "Jim dynamic extensions: [lsort $extinfo(module-c)]"
402 define STATIC_EXTS [concat $extinfo(static-c) $extinfo(static-tcl)]
403 define C_EXT_OBJS [prefix jim- [suffix .o $extinfo(static-c)]]
404 define TCL_EXT_OBJS [suffix .o $extinfo(static-tcl)]
405 define C_EXT_SHOBJS [suffix .so $extinfo(module-c)]
406 define TCL_EXTS [suffix .tcl $extinfo(module-tcl)]
407 define EXTRA_OBJS $extra_objs
409 # Restore the user-specified LIBS
410 define LIBS $LIBS
412 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8} -bare JIM_VERSION -none *
413 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_* _FILE_OFFSET*}
414 make-template Makefile.in
415 make-template build-jim-ext.in
417 catch {exec chmod +x build-jim-ext}