string map and string compare now support embedded nulls
[jimtcl.git] / auto.def
blobfe6e4a22184b90525fe43ab57beb326f7ad81044
1 # vim:se syn=tcl:
4 define JIM_VERSION 79
6 options-defaults {
7 silent-rules 1
10 # Note: modules which support options *must* be included before 'options'
11 use cc cc-shared cc-db cc-lib pkg-config util
12 use local
14 options {
15 utf8 => "include support for utf8-encoded strings"
16 lineedit=1 => "disable line editing"
17 references=1 => "disable support for references"
18 math => "include support for math functions"
19 ssl => "include ssl/tls support in the aio extension"
20 ipv6 => "include ipv6 support in the aio extension"
21 maintainer => {enable the [debug] command and JimPanic}
22 full => "Enable some optional features: ipv6, ssl, math, utf8, binary, oo, tree"
23 with-jim-shared shared => "build a shared library instead of a static library"
24 jim-regexp=1 => "prefer POSIX regex if over the the built-in (Tcl-compatible) regex"
25 docs=1 => "don't build or install the documentation"
26 docdir:path => "path to install docs (if built)"
27 random-hash => "randomise hash tables. more secure but hash table results are not predicable"
28 with-jim-ext: {with-ext:"ext1,ext2,..."} => {
29 Specify additional jim extensions to include.
30 These are enabled by default:
32 aio - ANSI I/O, including open and socket
33 eventloop - after, vwait, update
34 array - Tcl-compatible array command
35 clock - Tcl-compatible clock command
36 exec - Tcl-compatible exec command
37 file - Tcl-compatible file command
38 glob - Tcl-compatible glob command
39 history - Tcl access to interactive history
40 readdir - Required for glob
41 package - Package management with the package command
42 load - Load binary extensions at runtime with load or package
43 posix - Posix APIs including os.fork, os.uptime
44 regexp - Tcl-compatible regexp, regsub commands
45 signal - Signal handling
46 stdlib - Built-in commands including lassign, lambda, alias
47 syslog - System logging with syslog
48 tclcompat - Tcl compatible read, gets, puts, parray, case, ...
49 namespace - Tcl compatible namespace support
51 These are disabled by default, but enabled by --full:
53 oo - Jim OO extension
54 tree - OO tree structure, similar to tcllib ::struct::tree
55 binary - Tcl-compatible 'binary' command
56 tclprefix - Support for the tcl::prefix command
57 zlib - Interface to zlib
58 json - JSON encode/decode
60 These are disabled unless explicitly enabled:
62 readline - Interface to libreadline
63 rlprompt - Tcl wrapper around the readline extension
64 mk - Interface to Metakit
65 sqlite3 - Interface to sqlite3
66 win32 - Interface to win32
68 with-out-jim-ext: {without-ext:"default|ext1,ext2,..."} => {
69 Specify jim extensions to exclude.
70 If 'default' is given, the default extensions will not be added.
72 with-jim-extmod: {with-mod:"ext1,ext2,..."} => {
73 Specify jim extensions to build as separate modules (either C or Tcl).
74 Note that not all extensions can be built as loadable modules.
76 # To help out openocd with automake
77 install-jim=1
80 # Save the user-specified LIBS
81 # We add detected libs to LDLIBS explicitly
82 set LIBS [get-define LIBS]
84 # In case -Werror is passed in CFLAGS, set -Wno-error when doing checks
85 # to prevent warnings from becoming errors
86 if {"-Werror" in [get-define CFLAGS] && [cctest -cflags -Wno-error]} {
87 cc-with {-cflags -Wno-error}
90 cc-check-types "long long"
91 cc-check-sizeof int
93 define CCOPTS ""
94 define CXXOPTS ""
95 if {[cctest -cflags -fno-unwind-tables]} {
96 define-append CCOPTS -fno-unwind-tables
98 if {[cctest -cflags -fno-asynchronous-unwind-tables]} {
99 define-append CCOPTS -fno-asynchronous-unwind-tables
102 cc-check-includes sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h
103 cc-check-includes sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h
105 define LDLIBS ""
107 # Haiku needs -lnetwork, Solaris needs -lnsl
108 if {[cc-check-function-in-lib inet_ntop {nsl network}]} {
109 # This does nothing if no libs are needed
110 cc-with [list -libs [get-define lib_inet_ntop]]
111 define-append LDLIBS [get-define lib_inet_ntop]
113 # Solaris needs -lsocket, Windows needs -lwsock32
114 if {[cc-check-function-in-lib socket socket]} {
115 define-append LDLIBS [get-define lib_socket]
118 cc-check-functions ualarm lstat fork vfork system select execvpe
119 cc-check-functions geteuid mkstemp realpath isatty
120 cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist isascii
121 cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
122 cc-check-functions shutdown socketpair isinf isnan link symlink fsync dup umask
123 cc-check-functions localtime gmtime strptime clock_gettime
125 if {[cc-check-function-in-lib backtrace execinfo]} {
126 define-append LDLIBS [get-define lib_backtrace]
129 if {[cc-check-functions sysinfo]} {
130 cc-with {-includes sys/sysinfo.h} {
131 cc-check-members "struct sysinfo.uptime"
135 cc-with {-includes {sys/types.h sys/stat.h}} {
136 cc-check-members "struct stat.st_mtimespec"
137 cc-check-members "struct stat.st_mtim"
140 cc-with {-includes fcntl.h} {
141 cc-check-types "struct flock"
144 cc-check-lfs
145 cc-check-functions fseeko ftello
147 define TCL_LIBRARY [get-define prefix]/lib/jim
149 lassign [split [get-define host] -] host_cpu host_vendor host_os
150 # Scrub revision from the host_os
151 regsub -all {[0-9.]} $host_os {} host_os
153 switch -glob -- $host_os {
154 mingw* {
155 # We provide our own implementation of dlopen for mingw32
156 define-feature dlopen-compat
157 define-feature winconsole
158 define TCL_PLATFORM_OS $host_os
159 define TCL_PLATFORM_PLATFORM windows
160 define TCL_PLATFORM_PATH_SEPARATOR {;}
162 default {
163 # Note that cygwin is considered a unix platform
164 define TCL_PLATFORM_OS $host_os
165 define TCL_PLATFORM_PLATFORM unix
166 define TCL_PLATFORM_PATH_SEPARATOR :
170 # Find some tools
171 cc-check-tools ar ranlib strip
172 define tclsh [info nameofexecutable]
174 # We only support silent-rules for GNU Make
175 define NO_SILENT_RULES
176 if {[get-define AM_SILENT_RULES 0]} {
177 if {[cc-check-progs [get-define MAKE make]]} {
178 # Are we using GNU make?
179 catch {exec [get-define MAKE] --version} makeversion
180 if {[string match "GNU Make*" $makeversion]} {
181 define NO_SILENT_RULES 0
186 if {[opt-bool docs]} {
187 if {[cc-check-progs asciidoc sed]} {
188 define INSTALL_DOCS docs
189 define HAVE_ASCIIDOC
190 } else {
191 define INSTALL_DOCS shipped
193 } else {
194 define INSTALL_DOCS nodocs
197 if {![cc-check-functions _NSGetEnviron]} {
198 msg-checking "Checking environ declared in unistd.h..."
199 if {[cctest -cflags {-D_GNU_SOURCE -D_POSIX_SOURCE} -includes unistd.h -code {char **ep = environ;}]} {
200 define NO_ENVIRON_EXTERN
201 msg-result "yes"
202 } else {
203 msg-result "no"
207 # Windows has a mkdir with no permission arg
208 cc-check-includes sys/types.h sys/stat.h
209 msg-checking "Checking for mkdir with one arg..."
210 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
211 define HAVE_MKDIR_ONE_ARG
212 msg-result yes
213 } else {
214 msg-result no
217 cc-with {-includes sys/stat.h} {
218 foreach i {S_IXUSR S_IRWXG S_IRWXO} {
219 if {![cc-check-decls $i]} {
220 define $i 0
225 set extra_objs {}
226 set jimregexp 0
228 # Returns 1 if either the given option is enabled, or
229 # --full is enabled and the option isn't explicitly disabled
231 proc opt-bool-or-full {opt} {
232 if {[opt-bool $opt]} {
233 return 1
235 if {[opt-bool full] && [opt-bool -nodefault $opt] != 0} {
236 return 1
238 return 0
241 if {[opt-bool-or-full utf8]} {
242 msg-result "Enabling UTF-8"
243 define JIM_UTF8
244 define-append CCOPTS -DUSE_UTF8
245 define PARSE_UNIDATA_FLAGS ""
246 incr jimregexp
247 } else {
248 define JIM_UTF8 0
250 if {[opt-bool maintainer]} {
251 msg-result "Enabling maintainer settings"
252 define JIM_MAINTAINER
254 # If --math or --full and not --disable-math
255 if {[opt-bool-or-full math]} {
256 msg-result "Enabling math functions"
257 define JIM_MATH_FUNCTIONS
258 cc-check-function-in-lib sin m
259 define-append LDLIBS [get-define lib_sin]
261 if {[opt-bool-or-full ipv6]} {
262 msg-result "Enabling IPv6"
263 define JIM_IPV6
265 define-append PKG_CONFIG_REQUIRES ""
266 if {[opt-bool-or-full ssl]} {
267 if {[pkg-config-init 0]} {
268 foreach pkg {openssl libssl} {
269 if {[pkg-config $pkg]} {
270 define JIM_SSL
271 define-append LDLIBS [pkg-config-get $pkg LIBS]
272 define-append LDFLAGS [pkg-config-get $pkg LDFLAGS]
273 define-append CCOPTS [pkg-config-get $pkg CFLAGS]
274 msg-result "Enabling SSL ($pkg)"
275 define-append PKG_CONFIG_REQUIRES $pkg
276 break
280 if {![is-defined JIM_SSL]} {
281 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]} {
282 msg-result "Enabling SSL"
283 define JIM_SSL
284 define-append LDLIBS [get-define lib_ERR_error_string] [get-define lib_TLSv1_2_method]
285 } elseif {[opt-bool ssl]} {
286 user-error "SSL support requires OpenSSL"
289 # Later versions deprecate TLSv1_2_method, but older versions don't have TLS_method
290 if {![cc-check-function-in-lib TLS_method ssl]} {
291 define-append CCOPTS -DUSE_TLSv1_2_method
294 if {[opt-bool-or-full lineedit]} {
295 if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
296 msg-result "Enabling line editing"
297 define USE_LINENOISE
298 define-append PARSE_UNIDATA_FLAGS -width
299 lappend extra_objs linenoise.o
300 if {[cc-check-inline] && [is-defined inline]} {
301 define-append CCOPTS -Dinline=[get-define inline]
305 if {[opt-bool references]} {
306 msg-result "Enabling references"
307 define JIM_REFERENCES
309 if {[opt-bool shared with-jim-shared]} {
310 msg-result "Building shared library"
311 } else {
312 msg-result "Building static library"
313 define JIM_STATICLIB
315 define VERSION [format %.2f [expr {[get-define JIM_VERSION] / 100.0}]]
316 define LIBSOEXT [format [get-define SH_SOEXTVER] [get-define VERSION]]
317 if {[get-define libdir] ni {/lib /usr/lib}} {
318 define SH_LINKRPATH_FLAGS [format [get-define SH_LINKRPATH] [get-define libdir]]
319 } else {
320 define SH_LINKRPATH_FLAGS ""
322 define JIM_INSTALL [opt-bool install-jim]
323 define JIM_DOCS [opt-bool docs]
324 define JIM_RANDOMISE_HASH [opt-bool random-hash]
325 define docdir [opt-str docdir o {${prefix}/docs/jim}]
327 # Attributes of the extensions
328 # tcl=Pure Tcl extension
329 # static=Can't be built as a module
330 # off=Off unless explicitly enabled
331 # optional=Off by default, but selected by --full
332 # cpp=Is a C++ extension
333 global extdb
334 dict set extdb attrs {
335 aio { static }
336 array {}
337 binary { tcl optional }
338 clock {}
339 eventloop { static }
340 exec { static }
341 file {}
342 glob { tcl }
343 history {}
344 interp { }
345 json { optional }
346 jsonencode { tcl optional }
347 load { static }
348 mk { cpp off }
349 namespace { static }
350 nshelper { tcl optional }
351 oo { tcl }
352 pack {}
353 package { static }
354 posix {}
355 readdir {}
356 readline { off }
357 regexp {}
358 rlprompt { tcl off }
359 sdl { off }
360 signal { static }
361 sqlite3 { off }
362 zlib { optional }
363 stdlib { tcl static }
364 syslog {}
365 tclcompat { tcl static }
366 tclprefix { optional }
367 tree { tcl }
368 win32 { off }
371 # Additional information about certain extensions
372 # dep=list of extensions which are required for this extension
373 # check=[expr] expression to evaluate to determine if the extension can be used
374 # libdep=list of 'define' symbols for dependent libraries
375 dict set extdb info {
376 binary { dep pack }
377 exec { check {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]} }
378 glob { dep readdir }
379 load { check {[have-feature dlopen-compat] || [cc-check-function-in-lib dlopen dl]} libdep lib_dlopen }
380 mk { check {[check-metakit]} libdep lib_mk }
381 namespace { dep nshelper }
382 json { dep jsonencode extrasrcs jsmn/jsmn.c }
383 posix { check {[have-feature waitpid]} }
384 readdir { check {[have-feature opendir]} }
385 readline { pkg-config readline check {[cc-check-function-in-lib readline readline]} libdep lib_readline}
386 rlprompt { dep readline }
387 tree { dep oo }
388 sdl { pkg-config SDL_gfx check {[cc-check-function-in-lib SDL_SetVideoMode SDL] && [cc-check-function-in-lib rectangleRGBA SDL_gfx]}
389 libdep {lib_SDL_SetVideoMode lib_rectangleRGBA}
391 signal { check {[have-feature sigaction]} }
392 sqlite3 { pkg-config sqlite3 check {[cc-check-function-in-lib sqlite3_prepare_v2 sqlite3]} libdep lib_sqlite3_prepare_v2 }
393 zlib { pkg-config zlib check {[cc-check-function-in-lib deflate z]} libdep lib_deflate }
394 syslog { check {[have-feature syslog]} }
395 tree { dep oo }
396 win32 { check {[have-feature windows]} }
399 # autosetup cc-check-function-in-library can't handle C++ libraries
400 proc check-metakit {} {
401 set found 0
402 msg-checking "Checking for Metakit..."
403 cc-with {-lang c++} {
404 if {[cctest -includes mk4.h -libs -lmk4 -code {c4_Storage dummy();}]} {
405 msg-result ok
406 define lib_mk -lmk4
407 incr found
408 } else {
409 msg-result "not found"
412 return $found
415 # Takes a list of module names, separated by spaces or commas
416 # and returns them as a single list
417 proc join-ext-names {list} {
418 set result {}
419 # Replace comma with space in each list then concatenate the result
420 foreach l $list {
421 lappend result {*}[string map {, " "} $l]
423 return $result
426 # Set up the withinfo array based on what the user selected
427 global withinfo
428 set withinfo(without) [join-ext-names [opt-val {without-ext with-out-jim-ext}]]
429 set withinfo(ext) [join-ext-names [opt-val {with-ext with-jim-ext}]]
430 set withinfo(mod) [join-ext-names [opt-val {with-mod with-jim-extmod}]]
431 set withinfo(nodefault) 0
432 set withinfo(optional) [opt-bool full]
433 if {$withinfo(without) eq "default"} {
434 set withinfo(without) {}
435 set withinfo(nodefault) 1
438 # Now go check everything - see autosetup/local.tcl
439 array set extinfo [check-extensions]
441 # Now special checks
442 if {[have-feature windows]} {
443 lappend extra_objs jim-win32compat.o
445 if {[llength $extinfo(module-c)] && [get-define JIM_STATICLIB]} {
446 user-error "cygwin/mingw require --shared for dynamic modules"
449 if {[have-feature termios.h]} {
450 lappend extra_objs jim-tty.o
453 if {[ext-get-status regexp] in {y m}} {
454 if {![have-feature regcomp]} {
455 # No regcomp means we need to use the built-in version
456 incr jimregexp
460 if {$jimregexp || [opt-bool jim-regexp]} {
461 msg-result "Using built-in regexp"
462 define JIM_REGEXP
464 # If the built-in regexp overrides the system regcomp, etc.
465 # jim must be built shared so that the correct symbols are found
466 if {[ext-get-status regexp] eq "m" && [get-define JIM_STATICLIB] && [have-feature regcomp]} {
467 user-error "Must use --shared with regexp module and built-in regexp"
471 foreach mod $extinfo(static-c) {
472 if {[dict exists $extdb info $mod extrasrcs]} {
473 foreach src [dict get $extdb info $mod extrasrcs] {
474 # In case we are building out-of-tree and $src is in a subdir
475 file mkdir [file dirname $src]
476 lappend extra_objs {*}[file rootname $src].o
481 # poor-man's signals
482 if {"signal" ni $extinfo(static-c)} {
483 lappend extra_objs jim-nosignal.o
486 if {[ext-get-status load] eq "n"} {
487 # If we don't have load, no need to support shared objects
488 define SH_LINKFLAGS ""
491 # Are we cross compiling?
492 if {[get-define host] ne [get-define build]} {
493 define cross_compiling 1
494 } else {
495 define cross_compiling 0
498 msg-result "Jim static extensions: [lsort [concat $extinfo(static-tcl) $extinfo(static-c)]]"
499 if {[llength $extinfo(module-tcl)]} {
500 msg-result "Jim Tcl extensions: [lsort $extinfo(module-tcl)]"
502 if {[llength $extinfo(module-c)]} {
503 msg-result "Jim dynamic extensions: [lsort $extinfo(module-c)]"
506 define STATIC_EXTS [concat $extinfo(static-c) $extinfo(static-tcl)]
507 define C_EXT_OBJS [prefix jim- [suffix .o $extinfo(static-c)]]
508 define TCL_EXT_OBJS [suffix .o $extinfo(static-tcl)]
509 define C_EXT_SHOBJS [suffix .so $extinfo(module-c)]
510 define TCL_EXTS [suffix .tcl $extinfo(module-tcl)]
511 define EXTRA_OBJS $extra_objs
513 # Restore the user-specified LIBS
514 define LIBS $LIBS
516 # Now generate the Makefile rules to build the external C shared objects
517 # It is easier to do this here rather than listing them out explicitly in Makefile.in
518 set lines {}
519 foreach mod $extinfo(module-c) {
520 set objs {}
521 set libs [get-define LDLIBS_$mod]
522 set srcs jim-$mod.c
523 if {[dict exists $extdb info $mod extrasrcs]} {
524 lappend srcs {*}[dict get $extdb info $mod extrasrcs]
526 lappend lines "$mod.so: $srcs"
527 foreach src $srcs {
528 set obj [file rootname $src].o
529 lappend objs $obj
530 lappend lines "\t\$(ECHO)\t\"\tCC\t$obj\""
531 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(SHOBJ_CFLAGS) -c -o $obj $src"
533 lappend lines "\t\$(ECHO)\t\"\tLDSO\t\$@\""
534 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(LDFLAGS) \$(SHOBJ_LDFLAGS) -o \$@ $objs \$(SH_LIBJIM) $libs"
535 lappend lines ""
537 define BUILD_SHOBJS [join $lines \n]
539 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8 SIZEOF_INT} -bare JIM_VERSION -none *
540 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_* _FILE_OFFSET*} -bare {S_I*}
541 make-template Makefile.in
542 make-template tests/Makefile.in
543 make-template build-jim-ext.in
544 make-template jimtcl.pc.in
546 catch {exec chmod +x build-jim-ext}