local, rename: don't allow renaming a local proc with upcall
[jimtcl.git] / auto.def
blob7693e13b1d0f14e03b86c6376d7363284e552595
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 # Disable ccache when using coverage
107 define CCACHE ""
108 define-append CCOPTS --coverage
109 define-append LDFLAGS --coverage
110 define COVERAGE 1
111 if {![cc-check-progs gcovr]} {
112 lappend warnings "Note: gcovr is not available, falling back to gcov"
114 } else {
115 lappend warnings "Warning: --coverage specified, but compiler does not support --coverage"
119 cc-check-includes time.h sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h
120 cc-check-includes sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h
122 # Check sizeof time_t so we can warn on non-Y2038 compliance
123 cc-with {-includes time.h} {
124 cc-check-sizeof time_t
127 define LDLIBS ""
129 # Haiku needs -lnetwork, Solaris needs -lnsl
130 if {[cc-check-function-in-lib inet_ntop {nsl network}]} {
131 # This does nothing if no libs are needed
132 cc-with [list -libs [get-define lib_inet_ntop]]
133 define-append LDLIBS [get-define lib_inet_ntop]
135 # Solaris needs -lsocket, Windows needs -lwsock32
136 if {[cc-check-function-in-lib socket socket]} {
137 define-append LDLIBS [get-define lib_socket]
140 cc-check-functions ualarm lstat fork vfork system select execvpe
141 cc-check-functions geteuid mkstemp realpath isatty
142 cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist isascii
143 cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
144 cc-check-functions shutdown socketpair isinf isnan link symlink fsync dup umask
145 cc-check-functions localtime gmtime strptime clock_gettime
147 if {[cc-check-function-in-lib backtrace execinfo]} {
148 define-append LDLIBS [get-define lib_backtrace]
151 if {[cc-check-functions sysinfo]} {
152 cc-with {-includes sys/sysinfo.h} {
153 cc-check-members "struct sysinfo.uptime"
157 cc-with {-includes {sys/types.h sys/stat.h}} {
158 cc-check-members "struct stat.st_mtimespec"
159 cc-check-members "struct stat.st_mtim"
162 cc-with {-includes fcntl.h} {
163 cc-check-types "struct flock"
166 cc-check-lfs
167 cc-check-functions fseeko ftello
169 define TCL_LIBRARY [get-define prefix]/lib/jim
171 lassign [split [get-define host] -] host_cpu host_vendor host_os
172 # Scrub revision from the host_os
173 regsub -all {[0-9.]} $host_os {} host_os
175 switch -glob -- $host_os {
176 mingw* {
177 # We provide our own implementation of dlopen for mingw32
178 define-feature dlopen-compat
179 define-feature winconsole
180 define TCL_PLATFORM_OS $host_os
181 define TCL_PLATFORM_PLATFORM windows
182 define TCL_PLATFORM_PATH_SEPARATOR {;}
184 default {
185 # Note that cygwin is considered a unix platform
186 define TCL_PLATFORM_OS $host_os
187 define TCL_PLATFORM_PLATFORM unix
188 define TCL_PLATFORM_PATH_SEPARATOR :
192 # Find some tools
193 cc-check-tools ar ranlib strip
194 define tclsh [info nameofexecutable]
196 # We only support silent-rules for GNU Make
197 define NO_SILENT_RULES
198 if {[get-define AM_SILENT_RULES 0]} {
199 if {[cc-check-progs [get-define MAKE make]]} {
200 # Are we using GNU make?
201 catch {exec [get-define MAKE] --version} makeversion
202 if {[string match "GNU Make*" $makeversion]} {
203 define NO_SILENT_RULES 0
208 if {[opt-bool docs]} {
209 if {[cc-check-progs asciidoc sed]} {
210 define INSTALL_DOCS docs
211 define HAVE_ASCIIDOC
212 } else {
213 define INSTALL_DOCS shipped
215 } else {
216 define INSTALL_DOCS nodocs
219 if {![cc-check-functions _NSGetEnviron]} {
220 msg-checking "Checking environ declared in unistd.h..."
221 if {[cctest -cflags {-D_GNU_SOURCE -D_POSIX_SOURCE} -includes unistd.h -code {char **ep = environ;}]} {
222 define NO_ENVIRON_EXTERN
223 msg-result "yes"
224 } else {
225 msg-result "no"
229 # Windows has a mkdir with no permission arg
230 cc-check-includes sys/types.h sys/stat.h
231 msg-checking "Checking for mkdir with one arg..."
232 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
233 define HAVE_MKDIR_ONE_ARG
234 msg-result yes
235 } else {
236 msg-result no
239 cc-with {-includes sys/stat.h} {
240 foreach i {S_IXUSR S_IRWXG S_IRWXO} {
241 if {![cc-check-decls $i]} {
242 define $i 0
247 set extra_objs {}
248 set jimregexp 0
250 # Returns 1 if either the given option is enabled, or
251 # --full is enabled and the option isn't explicitly disabled
253 proc opt-bool-or-full {opt} {
254 if {[opt-bool $opt]} {
255 return 1
257 if {[opt-bool full] && [opt-bool -nodefault $opt] != 0} {
258 return 1
260 return 0
263 if {[opt-bool-or-full utf8]} {
264 msg-result "Enabling UTF-8"
265 define JIM_UTF8
266 define-append CCOPTS -DUSE_UTF8
267 define PARSE_UNIDATA_FLAGS ""
268 incr jimregexp
269 } else {
270 define JIM_UTF8 0
272 if {[opt-bool maintainer]} {
273 msg-result "Enabling maintainer settings"
274 define JIM_MAINTAINER
276 # If --math or --full and not --disable-math
277 if {[opt-bool-or-full math]} {
278 msg-result "Enabling math functions"
279 define JIM_MATH_FUNCTIONS
280 cc-check-function-in-lib sin m
281 define-append LDLIBS [get-define lib_sin]
283 if {[opt-bool-or-full ipv6]} {
284 msg-result "Enabling IPv6"
285 define JIM_IPV6
287 define-append PKG_CONFIG_REQUIRES ""
288 if {[opt-bool-or-full ssl]} {
289 if {[pkg-config-init 0]} {
290 foreach pkg {openssl libssl} {
291 if {[pkg-config $pkg]} {
292 define JIM_SSL
293 define-append LDLIBS [pkg-config-get $pkg LIBS]
294 define-append LDFLAGS [pkg-config-get $pkg LDFLAGS]
295 define-append CCOPTS [pkg-config-get $pkg CFLAGS]
296 msg-result "Enabling SSL ($pkg)"
297 define-append PKG_CONFIG_REQUIRES $pkg
298 break
302 if {![is-defined JIM_SSL]} {
303 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]} {
304 msg-result "Enabling SSL"
305 define JIM_SSL
306 define-append LDLIBS [get-define lib_ERR_error_string] [get-define lib_TLSv1_2_method]
307 } elseif {[opt-bool ssl]} {
308 user-error "SSL support requires OpenSSL"
311 # Later versions deprecate TLSv1_2_method, but older versions don't have TLS_method
312 if {![cc-check-function-in-lib TLS_method ssl]} {
313 define-append CCOPTS -DUSE_TLSv1_2_method
316 if {[opt-bool-or-full lineedit]} {
317 if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
318 msg-result "Enabling line editing"
319 define USE_LINENOISE
320 define-append PARSE_UNIDATA_FLAGS -width
321 lappend extra_objs linenoise.o
322 if {[cc-check-inline] && [is-defined inline]} {
323 define-append CCOPTS -Dinline=[get-define inline]
327 if {[opt-bool references]} {
328 msg-result "Enabling references"
329 define JIM_REFERENCES
331 if {[opt-bool shared with-jim-shared]} {
332 msg-result "Building shared library"
333 } else {
334 msg-result "Building static library"
335 define JIM_STATICLIB
337 define VERSION [format %.2f [expr {[get-define JIM_VERSION] / 100.0}]]
338 define LIBSOEXT [format [get-define SH_SOEXTVER] [get-define VERSION]]
339 if {[get-define libdir] ni {/lib /usr/lib}} {
340 define SH_LINKRPATH_FLAGS [format [get-define SH_LINKRPATH] [get-define libdir]]
341 } else {
342 define SH_LINKRPATH_FLAGS ""
344 define JIM_INSTALL [opt-bool install-jim]
345 define JIM_DOCS [opt-bool docs]
346 define JIM_RANDOMISE_HASH [opt-bool random-hash]
347 define docdir [opt-str docdir o {${prefix}/docs/jim}]
349 # Attributes of the extensions
350 # tcl=Pure Tcl extension
351 # static=Can't be built as a module
352 # off=Off unless explicitly enabled
353 # optional=Off by default, but selected by --full
354 # cpp=Is a C++ extension
355 global extdb
356 dict set extdb attrs {
357 aio { static }
358 array {}
359 binary { tcl optional }
360 clock {}
361 eventloop { static }
362 exec { static }
363 file {}
364 glob { tcl }
365 history {}
366 interp { }
367 json { optional }
368 jsonencode { tcl optional }
369 load { static }
370 mk { cpp off }
371 namespace { static }
372 nshelper { tcl optional }
373 oo { tcl }
374 pack {}
375 package { static }
376 posix {}
377 readdir {}
378 readline { off }
379 regexp {}
380 rlprompt { tcl off }
381 sdl { off }
382 signal { static }
383 sqlite3 { off }
384 zlib { optional }
385 stdlib { tcl static }
386 syslog {}
387 tclcompat { tcl static }
388 tclprefix { optional }
389 tree { tcl }
390 win32 { off }
393 # Additional information about certain extensions
394 # dep=list of extensions which are required for this extension
395 # check=[expr] expression to evaluate to determine if the extension can be used
396 # libdep=list of 'define' symbols for dependent libraries
397 dict set extdb info {
398 binary { dep pack }
399 exec { check {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]} }
400 glob { dep readdir }
401 load { check {[have-feature dlopen-compat] || [cc-check-function-in-lib dlopen dl]} libdep lib_dlopen }
402 mk { check {[check-metakit]} libdep lib_mk }
403 namespace { dep nshelper }
404 json { dep jsonencode extrasrcs jsmn/jsmn.c }
405 posix { check {[have-feature waitpid]} }
406 readdir { check {[have-feature opendir]} }
407 readline { pkg-config readline check {[cc-check-function-in-lib readline readline]} libdep lib_readline}
408 rlprompt { dep readline }
409 tree { dep oo }
410 sdl { pkg-config SDL_gfx check {[cc-check-function-in-lib SDL_SetVideoMode SDL] && [cc-check-function-in-lib rectangleRGBA SDL_gfx]}
411 libdep {lib_SDL_SetVideoMode lib_rectangleRGBA}
413 signal { check {[have-feature sigaction]} }
414 sqlite3 { pkg-config sqlite3 check {[cc-check-function-in-lib sqlite3_prepare_v2 sqlite3]} libdep lib_sqlite3_prepare_v2 }
415 zlib { pkg-config zlib check {[cc-check-function-in-lib deflate z]} libdep lib_deflate }
416 syslog { check {[have-feature syslog]} }
417 tree { dep oo }
418 win32 { check {[have-feature windows]} }
421 # autosetup cc-check-function-in-library can't handle C++ libraries
422 proc check-metakit {} {
423 set found 0
424 msg-checking "Checking for Metakit..."
425 cc-with {-lang c++} {
426 if {[cctest -includes mk4.h -libs -lmk4 -code {c4_Storage dummy();}]} {
427 msg-result ok
428 define lib_mk -lmk4
429 incr found
430 } else {
431 msg-result "not found"
434 return $found
437 # Takes a list of module names, separated by spaces or commas
438 # and returns them as a single list
439 proc join-ext-names {list} {
440 set result {}
441 # Replace comma with space in each list then concatenate the result
442 foreach l $list {
443 lappend result {*}[string map {, " "} $l]
445 return $result
448 # Set up the withinfo array based on what the user selected
449 global withinfo
450 set withinfo(without) [join-ext-names [opt-val {without-ext with-out-jim-ext}]]
451 set withinfo(ext) [join-ext-names [opt-val {with-ext with-jim-ext}]]
452 set withinfo(mod) [join-ext-names [opt-val {with-mod with-jim-extmod}]]
453 set withinfo(nodefault) 0
454 set withinfo(optional) [opt-bool full]
455 if {$withinfo(without) eq "default"} {
456 set withinfo(without) {}
457 set withinfo(nodefault) 1
460 # Now go check everything - see autosetup/local.tcl
461 array set extinfo [check-extensions]
463 # Now special checks
464 if {[have-feature windows]} {
465 lappend extra_objs jim-win32compat.o
467 if {[llength $extinfo(module-c)] && [get-define JIM_STATICLIB]} {
468 user-error "cygwin/mingw require --shared for dynamic modules"
471 if {[have-feature termios.h]} {
472 lappend extra_objs jim-tty.o
475 if {[ext-get-status regexp] in {y m}} {
476 if {![have-feature regcomp]} {
477 # No regcomp means we need to use the built-in version
478 incr jimregexp
482 if {$jimregexp || [opt-bool jim-regexp]} {
483 msg-result "Using built-in regexp"
484 define JIM_REGEXP
486 # If the built-in regexp overrides the system regcomp, etc.
487 # jim must be built shared so that the correct symbols are found
488 if {[ext-get-status regexp] eq "m" && [get-define JIM_STATICLIB] && [have-feature regcomp]} {
489 user-error "Must use --shared with regexp module and built-in regexp"
493 foreach mod $extinfo(static-c) {
494 if {[dict exists $extdb info $mod extrasrcs]} {
495 foreach src [dict get $extdb info $mod extrasrcs] {
496 # In case we are building out-of-tree and $src is in a subdir
497 file mkdir [file dirname $src]
498 lappend extra_objs {*}[file rootname $src].o
503 # poor-man's signals
504 if {"signal" ni $extinfo(static-c)} {
505 lappend extra_objs jim-nosignal.o
508 if {[ext-get-status load] eq "n"} {
509 # If we don't have load, no need to support shared objects
510 define SH_LINKFLAGS ""
513 # Are we cross compiling?
514 if {[get-define host] ne [get-define build]} {
515 define cross_compiling 1
516 } else {
517 define cross_compiling 0
520 msg-result "Jim static extensions: [lsort [concat $extinfo(static-tcl) $extinfo(static-c)]]"
521 if {[llength $extinfo(module-tcl)]} {
522 msg-result "Jim Tcl extensions: [lsort $extinfo(module-tcl)]"
524 if {[llength $extinfo(module-c)]} {
525 msg-result "Jim dynamic extensions: [lsort $extinfo(module-c)]"
528 define STATIC_EXTS [concat $extinfo(static-c) $extinfo(static-tcl)]
529 define C_EXT_OBJS [prefix jim- [suffix .o $extinfo(static-c)]]
530 define TCL_EXT_OBJS [suffix .o $extinfo(static-tcl)]
531 define C_EXT_SHOBJS [suffix .so $extinfo(module-c)]
532 define TCL_EXTS [suffix .tcl $extinfo(module-tcl)]
533 define EXTRA_OBJS $extra_objs
535 # Restore the user-specified LIBS
536 define LIBS $LIBS
538 # Now generate the Makefile rules to build the external C shared objects
539 # It is easier to do this here rather than listing them out explicitly in Makefile.in
540 set lines {}
541 foreach mod $extinfo(module-c) {
542 set objs {}
543 set libs [get-define LDLIBS_$mod]
544 set srcs jim-$mod.c
545 if {[dict exists $extdb info $mod extrasrcs]} {
546 lappend srcs {*}[dict get $extdb info $mod extrasrcs]
548 lappend lines "$mod.so: $srcs"
549 foreach src $srcs {
550 set obj [file rootname $src].o
551 lappend objs $obj
552 lappend lines "\t\$(ECHO)\t\"\tCC\t$obj\""
553 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(SHOBJ_CFLAGS) -c -o $obj $src"
555 lappend lines "\t\$(ECHO)\t\"\tLDSO\t\$@\""
556 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(LDFLAGS) \$(SHOBJ_LDFLAGS) -o \$@ $objs \$(SH_LIBJIM) $libs"
557 lappend lines ""
559 define BUILD_SHOBJS [join $lines \n]
561 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8 SIZEOF_INT} -bare JIM_VERSION -none *
562 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_* _FILE_OFFSET*} -bare {S_I*}
563 make-template Makefile.in
564 make-template tests/Makefile.in
565 make-template examples.api/Makefile.in
566 make-template build-jim-ext.in
567 make-template jimtcl.pc.in
569 catch {exec chmod +x build-jim-ext}
571 if {[get-define SIZEOF_TIME_T] <= 4} {
572 set note ""
573 if {[have-feature windows]} {
574 set note ", consider CFLAGS=-D__MINGW_USE_VC2005_COMPAT on mingw32"
576 lappend warnings "Warning: sizeof(time_t) is [get-define SIZEOF_TIME_T] -- not Y2038 compliant$note"
579 # Output any warnings at the end to make them easier to see
580 foreach warning $warnings {
581 user-notice $warning