scan: Fix a utf-8 bug for string length
[jimtcl.git] / auto.def
blob4a891ded24e1ba7a8cfebd725066574d0666ad0a
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 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]
156 if {[cc-check-functions sysinfo]} {
157 cc-with {-includes sys/sysinfo.h} {
158 cc-check-members "struct sysinfo.uptime"
162 cc-with {-includes {sys/types.h sys/stat.h}} {
163 cc-check-members "struct stat.st_mtimespec"
164 cc-check-members "struct stat.st_mtim"
167 cc-with {-includes fcntl.h} {
168 cc-check-types "struct flock"
171 cc-check-lfs
172 cc-check-functions fseeko ftello
174 define TCL_LIBRARY [get-define prefix]/lib/jim
176 lassign [split [get-define host] -] host_cpu host_vendor host_os
177 # Scrub revision from the host_os
178 regsub -all {[0-9.]} $host_os {} host_os
180 switch -glob -- $host_os {
181 mingw* {
182 # We provide our own implementation of dlopen for mingw32
183 define-feature dlopen-compat
184 define-feature winconsole
185 define TCL_PLATFORM_OS $host_os
186 define TCL_PLATFORM_PLATFORM windows
187 define TCL_PLATFORM_PATH_SEPARATOR {;}
189 default {
190 # Note that cygwin is considered a unix platform
191 define TCL_PLATFORM_OS $host_os
192 define TCL_PLATFORM_PLATFORM unix
193 define TCL_PLATFORM_PATH_SEPARATOR :
197 # Find some tools
198 cc-check-tools ar ranlib strip
199 define tclsh [info nameofexecutable]
201 # We only support silent-rules for GNU Make
202 define NO_SILENT_RULES
203 if {[get-define AM_SILENT_RULES 0]} {
204 if {[cc-check-progs [get-define MAKE make]]} {
205 # Are we using GNU make?
206 catch {exec [get-define MAKE] --version} makeversion
207 if {[string match "GNU Make*" $makeversion]} {
208 define NO_SILENT_RULES 0
213 if {[opt-bool docs]} {
214 if {[cc-check-progs asciidoc sed]} {
215 define INSTALL_DOCS docs
216 define HAVE_ASCIIDOC
217 } else {
218 define INSTALL_DOCS shipped
220 } else {
221 define INSTALL_DOCS nodocs
224 if {![cc-check-functions _NSGetEnviron]} {
225 msg-checking "Checking environ declared in unistd.h..."
226 if {[cctest -cflags {-D_GNU_SOURCE -D_POSIX_SOURCE} -includes unistd.h -code {char **ep = environ;}]} {
227 define NO_ENVIRON_EXTERN
228 msg-result "yes"
229 } else {
230 msg-result "no"
234 # Windows has a mkdir with no permission arg
235 cc-check-includes sys/types.h sys/stat.h
236 msg-checking "Checking for mkdir with one arg..."
237 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
238 define HAVE_MKDIR_ONE_ARG
239 msg-result yes
240 } else {
241 msg-result no
244 cc-with {-includes sys/stat.h} {
245 foreach i {S_IXUSR S_IRWXG S_IRWXO} {
246 if {![cc-check-decls $i]} {
247 define $i 0
252 set extra_objs {}
253 set jimregexp 0
255 # Returns 1 if either the given option is enabled, or
256 # --full is enabled and the option isn't explicitly disabled
258 proc opt-bool-or-full {opt} {
259 if {[opt-bool $opt]} {
260 return 1
262 if {[opt-bool full] && [opt-bool -nodefault $opt] != 0} {
263 return 1
265 return 0
268 if {[opt-bool-or-full utf8]} {
269 msg-result "Enabling UTF-8"
270 define JIM_UTF8
271 define-append CCOPTS -DUSE_UTF8
272 define PARSE_UNIDATA_FLAGS ""
273 incr jimregexp
274 } else {
275 define JIM_UTF8 0
277 if {[opt-bool maintainer]} {
278 msg-result "Enabling maintainer settings"
279 define JIM_MAINTAINER
281 # If --math or --full and not --disable-math
282 if {[opt-bool-or-full math]} {
283 msg-result "Enabling math functions"
284 define JIM_MATH_FUNCTIONS
285 cc-check-function-in-lib sin m
286 define-append LDLIBS [get-define lib_sin]
288 if {[opt-bool-or-full ipv6]} {
289 msg-result "Enabling IPv6"
290 define JIM_IPV6
292 define-append PKG_CONFIG_REQUIRES ""
293 if {[opt-bool-or-full ssl]} {
294 if {[pkg-config-init 0]} {
295 foreach pkg {openssl libssl} {
296 if {[pkg-config $pkg]} {
297 define JIM_SSL
298 define-append LDLIBS [pkg-config-get $pkg LIBS]
299 define-append LDFLAGS [pkg-config-get $pkg LDFLAGS]
300 define-append CCOPTS [pkg-config-get $pkg CFLAGS]
301 msg-result "Enabling SSL ($pkg)"
302 define-append PKG_CONFIG_REQUIRES $pkg
303 break
307 if {![is-defined JIM_SSL]} {
308 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]} {
309 msg-result "Enabling SSL"
310 define JIM_SSL
311 define-append LDLIBS [get-define lib_ERR_error_string] [get-define lib_TLSv1_2_method]
312 } elseif {[opt-bool ssl]} {
313 user-error "SSL support requires OpenSSL"
316 # Later versions deprecate TLSv1_2_method, but older versions don't have TLS_method
317 if {![cc-check-function-in-lib TLS_method ssl]} {
318 define-append CCOPTS -DUSE_TLSv1_2_method
321 if {[opt-bool-or-full lineedit]} {
322 if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
323 msg-result "Enabling line editing"
324 define USE_LINENOISE
325 define-append PARSE_UNIDATA_FLAGS -width
326 lappend extra_objs linenoise.o
327 if {[cc-check-inline] && [is-defined inline]} {
328 define-append CCOPTS -Dinline=[get-define inline]
332 if {[opt-bool references]} {
333 msg-result "Enabling references"
334 define JIM_REFERENCES
336 if {[opt-bool shared with-jim-shared]} {
337 msg-result "Building shared library"
338 } else {
339 msg-result "Building static library"
340 define JIM_STATICLIB
342 define VERSION [format %.2f [expr {[get-define JIM_VERSION] / 100.0}]]
343 define LIBSOEXT [format [get-define SH_SOEXTVER] [get-define VERSION]]
344 if {[get-define libdir] ni {/lib /usr/lib}} {
345 define SH_LINKRPATH_FLAGS [format [get-define SH_LINKRPATH] [get-define libdir]]
346 } else {
347 define SH_LINKRPATH_FLAGS ""
349 define JIM_INSTALL [opt-bool install-jim]
350 define JIM_DOCS [opt-bool docs]
351 define JIM_RANDOMISE_HASH [opt-bool random-hash]
352 define docdir [opt-str docdir o {${prefix}/docs/jim}]
354 # Attributes of the extensions
355 # tcl=Pure Tcl extension
356 # static=Can't be built as a module
357 # off=Off unless explicitly enabled
358 # optional=Off by default, but selected by --full
359 # cpp=Is a C++ extension
360 global extdb
361 dict set extdb attrs {
362 aio { static }
363 array {}
364 binary { tcl optional }
365 clock {}
366 eventloop { static }
367 exec { static }
368 file {}
369 glob { tcl }
370 history {}
371 interp { }
372 json { optional }
373 jsonencode { tcl optional }
374 load { static }
375 mk { cpp off }
376 namespace { static }
377 nshelper { tcl optional }
378 oo { tcl }
379 pack {}
380 package { static }
381 posix {}
382 readdir {}
383 readline { off }
384 regexp {}
385 rlprompt { tcl off }
386 sdl { off }
387 signal { static }
388 sqlite3 { off }
389 zlib { optional }
390 stdlib { tcl static }
391 syslog {}
392 tclcompat { tcl static }
393 tclprefix { optional }
394 tree { tcl }
395 win32 { off }
398 # Additional information about certain extensions
399 # dep=list of extensions which are required for this extension
400 # check=[expr] expression to evaluate to determine if the extension can be used
401 # libdep=list of 'define' symbols for dependent libraries
402 dict set extdb info {
403 binary { dep pack }
404 exec { check {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]} }
405 glob { dep readdir }
406 load { check {[have-feature dlopen-compat] || [cc-check-function-in-lib dlopen dl]} libdep lib_dlopen }
407 mk { check {[check-metakit]} libdep lib_mk }
408 namespace { dep nshelper }
409 json { dep jsonencode extrasrcs jsmn/jsmn.c }
410 posix { check {[have-feature waitpid]} }
411 readdir { check {[have-feature opendir]} }
412 readline { pkg-config readline check {[cc-check-function-in-lib readline readline]} libdep lib_readline}
413 rlprompt { dep readline }
414 tree { dep oo }
415 sdl { pkg-config SDL_gfx check {[cc-check-function-in-lib SDL_SetVideoMode SDL] && [cc-check-function-in-lib rectangleRGBA SDL_gfx]}
416 libdep {lib_SDL_SetVideoMode lib_rectangleRGBA}
418 signal { check {[have-feature sigaction]} }
419 sqlite3 { pkg-config sqlite3 check {[cc-check-function-in-lib sqlite3_prepare_v2 sqlite3]} libdep lib_sqlite3_prepare_v2 }
420 zlib { pkg-config zlib check {[cc-check-function-in-lib deflate z]} libdep lib_deflate }
421 syslog { check {[have-feature syslog]} }
422 tree { dep oo }
423 win32 { check {[have-feature windows]} }
426 # autosetup cc-check-function-in-library can't handle C++ libraries
427 proc check-metakit {} {
428 set found 0
429 msg-checking "Checking for Metakit..."
430 cc-with {-lang c++} {
431 if {[cctest -includes mk4.h -libs -lmk4 -code {c4_Storage dummy();}]} {
432 msg-result ok
433 define lib_mk -lmk4
434 incr found
435 } else {
436 msg-result "not found"
439 return $found
442 # Takes a list of module names, separated by spaces or commas
443 # and returns them as a single list
444 proc join-ext-names {list} {
445 set result {}
446 # Replace comma with space in each list then concatenate the result
447 foreach l $list {
448 lappend result {*}[string map {, " "} $l]
450 return $result
453 # Set up the withinfo array based on what the user selected
454 global withinfo
455 set withinfo(without) [join-ext-names [opt-val {without-ext with-out-jim-ext}]]
456 set withinfo(ext) [join-ext-names [opt-val {with-ext with-jim-ext}]]
457 set withinfo(mod) [join-ext-names [opt-val {with-mod with-jim-extmod}]]
458 set withinfo(nodefault) 0
459 set withinfo(optional) [opt-bool full]
460 if {$withinfo(without) eq "default"} {
461 set withinfo(without) {}
462 set withinfo(nodefault) 1
465 # Now go check everything - see autosetup/local.tcl
466 array set extinfo [check-extensions]
468 # Now special checks
469 if {[have-feature windows]} {
470 lappend extra_objs jim-win32compat.o
472 if {[llength $extinfo(module-c)] && [get-define JIM_STATICLIB]} {
473 user-error "cygwin/mingw require --shared for dynamic modules"
476 if {[have-feature termios.h]} {
477 lappend extra_objs jim-tty.o
480 if {[ext-get-status regexp] in {y m}} {
481 if {![have-feature regcomp]} {
482 # No regcomp means we need to use the built-in version
483 incr jimregexp
487 if {$jimregexp || [opt-bool jim-regexp]} {
488 msg-result "Using built-in regexp"
489 define JIM_REGEXP
491 # If the built-in regexp overrides the system regcomp, etc.
492 # jim must be built shared so that the correct symbols are found
493 if {[ext-get-status regexp] eq "m" && [get-define JIM_STATICLIB] && [have-feature regcomp]} {
494 user-error "Must use --shared with regexp module and built-in regexp"
498 foreach mod $extinfo(static-c) {
499 if {[dict exists $extdb info $mod extrasrcs]} {
500 foreach src [dict get $extdb info $mod extrasrcs] {
501 # In case we are building out-of-tree and $src is in a subdir
502 file mkdir [file dirname $src]
503 lappend extra_objs {*}[file rootname $src].o
508 # poor-man's signals
509 if {"signal" ni $extinfo(static-c)} {
510 lappend extra_objs jim-nosignal.o
513 if {[ext-get-status load] eq "n"} {
514 # If we don't have load, no need to support shared objects
515 define SH_LINKFLAGS ""
518 # Are we cross compiling?
519 if {[get-define host] ne [get-define build]} {
520 define cross_compiling 1
521 } else {
522 define cross_compiling 0
525 msg-result "Jim static extensions: [lsort [concat $extinfo(static-tcl) $extinfo(static-c)]]"
526 if {[llength $extinfo(module-tcl)]} {
527 msg-result "Jim Tcl extensions: [lsort $extinfo(module-tcl)]"
529 if {[llength $extinfo(module-c)]} {
530 msg-result "Jim dynamic extensions: [lsort $extinfo(module-c)]"
533 define STATIC_EXTS [concat $extinfo(static-c) $extinfo(static-tcl)]
534 define C_EXT_OBJS [prefix jim- [suffix .o $extinfo(static-c)]]
535 define TCL_EXT_OBJS [suffix .o $extinfo(static-tcl)]
536 define C_EXT_SHOBJS [suffix .so $extinfo(module-c)]
537 define TCL_EXTS [suffix .tcl $extinfo(module-tcl)]
538 define EXTRA_OBJS $extra_objs
540 # Restore the user-specified LIBS
541 define LIBS $LIBS
543 # Now generate the Makefile rules to build the external C shared objects
544 # It is easier to do this here rather than listing them out explicitly in Makefile.in
545 set lines {}
546 foreach mod $extinfo(module-c) {
547 set objs {}
548 set libs [get-define LDLIBS_$mod]
549 set srcs jim-$mod.c
550 if {[dict exists $extdb info $mod extrasrcs]} {
551 lappend srcs {*}[dict get $extdb info $mod extrasrcs]
553 lappend lines "$mod.so: $srcs"
554 foreach src $srcs {
555 set obj [file rootname $src].o
556 lappend objs $obj
557 lappend lines "\t\$(ECHO)\t\"\tCC\t$obj\""
558 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(SHOBJ_CFLAGS) -c -o $obj $src"
560 lappend lines "\t\$(ECHO)\t\"\tLDSO\t\$@\""
561 lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(LDFLAGS) \$(SHOBJ_LDFLAGS) -o \$@ $objs \$(SH_LIBJIM) $libs"
562 lappend lines ""
564 define BUILD_SHOBJS [join $lines \n]
566 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8 SIZEOF_INT} -bare JIM_VERSION -none *
567 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_* _FILE_OFFSET*} -bare {S_I*}
568 make-template Makefile.in
569 make-template tests/Makefile.in
570 make-template examples.api/Makefile.in
571 make-template build-jim-ext.in
572 make-template jimtcl.pc.in
574 catch {exec chmod +x build-jim-ext}
576 if {[get-define SIZEOF_TIME_T] <= 4} {
577 set note ""
578 if {[have-feature windows]} {
579 set note ", consider CFLAGS=-D__MINGW_USE_VC2005_COMPAT on mingw32"
581 lappend warnings "Warning: sizeof(time_t) is [get-define SIZEOF_TIME_T] -- not Y2038 compliant$note"
584 # Output any warnings at the end to make them easier to see
585 foreach warning $warnings {
586 user-notice $warning