scan: make some structure members const
[jimtcl.git] / auto.def
blob61382efe02c6976c3fc2300dd0fffa6cd87d5b81
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 util
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, but enabled by --full:
49 oo - Jim OO extension
50 tree - OO tree structure, similar to tcllib ::struct::tree
51 binary - Tcl-compatible 'binary' command
52 tclprefix - Support for the tcl::prefix command
53 zlib - Interface to zlib
55 These are disabled unless explicitly enabled:
57 readline - Interface to libreadline
58 rlprompt - Tcl wrapper around the readline extension
59 mk - Interface to Metakit
60 sqlite3 - Interface to sqlite3
61 win32 - Interface to win32
63 with-out-jim-ext: {without-ext:"default|ext1,ext2,..."} => {
64 Specify jim extensions to exclude.
65 If 'default' is given, the default extensions will not be added.
67 with-jim-extmod: {with-mod:"ext1,ext2,..."} => {
68 Specify jim extensions to build as separate modules (either C or Tcl).
69 Note that not all extensions can be built as loadable modules.
71 # To help out openocd with automake
72 install-jim=1
75 # Save the user-specified LIBS
76 # We add detected libs to LDLIBS explicitly
77 set LIBS [get-define LIBS]
79 # In case -Werror is passed in CFLAGS, set -Wno-error when doing checks
80 # to prevent warnings from becoming errors
81 if {"-Werror" in [get-define CFLAGS] && [cctest -cflags -Wno-error]} {
82 cc-with {-cflags -Wno-error}
85 cc-check-types "long long"
87 define CCOPTS ""
88 define CXXOPTS ""
89 if {[cctest -cflags -fno-unwind-tables]} {
90 define-append CCOPTS -fno-unwind-tables
92 if {[cctest -cflags -fno-asynchronous-unwind-tables]} {
93 define-append CCOPTS -fno-asynchronous-unwind-tables
96 cc-check-includes sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h
97 cc-check-includes sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h
99 define LDLIBS ""
101 # Haiku needs -lnetwork, Solaris needs -lnsl
102 if {[cc-check-function-in-lib inet_ntop {nsl network}]} {
103 # This does nothing if no libs are needed
104 cc-with [list -libs [get-define lib_inet_ntop]]
105 define-append LDLIBS [get-define lib_inet_ntop]
107 # Solaris needs -lsocket, Windows needs -lwsock32
108 if {[cc-check-function-in-lib socket socket]} {
109 define-append LDLIBS [get-define lib_socket]
112 cc-check-functions ualarm lstat fork vfork system select execvpe
113 cc-check-functions geteuid mkstemp realpath isatty
114 cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist isascii
115 cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
116 cc-check-functions shutdown socketpair isinf isnan link symlink fsync dup umask
117 cc-check-functions localtime gmtime strptime timegm
119 if {[cc-check-function-in-lib backtrace execinfo]} {
120 define-append LDLIBS [get-define lib_backtrace]
123 if {[cc-check-functions sysinfo]} {
124 cc-with {-includes sys/sysinfo.h} {
125 cc-check-members "struct sysinfo.uptime"
129 cc-with {-includes fcntl.h} {
130 cc-check-types "struct flock"
133 cc-check-lfs
134 cc-check-functions fseeko ftello
136 define TCL_LIBRARY [get-define prefix]/lib/jim
138 lassign [split [get-define host] -] host_cpu host_vendor host_os
139 # Scrub revision from the host_os
140 regsub -all {[0-9.]} $host_os {} host_os
142 switch -glob -- $host_os {
143 mingw* {
144 # We provide our own implementation of dlopen for mingw32
145 define-feature dlopen-compat
146 define-feature winconsole
147 define TCL_PLATFORM_OS $host_os
148 define TCL_PLATFORM_PLATFORM windows
149 define TCL_PLATFORM_PATH_SEPARATOR {;}
151 default {
152 # Note that cygwin is considered a unix platform
153 define TCL_PLATFORM_OS $host_os
154 define TCL_PLATFORM_PLATFORM unix
155 define TCL_PLATFORM_PATH_SEPARATOR :
159 # Find some tools
160 cc-check-tools ar ranlib strip
161 define tclsh [info nameofexecutable]
163 if {[opt-bool docs]} {
164 if {[cc-check-progs asciidoc sed]} {
165 define INSTALL_DOCS docs
166 define HAVE_ASCIIDOC
167 } else {
168 define INSTALL_DOCS shipped
170 } else {
171 define INSTALL_DOCS nodocs
174 if {![cc-check-functions _NSGetEnviron]} {
175 msg-checking "Checking environ declared in unistd.h..."
176 if {[cctest -cflags {-D_GNU_SOURCE -D_POSIX_SOURCE} -includes unistd.h -code {char **ep = environ;}]} {
177 define NO_ENVIRON_EXTERN
178 msg-result "yes"
179 } else {
180 msg-result "no"
184 # Windows has a mkdir with no permission arg
185 cc-check-includes sys/types.h sys/stat.h
186 msg-checking "Checking for mkdir with one arg..."
187 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
188 define HAVE_MKDIR_ONE_ARG
189 msg-result yes
190 } else {
191 msg-result no
194 cc-with {-includes sys/stat.h} {
195 foreach i {S_IXUSR S_IRWXG S_IRWXO} {
196 if {![cc-check-decls $i]} {
197 define $i 0
202 set extra_objs {}
203 set jimregexp 0
205 # Returns 1 if either the given option is enabled, or
206 # --full is enabled and the option isn't explicitly disabled
208 proc opt-bool-or-full {opt} {
209 if {[opt-bool $opt]} {
210 return 1
212 if {[opt-bool full] && [opt-bool -nodefault $opt] != 0} {
213 return 1
215 return 0
218 if {[opt-bool-or-full utf8]} {
219 msg-result "Enabling UTF-8"
220 define JIM_UTF8
221 define-append CCOPTS -DUSE_UTF8
222 define PARSE_UNIDATA_FLAGS ""
223 incr jimregexp
224 } else {
225 define JIM_UTF8 0
227 if {[opt-bool maintainer]} {
228 msg-result "Enabling maintainer settings"
229 define JIM_MAINTAINER
231 # If --math or --full and not --disable-math
232 if {[opt-bool-or-full math]} {
233 msg-result "Enabling math functions"
234 define JIM_MATH_FUNCTIONS
235 cc-check-function-in-lib sin m
236 define-append LDLIBS [get-define lib_sin]
238 if {[opt-bool-or-full ipv6]} {
239 msg-result "Enabling IPv6"
240 define JIM_IPV6
242 define-append PKG_CONFIG_REQUIRES ""
243 if {[opt-bool-or-full ssl]} {
244 if {[pkg-config-init 0]} {
245 foreach pkg {openssl libssl} {
246 if {[pkg-config $pkg]} {
247 define JIM_SSL
248 define-append LDLIBS [pkg-config-get $pkg LIBS]
249 define-append LDFLAGS [pkg-config-get $pkg LDFLAGS]
250 define-append CCOPTS [pkg-config-get $pkg CFLAGS]
251 msg-result "Enabling SSL ($pkg)"
252 define-append PKG_CONFIG_REQUIRES $pkg
253 break
257 if {![is-defined JIM_SSL]} {
258 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]} {
259 msg-result "Enabling SSL"
260 define JIM_SSL
261 define-append LDLIBS [get-define lib_ERR_error_string] [get-define lib_TLSv1_2_method]
262 } elseif {[opt-bool ssl]} {
263 user-error "SSL support requires OpenSSL"
267 if {[opt-bool-or-full lineedit]} {
268 if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
269 msg-result "Enabling line editing"
270 define USE_LINENOISE
271 define-append PARSE_UNIDATA_FLAGS -width
272 lappend extra_objs linenoise.o
275 if {[opt-bool references]} {
276 msg-result "Enabling references"
277 define JIM_REFERENCES
279 if {[opt-bool shared with-jim-shared]} {
280 msg-result "Building shared library"
281 } else {
282 msg-result "Building static library"
283 define JIM_STATICLIB
285 define VERSION [format %.2f [expr {[get-define JIM_VERSION] / 100.0}]]
286 define LIBSOEXT [format [get-define SH_SOEXTVER] [get-define VERSION]]
287 define JIM_INSTALL [opt-bool install-jim]
288 define JIM_DOCS [opt-bool docs]
289 define JIM_RANDOMISE_HASH [opt-bool random-hash]
290 if {[opt-val docdir] ne ""} {
291 define docdir [lindex [opt-val docdir] end]
292 } else {
293 define docdir {${prefix}/docs/jim}
296 # Attributes of the extensions
297 # tcl=Pure Tcl extension
298 # static=Can't be built as a module
299 # off=Off unless explicitly enabled
300 # optional=Off by default, but selected by --full
301 # cpp=Is a C++ extension
302 global extdb
303 dict set extdb attrs {
304 aio { static }
305 array {}
306 binary { tcl optional }
307 clock {}
308 eventloop { static }
309 exec { static }
310 file {}
311 glob { tcl }
312 history {}
313 interp { }
314 load { static }
315 mk { cpp off }
316 namespace { static }
317 nshelper { tcl optional }
318 oo { tcl }
319 pack {}
320 package { static }
321 posix {}
322 readdir {}
323 readline { off }
324 regexp {}
325 rlprompt { tcl off }
326 sdl { off }
327 signal { static }
328 sqlite3 { off }
329 zlib { optional }
330 stdlib { tcl static }
331 syslog {}
332 tclcompat { tcl static }
333 tclprefix { optional }
334 tree { tcl }
335 win32 { off }
338 # Additional information about certain extensions
339 # dep=list of extensions which are required for this extension
340 # check=[expr] expression to evaluate to determine if the extension can be used
341 # libdep=list of 'define' symbols for dependent libraries
342 dict set extdb info {
343 binary { dep pack }
344 exec { check {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]} }
345 glob { dep readdir }
346 load { check {[have-feature dlopen-compat] || [cc-check-function-in-lib dlopen dl]} libdep lib_dlopen }
347 mk { check {[check-metakit]} libdep lib_mk }
348 namespace { dep nshelper }
349 posix { check {[have-feature waitpid]} }
350 readdir { check {[have-feature opendir]} }
351 readline { pkg-config readline check {[cc-check-function-in-lib readline readline]} libdep lib_readline}
352 rlprompt { dep readline }
353 tree { dep oo }
354 sdl { pkg-config SDL_gfx check {[cc-check-function-in-lib SDL_SetVideoMode SDL] && [cc-check-function-in-lib rectangleRGBA SDL_gfx]}
355 libdep {lib_SDL_SetVideoMode lib_rectangleRGBA}
357 signal { check {[have-feature sigaction] && [have-feature vfork]} }
358 sqlite3 { pkg-config sqlite3 check {[cc-check-function-in-lib sqlite3_prepare_v2 sqlite3]} libdep lib_sqlite3_prepare_v2 }
359 zlib { pkg-config zlib check {[cc-check-function-in-lib deflate z]} libdep lib_deflate }
360 syslog { check {[have-feature syslog]} }
361 tree { dep oo }
362 win32 { check {[have-feature windows]} }
365 # autosetup cc-check-function-in-library can't handle C++ libraries
366 proc check-metakit {} {
367 set found 0
368 msg-checking "Checking for Metakit..."
369 cc-with {-lang c++} {
370 if {[cctest -includes mk4.h -libs -lmk4 -code {c4_Storage dummy();}]} {
371 msg-result ok
372 define lib_mk -lmk4
373 incr found
374 } else {
375 msg-result "not found"
378 return $found
381 # Takes a list of module names, separated by spaces or commas
382 # and returns them as a single list
383 proc join-ext-names {list} {
384 set result {}
385 # Replace comma with space in each list then concatenate the result
386 foreach l $list {
387 lappend result {*}[string map {, " "} $l]
389 return $result
392 # Set up the withinfo array based on what the user selected
393 global withinfo
394 set withinfo(without) [join-ext-names [opt-val {without-ext with-out-jim-ext}]]
395 set withinfo(ext) [join-ext-names [opt-val {with-ext with-jim-ext}]]
396 set withinfo(mod) [join-ext-names [opt-val {with-mod with-jim-extmod}]]
397 set withinfo(nodefault) 0
398 set withinfo(optional) [opt-bool full]
399 if {$withinfo(without) eq "default"} {
400 set withinfo(without) {}
401 set withinfo(nodefault) 1
404 # Now go check everything - see autosetup/local.tcl
405 array set extinfo [check-extensions]
407 # Now special checks
408 if {[have-feature windows]} {
409 lappend extra_objs jim-win32compat.o
411 if {[llength $extinfo(module-c)] && [get-define JIM_STATICLIB]} {
412 user-error "cygwin/mingw require --shared for dynamic modules"
415 if {[have-feature termios.h]} {
416 lappend extra_objs jim-tty.o
419 if {[ext-get-status regexp] in {y m}} {
420 if {![have-feature regcomp]} {
421 # No regcomp means we need to use the built-in version
422 incr jimregexp
426 if {$jimregexp || [opt-bool jim-regexp]} {
427 msg-result "Using built-in regexp"
428 define JIM_REGEXP
430 # If the built-in regexp overrides the system regcomp, etc.
431 # jim must be built shared so that the correct symbols are found
432 if {[ext-get-status regexp] eq "m" && [get-define JIM_STATICLIB] && [have-feature regcomp]} {
433 user-error "Must use --shared with regexp module and built-in regexp"
437 if {[ext-get-status load] eq "n"} {
438 # If we don't have load, no need to support shared objects
439 define SH_LINKFLAGS ""
442 msg-result "Jim static extensions: [lsort [concat $extinfo(static-tcl) $extinfo(static-c)]]"
443 if {[llength $extinfo(module-tcl)]} {
444 msg-result "Jim Tcl extensions: [lsort $extinfo(module-tcl)]"
446 if {[llength $extinfo(module-c)]} {
447 msg-result "Jim dynamic extensions: [lsort $extinfo(module-c)]"
450 define STATIC_EXTS [concat $extinfo(static-c) $extinfo(static-tcl)]
451 define C_EXT_OBJS [prefix jim- [suffix .o $extinfo(static-c)]]
452 define TCL_EXT_OBJS [suffix .o $extinfo(static-tcl)]
453 define C_EXT_SHOBJS [suffix .so $extinfo(module-c)]
454 define TCL_EXTS [suffix .tcl $extinfo(module-tcl)]
455 define EXTRA_OBJS $extra_objs
457 # Restore the user-specified LIBS
458 define LIBS $LIBS
460 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8} -bare JIM_VERSION -none *
461 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_* _FILE_OFFSET*} -bare {S_I*}
462 make-template Makefile.in
463 make-template build-jim-ext.in
464 make-template jimtcl.pc.in
466 catch {exec chmod +x build-jim-ext}