apply: ignore the current namespace
[jimtcl.git] / auto.def
blob681c9130dac19d3586e9f1815d6babb04b9eb446
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 time.h 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 # Check sizeof time_t so we can warn on non-Y2038 compliance
106 cc-with {-includes time.h} {
107 cc-check-sizeof time_t
110 define LDLIBS ""
112 # Haiku needs -lnetwork, Solaris needs -lnsl
113 if {[cc-check-function-in-lib inet_ntop {nsl network}]} {
114 # This does nothing if no libs are needed
115 cc-with [list -libs [get-define lib_inet_ntop]]
116 define-append LDLIBS [get-define lib_inet_ntop]
118 # Solaris needs -lsocket, Windows needs -lwsock32
119 if {[cc-check-function-in-lib socket socket]} {
120 define-append LDLIBS [get-define lib_socket]
123 cc-check-functions ualarm lstat fork vfork system select execvpe
124 cc-check-functions geteuid mkstemp realpath isatty
125 cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist isascii
126 cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
127 cc-check-functions shutdown socketpair isinf isnan link symlink fsync dup umask
128 cc-check-functions localtime gmtime strptime clock_gettime
130 if {[cc-check-function-in-lib backtrace execinfo]} {
131 define-append LDLIBS [get-define lib_backtrace]
134 if {[cc-check-functions sysinfo]} {
135 cc-with {-includes sys/sysinfo.h} {
136 cc-check-members "struct sysinfo.uptime"
140 cc-with {-includes {sys/types.h sys/stat.h}} {
141 cc-check-members "struct stat.st_mtimespec"
142 cc-check-members "struct stat.st_mtim"
145 cc-with {-includes fcntl.h} {
146 cc-check-types "struct flock"
149 cc-check-lfs
150 cc-check-functions fseeko ftello
152 define TCL_LIBRARY [get-define prefix]/lib/jim
154 lassign [split [get-define host] -] host_cpu host_vendor host_os
155 # Scrub revision from the host_os
156 regsub -all {[0-9.]} $host_os {} host_os
158 switch -glob -- $host_os {
159 mingw* {
160 # We provide our own implementation of dlopen for mingw32
161 define-feature dlopen-compat
162 define-feature winconsole
163 define TCL_PLATFORM_OS $host_os
164 define TCL_PLATFORM_PLATFORM windows
165 define TCL_PLATFORM_PATH_SEPARATOR {;}
167 default {
168 # Note that cygwin is considered a unix platform
169 define TCL_PLATFORM_OS $host_os
170 define TCL_PLATFORM_PLATFORM unix
171 define TCL_PLATFORM_PATH_SEPARATOR :
175 # Find some tools
176 cc-check-tools ar ranlib strip
177 define tclsh [info nameofexecutable]
179 # We only support silent-rules for GNU Make
180 define NO_SILENT_RULES
181 if {[get-define AM_SILENT_RULES 0]} {
182 if {[cc-check-progs [get-define MAKE make]]} {
183 # Are we using GNU make?
184 catch {exec [get-define MAKE] --version} makeversion
185 if {[string match "GNU Make*" $makeversion]} {
186 define NO_SILENT_RULES 0
191 if {[opt-bool docs]} {
192 if {[cc-check-progs asciidoc sed]} {
193 define INSTALL_DOCS docs
194 define HAVE_ASCIIDOC
195 } else {
196 define INSTALL_DOCS shipped
198 } else {
199 define INSTALL_DOCS nodocs
202 if {![cc-check-functions _NSGetEnviron]} {
203 msg-checking "Checking environ declared in unistd.h..."
204 if {[cctest -cflags {-D_GNU_SOURCE -D_POSIX_SOURCE} -includes unistd.h -code {char **ep = environ;}]} {
205 define NO_ENVIRON_EXTERN
206 msg-result "yes"
207 } else {
208 msg-result "no"
212 # Windows has a mkdir with no permission arg
213 cc-check-includes sys/types.h sys/stat.h
214 msg-checking "Checking for mkdir with one arg..."
215 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
216 define HAVE_MKDIR_ONE_ARG
217 msg-result yes
218 } else {
219 msg-result no
222 cc-with {-includes sys/stat.h} {
223 foreach i {S_IXUSR S_IRWXG S_IRWXO} {
224 if {![cc-check-decls $i]} {
225 define $i 0
230 set extra_objs {}
231 set jimregexp 0
233 # Returns 1 if either the given option is enabled, or
234 # --full is enabled and the option isn't explicitly disabled
236 proc opt-bool-or-full {opt} {
237 if {[opt-bool $opt]} {
238 return 1
240 if {[opt-bool full] && [opt-bool -nodefault $opt] != 0} {
241 return 1
243 return 0
246 if {[opt-bool-or-full utf8]} {
247 msg-result "Enabling UTF-8"
248 define JIM_UTF8
249 define-append CCOPTS -DUSE_UTF8
250 define PARSE_UNIDATA_FLAGS ""
251 incr jimregexp
252 } else {
253 define JIM_UTF8 0
255 if {[opt-bool maintainer]} {
256 msg-result "Enabling maintainer settings"
257 define JIM_MAINTAINER
259 # If --math or --full and not --disable-math
260 if {[opt-bool-or-full math]} {
261 msg-result "Enabling math functions"
262 define JIM_MATH_FUNCTIONS
263 cc-check-function-in-lib sin m
264 define-append LDLIBS [get-define lib_sin]
266 if {[opt-bool-or-full ipv6]} {
267 msg-result "Enabling IPv6"
268 define JIM_IPV6
270 define-append PKG_CONFIG_REQUIRES ""
271 if {[opt-bool-or-full ssl]} {
272 if {[pkg-config-init 0]} {
273 foreach pkg {openssl libssl} {
274 if {[pkg-config $pkg]} {
275 define JIM_SSL
276 define-append LDLIBS [pkg-config-get $pkg LIBS]
277 define-append LDFLAGS [pkg-config-get $pkg LDFLAGS]
278 define-append CCOPTS [pkg-config-get $pkg CFLAGS]
279 msg-result "Enabling SSL ($pkg)"
280 define-append PKG_CONFIG_REQUIRES $pkg
281 break
285 if {![is-defined JIM_SSL]} {
286 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]} {
287 msg-result "Enabling SSL"
288 define JIM_SSL
289 define-append LDLIBS [get-define lib_ERR_error_string] [get-define lib_TLSv1_2_method]
290 } elseif {[opt-bool ssl]} {
291 user-error "SSL support requires OpenSSL"
294 # Later versions deprecate TLSv1_2_method, but older versions don't have TLS_method
295 if {![cc-check-function-in-lib TLS_method ssl]} {
296 define-append CCOPTS -DUSE_TLSv1_2_method
299 if {[opt-bool-or-full lineedit]} {
300 if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
301 msg-result "Enabling line editing"
302 define USE_LINENOISE
303 define-append PARSE_UNIDATA_FLAGS -width
304 lappend extra_objs linenoise.o
305 if {[cc-check-inline] && [is-defined inline]} {
306 define-append CCOPTS -Dinline=[get-define inline]
310 if {[opt-bool references]} {
311 msg-result "Enabling references"
312 define JIM_REFERENCES
314 if {[opt-bool shared with-jim-shared]} {
315 msg-result "Building shared library"
316 } else {
317 msg-result "Building static library"
318 define JIM_STATICLIB
320 define VERSION [format %.2f [expr {[get-define JIM_VERSION] / 100.0}]]
321 define LIBSOEXT [format [get-define SH_SOEXTVER] [get-define VERSION]]
322 if {[get-define libdir] ni {/lib /usr/lib}} {
323 define SH_LINKRPATH_FLAGS [format [get-define SH_LINKRPATH] [get-define libdir]]
324 } else {
325 define SH_LINKRPATH_FLAGS ""
327 define JIM_INSTALL [opt-bool install-jim]
328 define JIM_DOCS [opt-bool docs]
329 define JIM_RANDOMISE_HASH [opt-bool random-hash]
330 define docdir [opt-str docdir o {${prefix}/docs/jim}]
332 # Attributes of the extensions
333 # tcl=Pure Tcl extension
334 # static=Can't be built as a module
335 # off=Off unless explicitly enabled
336 # optional=Off by default, but selected by --full
337 # cpp=Is a C++ extension
338 global extdb
339 dict set extdb attrs {
340 aio { static }
341 array {}
342 binary { tcl optional }
343 clock {}
344 eventloop { static }
345 exec { static }
346 file {}
347 glob { tcl }
348 history {}
349 interp { }
350 json { optional }
351 jsonencode { tcl optional }
352 load { static }
353 mk { cpp off }
354 namespace { static }
355 nshelper { tcl optional }
356 oo { tcl }
357 pack {}
358 package { static }
359 posix {}
360 readdir {}
361 readline { off }
362 regexp {}
363 rlprompt { tcl off }
364 sdl { off }
365 signal { static }
366 sqlite3 { off }
367 zlib { optional }
368 stdlib { tcl static }
369 syslog {}
370 tclcompat { tcl static }
371 tclprefix { optional }
372 tree { tcl }
373 win32 { off }
376 # Additional information about certain extensions
377 # dep=list of extensions which are required for this extension
378 # check=[expr] expression to evaluate to determine if the extension can be used
379 # libdep=list of 'define' symbols for dependent libraries
380 dict set extdb info {
381 binary { dep pack }
382 exec { check {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]} }
383 glob { dep readdir }
384 load { check {[have-feature dlopen-compat] || [cc-check-function-in-lib dlopen dl]} libdep lib_dlopen }
385 mk { check {[check-metakit]} libdep lib_mk }
386 namespace { dep nshelper }
387 json { dep jsonencode extrasrcs jsmn/jsmn.c }
388 posix { check {[have-feature waitpid]} }
389 readdir { check {[have-feature opendir]} }
390 readline { pkg-config readline check {[cc-check-function-in-lib readline readline]} libdep lib_readline}
391 rlprompt { dep readline }
392 tree { dep oo }
393 sdl { pkg-config SDL_gfx check {[cc-check-function-in-lib SDL_SetVideoMode SDL] && [cc-check-function-in-lib rectangleRGBA SDL_gfx]}
394 libdep {lib_SDL_SetVideoMode lib_rectangleRGBA}
396 signal { check {[have-feature sigaction]} }
397 sqlite3 { pkg-config sqlite3 check {[cc-check-function-in-lib sqlite3_prepare_v2 sqlite3]} libdep lib_sqlite3_prepare_v2 }
398 zlib { pkg-config zlib check {[cc-check-function-in-lib deflate z]} libdep lib_deflate }
399 syslog { check {[have-feature syslog]} }
400 tree { dep oo }
401 win32 { check {[have-feature windows]} }
404 # autosetup cc-check-function-in-library can't handle C++ libraries
405 proc check-metakit {} {
406 set found 0
407 msg-checking "Checking for Metakit..."
408 cc-with {-lang c++} {
409 if {[cctest -includes mk4.h -libs -lmk4 -code {c4_Storage dummy();}]} {
410 msg-result ok
411 define lib_mk -lmk4
412 incr found
413 } else {
414 msg-result "not found"
417 return $found
420 # Takes a list of module names, separated by spaces or commas
421 # and returns them as a single list
422 proc join-ext-names {list} {
423 set result {}
424 # Replace comma with space in each list then concatenate the result
425 foreach l $list {
426 lappend result {*}[string map {, " "} $l]
428 return $result
431 # Set up the withinfo array based on what the user selected
432 global withinfo
433 set withinfo(without) [join-ext-names [opt-val {without-ext with-out-jim-ext}]]
434 set withinfo(ext) [join-ext-names [opt-val {with-ext with-jim-ext}]]
435 set withinfo(mod) [join-ext-names [opt-val {with-mod with-jim-extmod}]]
436 set withinfo(nodefault) 0
437 set withinfo(optional) [opt-bool full]
438 if {$withinfo(without) eq "default"} {
439 set withinfo(without) {}
440 set withinfo(nodefault) 1
443 # Now go check everything - see autosetup/local.tcl
444 array set extinfo [check-extensions]
446 # Now special checks
447 if {[have-feature windows]} {
448 lappend extra_objs jim-win32compat.o
450 if {[llength $extinfo(module-c)] && [get-define JIM_STATICLIB]} {
451 user-error "cygwin/mingw require --shared for dynamic modules"
454 if {[have-feature termios.h]} {
455 lappend extra_objs jim-tty.o
458 if {[ext-get-status regexp] in {y m}} {
459 if {![have-feature regcomp]} {
460 # No regcomp means we need to use the built-in version
461 incr jimregexp
465 if {$jimregexp || [opt-bool jim-regexp]} {
466 msg-result "Using built-in regexp"
467 define JIM_REGEXP
469 # If the built-in regexp overrides the system regcomp, etc.
470 # jim must be built shared so that the correct symbols are found
471 if {[ext-get-status regexp] eq "m" && [get-define JIM_STATICLIB] && [have-feature regcomp]} {
472 user-error "Must use --shared with regexp module and built-in regexp"
476 foreach mod $extinfo(static-c) {
477 if {[dict exists $extdb info $mod extrasrcs]} {
478 foreach src [dict get $extdb info $mod extrasrcs] {
479 # In case we are building out-of-tree and $src is in a subdir
480 file mkdir [file dirname $src]
481 lappend extra_objs {*}[file rootname $src].o
486 # poor-man's signals
487 if {"signal" ni $extinfo(static-c)} {
488 lappend extra_objs jim-nosignal.o
491 if {[ext-get-status load] eq "n"} {
492 # If we don't have load, no need to support shared objects
493 define SH_LINKFLAGS ""
496 # Are we cross compiling?
497 if {[get-define host] ne [get-define build]} {
498 define cross_compiling 1
499 } else {
500 define cross_compiling 0
503 msg-result "Jim static extensions: [lsort [concat $extinfo(static-tcl) $extinfo(static-c)]]"
504 if {[llength $extinfo(module-tcl)]} {
505 msg-result "Jim Tcl extensions: [lsort $extinfo(module-tcl)]"
507 if {[llength $extinfo(module-c)]} {
508 msg-result "Jim dynamic extensions: [lsort $extinfo(module-c)]"
511 define STATIC_EXTS [concat $extinfo(static-c) $extinfo(static-tcl)]
512 define C_EXT_OBJS [prefix jim- [suffix .o $extinfo(static-c)]]
513 define TCL_EXT_OBJS [suffix .o $extinfo(static-tcl)]
514 define C_EXT_SHOBJS [suffix .so $extinfo(module-c)]
515 define TCL_EXTS [suffix .tcl $extinfo(module-tcl)]
516 define EXTRA_OBJS $extra_objs
518 # Restore the user-specified LIBS
519 define LIBS $LIBS
521 # Now generate the Makefile rules to build the external C shared objects
522 # It is easier to do this here rather than listing them out explicitly in Makefile.in
523 set lines {}
524 foreach mod $extinfo(module-c) {
525 set objs {}
526 set libs [get-define LDLIBS_$mod]
527 set srcs jim-$mod.c
528 if {[dict exists $extdb info $mod extrasrcs]} {
529 lappend srcs {*}[dict get $extdb info $mod extrasrcs]
531 lappend lines "$mod.so: $srcs"
532 foreach src $srcs {
533 set obj [file rootname $src].o
534 lappend objs $obj
535 lappend lines "\t\$(ECHO)\t\"\tCC\t$obj\""
536 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(SHOBJ_CFLAGS) -c -o $obj $src"
538 lappend lines "\t\$(ECHO)\t\"\tLDSO\t\$@\""
539 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(LDFLAGS) \$(SHOBJ_LDFLAGS) -o \$@ $objs \$(SH_LIBJIM) $libs"
540 lappend lines ""
542 define BUILD_SHOBJS [join $lines \n]
544 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8 SIZEOF_INT} -bare JIM_VERSION -none *
545 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_* _FILE_OFFSET*} -bare {S_I*}
546 make-template Makefile.in
547 make-template tests/Makefile.in
548 make-template examples.api/Makefile.in
549 make-template build-jim-ext.in
550 make-template jimtcl.pc.in
552 catch {exec chmod +x build-jim-ext}
554 # Finally produce any warnings
555 if {[get-define SIZEOF_TIME_T] <= 4} {
556 set note ""
557 if {[have-feature windows]} {
558 set note ", consider CFLAGS=-D__MINGW_USE_VC2005_COMPAT on mingw32"
560 user-notice "Warning: sizeof(time_t) is [get-define SIZEOF_TIME_T] -- not Y2038 compliant$note"