tests: interactive.tests requires socket pty support
[jimtcl.git] / auto.def
blob7483db28564d2417226ff0f01965dbaa5e9b77cb
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 coverage => "build with code coverage support"
29 with-jim-ext: {with-ext:"ext1,ext2,..."} => {
30 Specify additional jim extensions to include.
31 These are enabled by default:
33 aio - ANSI I/O, including open and socket
34 eventloop - after, vwait, update
35 array - Tcl-compatible array command
36 clock - Tcl-compatible clock command
37 exec - Tcl-compatible exec command
38 file - Tcl-compatible file command
39 glob - Tcl-compatible glob command
40 history - Tcl access to interactive history
41 readdir - Required for glob
42 package - Package management with the package command
43 load - Load binary extensions at runtime with load or package
44 posix - Posix APIs including os.fork, os.uptime
45 regexp - Tcl-compatible regexp, regsub commands
46 signal - Signal handling
47 stdlib - Built-in commands including lassign, lambda, alias
48 syslog - System logging with syslog
49 tclcompat - Tcl compatible read, gets, puts, parray, case, ...
50 namespace - Tcl compatible namespace support
52 These are disabled by default, but enabled by --full:
54 oo - Jim OO extension
55 tree - OO tree structure, similar to tcllib ::struct::tree
56 binary - Tcl-compatible 'binary' command
57 tclprefix - Support for the tcl::prefix command
58 zlib - Interface to zlib
59 json - JSON encode/decode
61 These are disabled unless explicitly enabled:
63 readline - Interface to libreadline
64 rlprompt - Tcl wrapper around the readline extension
65 mk - Interface to Metakit
66 sqlite3 - Interface to sqlite3
67 win32 - Interface to win32
69 with-out-jim-ext: {without-ext:"default|ext1,ext2,..."} => {
70 Specify jim extensions to exclude.
71 If 'default' is given, the default extensions will not be added.
73 with-jim-extmod: {with-mod:"ext1,ext2,..."} => {
74 Specify jim extensions to build as separate modules (either C or Tcl).
75 Note that not all extensions can be built as loadable modules.
77 # To help out openocd with automake
78 install-jim=1
81 set warnings {}
83 # Save the user-specified LIBS
84 # We add detected libs to LDLIBS explicitly
85 set LIBS [get-define LIBS]
87 # In case -Werror is passed in CFLAGS, set -Wno-error when doing checks
88 # to prevent warnings from becoming errors
89 if {"-Werror" in [get-define CFLAGS] && [cctest -cflags -Wno-error]} {
90 cc-with {-cflags -Wno-error}
93 cc-check-types "long long"
94 cc-check-sizeof int
96 define CCOPTS ""
97 define CXXOPTS ""
98 if {[cctest -cflags -fno-unwind-tables]} {
99 define-append CCOPTS -fno-unwind-tables
101 if {[cctest -cflags -fno-asynchronous-unwind-tables]} {
102 define-append CCOPTS -fno-asynchronous-unwind-tables
104 if {[opt-bool coverage]} {
105 if {[cctest -link 1 -cflags --coverage]} {
106 # When using coverage, disable ccache and compiler optimisation
107 define CCACHE ""
108 define-append CCOPTS --coverage -O0
109 define-append LDFLAGS --coverage
110 define COVERAGE 1
111 if {[cc-check-progs gcovr]} {
112 define COVERAGE_TOOL gcovr
113 } elseif {[cc-check-progs lcov] && [cc-check-progs genhtml]} {
114 define COVERAGE_TOOL lcov
115 } else {
116 define COVERAGE_TOOL gcov
117 lappend warnings "Note: Neither lcov nor gcovr is available, falling back to gcov"
119 } else {
120 lappend warnings "Warning: --coverage specified, but compiler does not support --coverage"
124 cc-check-includes time.h sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h
125 cc-check-includes util.h pty.h sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h
127 # Check sizeof time_t so we can warn on non-Y2038 compliance
128 cc-with {-includes time.h} {
129 cc-check-sizeof time_t
132 define LDLIBS ""
134 # Haiku needs -lnetwork, Solaris needs -lnsl
135 if {[cc-check-function-in-lib inet_ntop {nsl network}]} {
136 # This does nothing if no libs are needed
137 cc-with [list -libs [get-define lib_inet_ntop]]
138 define-append LDLIBS [get-define lib_inet_ntop]
140 # Solaris needs -lsocket, Windows needs -lwsock32
141 if {[cc-check-function-in-lib socket socket]} {
142 define-append LDLIBS [get-define lib_socket]
145 cc-check-functions ualarm lstat fork vfork system select execvpe
146 cc-check-functions geteuid mkstemp realpath isatty
147 cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist isascii
148 cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
149 cc-check-functions shutdown socketpair isinf isnan link symlink fsync dup umask
150 cc-check-functions localtime gmtime strptime clock_gettime
152 if {[cc-check-function-in-lib backtrace execinfo]} {
153 define-append LDLIBS [get-define lib_backtrace]
155 if {[cc-check-function-in-lib openpty util]} {
156 define-append LDLIBS [get-define lib_openpty]
159 if {[cc-check-functions sysinfo]} {
160 cc-with {-includes sys/sysinfo.h} {
161 cc-check-members "struct sysinfo.uptime"
165 cc-with {-includes {sys/types.h sys/stat.h}} {
166 cc-check-members "struct stat.st_mtimespec"
167 cc-check-members "struct stat.st_mtim"
170 cc-with {-includes fcntl.h} {
171 cc-check-types "struct flock"
174 cc-check-lfs
175 cc-check-functions fseeko ftello
177 define TCL_LIBRARY [get-define prefix]/lib/jim
179 lassign [split [get-define host] -] host_cpu host_vendor host_os
180 # Scrub revision from the host_os
181 regsub -all {[0-9.]} $host_os {} host_os
183 switch -glob -- $host_os {
184 mingw* {
185 # We provide our own implementation of dlopen for mingw32
186 define-feature dlopen-compat
187 define-feature winconsole
188 define TCL_PLATFORM_OS $host_os
189 define TCL_PLATFORM_PLATFORM windows
190 define TCL_PLATFORM_PATH_SEPARATOR {;}
192 default {
193 # Note that cygwin is considered a unix platform
194 define TCL_PLATFORM_OS $host_os
195 define TCL_PLATFORM_PLATFORM unix
196 define TCL_PLATFORM_PATH_SEPARATOR :
200 # Find some tools
201 cc-check-tools ar ranlib strip
202 define tclsh [info nameofexecutable]
204 # We only support silent-rules for GNU Make
205 define NO_SILENT_RULES
206 if {[get-define AM_SILENT_RULES 0]} {
207 if {[cc-check-progs [get-define MAKE make]]} {
208 # Are we using GNU make?
209 catch {exec [get-define MAKE] --version} makeversion
210 if {[string match "GNU Make*" $makeversion]} {
211 define NO_SILENT_RULES 0
216 if {[opt-bool docs]} {
217 if {[cc-check-progs asciidoc sed]} {
218 define INSTALL_DOCS docs
219 define HAVE_ASCIIDOC
220 } else {
221 define INSTALL_DOCS shipped
223 } else {
224 define INSTALL_DOCS nodocs
227 if {![cc-check-functions _NSGetEnviron]} {
228 msg-checking "Checking environ declared in unistd.h..."
229 if {[cctest -cflags {-D_GNU_SOURCE -D_POSIX_SOURCE} -includes unistd.h -code {char **ep = environ;}]} {
230 define NO_ENVIRON_EXTERN
231 msg-result "yes"
232 } else {
233 msg-result "no"
237 # Windows has a mkdir with no permission arg
238 cc-check-includes sys/types.h sys/stat.h
239 msg-checking "Checking for mkdir with one arg..."
240 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
241 define HAVE_MKDIR_ONE_ARG
242 msg-result yes
243 } else {
244 msg-result no
247 cc-with {-includes sys/stat.h} {
248 foreach i {S_IXUSR S_IRWXG S_IRWXO} {
249 if {![cc-check-decls $i]} {
250 define $i 0
255 set extra_objs {}
256 set jimregexp 0
258 # Returns 1 if either the given option is enabled, or
259 # --full is enabled and the option isn't explicitly disabled
261 proc opt-bool-or-full {opt} {
262 if {[opt-bool $opt]} {
263 return 1
265 if {[opt-bool full] && [opt-bool -nodefault $opt] != 0} {
266 return 1
268 return 0
271 if {[opt-bool-or-full utf8]} {
272 msg-result "Enabling UTF-8"
273 define JIM_UTF8
274 define-append CCOPTS -DUSE_UTF8
275 define PARSE_UNIDATA_FLAGS ""
276 incr jimregexp
277 } else {
278 define JIM_UTF8 0
280 if {[opt-bool maintainer]} {
281 msg-result "Enabling maintainer settings"
282 define JIM_MAINTAINER
284 # If --math or --full and not --disable-math
285 if {[opt-bool-or-full math]} {
286 msg-result "Enabling math functions"
287 define JIM_MATH_FUNCTIONS
288 cc-check-function-in-lib sin m
289 define-append LDLIBS [get-define lib_sin]
291 if {[opt-bool-or-full ipv6]} {
292 msg-result "Enabling IPv6"
293 define JIM_IPV6
295 define-append PKG_CONFIG_REQUIRES ""
296 if {[opt-bool-or-full ssl]} {
297 if {[pkg-config-init 0]} {
298 foreach pkg {openssl libssl} {
299 if {[pkg-config $pkg]} {
300 define JIM_SSL
301 define-append LDLIBS [pkg-config-get $pkg LIBS]
302 define-append LDFLAGS [pkg-config-get $pkg LDFLAGS]
303 define-append CCOPTS [pkg-config-get $pkg CFLAGS]
304 msg-result "Enabling SSL ($pkg)"
305 define-append PKG_CONFIG_REQUIRES $pkg
306 break
310 if {![is-defined JIM_SSL]} {
311 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]} {
312 msg-result "Enabling SSL"
313 define JIM_SSL
314 define-append LDLIBS [get-define lib_ERR_error_string] [get-define lib_TLSv1_2_method]
315 } elseif {[opt-bool ssl]} {
316 user-error "SSL support requires OpenSSL"
319 # Later versions deprecate TLSv1_2_method, but older versions don't have TLS_method
320 if {![cc-check-function-in-lib TLS_method ssl]} {
321 define-append CCOPTS -DUSE_TLSv1_2_method
324 if {[opt-bool-or-full lineedit]} {
325 if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
326 msg-result "Enabling line editing"
327 define USE_LINENOISE
328 define-append PARSE_UNIDATA_FLAGS -width
329 lappend extra_objs linenoise.o
330 if {[cc-check-inline] && [is-defined inline]} {
331 define-append CCOPTS -Dinline=[get-define inline]
335 if {[opt-bool references]} {
336 msg-result "Enabling references"
337 define JIM_REFERENCES
339 if {[opt-bool shared with-jim-shared]} {
340 msg-result "Building shared library"
341 } else {
342 msg-result "Building static library"
343 define JIM_STATICLIB
345 define VERSION [format %.2f [expr {[get-define JIM_VERSION] / 100.0}]]
346 define LIBSOEXT [format [get-define SH_SOEXTVER] [get-define VERSION]]
347 if {[get-define libdir] ni {/lib /usr/lib}} {
348 define SH_LINKRPATH_FLAGS [format [get-define SH_LINKRPATH] [get-define libdir]]
349 } else {
350 define SH_LINKRPATH_FLAGS ""
352 define JIM_INSTALL [opt-bool install-jim]
353 define JIM_DOCS [opt-bool docs]
354 define JIM_RANDOMISE_HASH [opt-bool random-hash]
355 define docdir [opt-str docdir o {${prefix}/docs/jim}]
357 # Attributes of the extensions
358 # tcl=Pure Tcl extension
359 # static=Can't be built as a module
360 # off=Off unless explicitly enabled
361 # optional=Off by default, but selected by --full
362 # cpp=Is a C++ extension
363 global extdb
364 dict set extdb attrs {
365 aio { static }
366 array {}
367 binary { tcl optional }
368 clock {}
369 eventloop { static }
370 exec { static }
371 file {}
372 glob { tcl }
373 history {}
374 interp { }
375 json { optional }
376 jsonencode { tcl optional }
377 load { static }
378 mk { cpp off }
379 namespace { static }
380 nshelper { tcl optional }
381 oo { tcl }
382 pack {}
383 package { static }
384 posix {}
385 readdir {}
386 readline { off }
387 regexp {}
388 rlprompt { tcl off }
389 sdl { off }
390 signal { static }
391 sqlite3 { off }
392 zlib { optional }
393 stdlib { tcl static }
394 syslog {}
395 tclcompat { tcl static }
396 tclprefix { optional }
397 tree { tcl }
398 win32 { off }
401 # Additional information about certain extensions
402 # dep=list of extensions which are required for this extension
403 # check=[expr] expression to evaluate to determine if the extension can be used
404 # libdep=list of 'define' symbols for dependent libraries
405 dict set extdb info {
406 binary { dep pack }
407 exec { check {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]} }
408 glob { dep readdir }
409 load { check {[have-feature dlopen-compat] || [cc-check-function-in-lib dlopen dl]} libdep lib_dlopen }
410 mk { check {[check-metakit]} libdep lib_mk }
411 namespace { dep nshelper }
412 json { dep jsonencode extrasrcs jsmn/jsmn.c }
413 posix { check {[have-feature waitpid]} }
414 readdir { check {[have-feature opendir]} }
415 readline { pkg-config readline check {[cc-check-function-in-lib readline readline]} libdep lib_readline}
416 rlprompt { dep readline }
417 tree { dep oo }
418 sdl { pkg-config SDL_gfx check {[cc-check-function-in-lib SDL_SetVideoMode SDL] && [cc-check-function-in-lib rectangleRGBA SDL_gfx]}
419 libdep {lib_SDL_SetVideoMode lib_rectangleRGBA}
421 signal { check {[have-feature sigaction]} }
422 sqlite3 { pkg-config sqlite3 check {[cc-check-function-in-lib sqlite3_prepare_v2 sqlite3]} libdep lib_sqlite3_prepare_v2 }
423 zlib { pkg-config zlib check {[cc-check-function-in-lib deflate z]} libdep lib_deflate }
424 syslog { check {[have-feature syslog]} }
425 tree { dep oo }
426 win32 { check {[have-feature windows]} }
429 # autosetup cc-check-function-in-library can't handle C++ libraries
430 proc check-metakit {} {
431 set found 0
432 msg-checking "Checking for Metakit..."
433 cc-with {-lang c++} {
434 if {[cctest -includes mk4.h -libs -lmk4 -code {c4_Storage dummy();}]} {
435 msg-result ok
436 define lib_mk -lmk4
437 incr found
438 } else {
439 msg-result "not found"
442 return $found
445 # Takes a list of module names, separated by spaces or commas
446 # and returns them as a single list
447 proc join-ext-names {list} {
448 set result {}
449 # Replace comma with space in each list then concatenate the result
450 foreach l $list {
451 lappend result {*}[string map {, " "} $l]
453 return $result
456 # Set up the withinfo array based on what the user selected
457 global withinfo
458 set withinfo(without) [join-ext-names [opt-val {without-ext with-out-jim-ext}]]
459 set withinfo(ext) [join-ext-names [opt-val {with-ext with-jim-ext}]]
460 set withinfo(mod) [join-ext-names [opt-val {with-mod with-jim-extmod}]]
461 set withinfo(nodefault) 0
462 set withinfo(optional) [opt-bool full]
463 if {$withinfo(without) eq "default"} {
464 set withinfo(without) {}
465 set withinfo(nodefault) 1
468 # Now go check everything - see autosetup/local.tcl
469 array set extinfo [check-extensions]
471 # Now special checks
472 if {[have-feature windows]} {
473 lappend extra_objs jim-win32compat.o
475 if {[llength $extinfo(module-c)] && [get-define JIM_STATICLIB]} {
476 user-error "cygwin/mingw require --shared for dynamic modules"
479 if {[have-feature termios.h]} {
480 lappend extra_objs jim-tty.o
483 if {[ext-get-status regexp] in {y m}} {
484 if {![have-feature regcomp]} {
485 # No regcomp means we need to use the built-in version
486 incr jimregexp
490 if {$jimregexp || [opt-bool jim-regexp]} {
491 msg-result "Using built-in regexp"
492 define JIM_REGEXP
494 # If the built-in regexp overrides the system regcomp, etc.
495 # jim must be built shared so that the correct symbols are found
496 if {[ext-get-status regexp] eq "m" && [get-define JIM_STATICLIB] && [have-feature regcomp]} {
497 user-error "Must use --shared with regexp module and built-in regexp"
501 foreach mod $extinfo(static-c) {
502 if {[dict exists $extdb info $mod extrasrcs]} {
503 foreach src [dict get $extdb info $mod extrasrcs] {
504 # In case we are building out-of-tree and $src is in a subdir
505 file mkdir [file dirname $src]
506 lappend extra_objs {*}[file rootname $src].o
511 # poor-man's signals
512 if {"signal" ni $extinfo(static-c)} {
513 lappend extra_objs jim-nosignal.o
516 if {[ext-get-status load] eq "n"} {
517 # If we don't have load, no need to support shared objects
518 define SH_LINKFLAGS ""
521 # Are we cross compiling?
522 if {[get-define host] ne [get-define build]} {
523 define cross_compiling 1
524 } else {
525 define cross_compiling 0
528 msg-result "Jim static extensions: [lsort [concat $extinfo(static-tcl) $extinfo(static-c)]]"
529 if {[llength $extinfo(module-tcl)]} {
530 msg-result "Jim Tcl extensions: [lsort $extinfo(module-tcl)]"
532 if {[llength $extinfo(module-c)]} {
533 msg-result "Jim dynamic extensions: [lsort $extinfo(module-c)]"
536 define STATIC_EXTS [concat $extinfo(static-c) $extinfo(static-tcl)]
537 define C_EXT_OBJS [prefix jim- [suffix .o $extinfo(static-c)]]
538 define TCL_EXT_OBJS [suffix .o $extinfo(static-tcl)]
539 define C_EXT_SHOBJS [suffix .so $extinfo(module-c)]
540 define TCL_EXTS [suffix .tcl $extinfo(module-tcl)]
541 define EXTRA_OBJS $extra_objs
543 # Restore the user-specified LIBS
544 define LIBS $LIBS
546 # Now generate the Makefile rules to build the external C shared objects
547 # It is easier to do this here rather than listing them out explicitly in Makefile.in
548 set lines {}
549 foreach mod $extinfo(module-c) {
550 set objs {}
551 set libs [get-define LDLIBS_$mod]
552 set srcs jim-$mod.c
553 if {[dict exists $extdb info $mod extrasrcs]} {
554 lappend srcs {*}[dict get $extdb info $mod extrasrcs]
556 lappend lines "$mod.so: $srcs"
557 foreach src $srcs {
558 set obj [file rootname $src].o
559 lappend objs $obj
560 lappend lines "\t\$(ECHO)\t\"\tCC\t$obj\""
561 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(SHOBJ_CFLAGS) -c -o $obj $src"
563 lappend lines "\t\$(ECHO)\t\"\tLDSO\t\$@\""
564 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(LDFLAGS) \$(SHOBJ_LDFLAGS) -o \$@ $objs \$(SH_LIBJIM) $libs"
565 lappend lines ""
567 define BUILD_SHOBJS [join $lines \n]
569 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8 SIZEOF_INT} -bare JIM_VERSION -none *
570 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_* _FILE_OFFSET*} -bare {S_I*}
571 make-template Makefile.in
572 make-template tests/Makefile.in
573 make-template examples.api/Makefile.in
574 make-template build-jim-ext.in
575 make-template jimtcl.pc.in
577 catch {exec chmod +x build-jim-ext}
579 if {[get-define SIZEOF_TIME_T] <= 4} {
580 set note ""
581 if {[have-feature windows]} {
582 set note ", consider CFLAGS=-D__MINGW_USE_VC2005_COMPAT on mingw32"
584 lappend warnings "Warning: sizeof(time_t) is [get-define SIZEOF_TIME_T] -- not Y2038 compliant$note"
587 # Output any warnings at the end to make them easier to see
588 foreach warning $warnings {
589 user-notice $warning