build: Support --silent-rules
[jimtcl.git] / auto.def
blob3ed5c23ea932efca748bf295ded9f3bfbeb55f14
1 # vim:se syn=tcl:
4 define JIM_VERSION 77
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
59 These are disabled unless explicitly enabled:
61 readline - Interface to libreadline
62 rlprompt - Tcl wrapper around the readline extension
63 mk - Interface to Metakit
64 sqlite3 - Interface to sqlite3
65 win32 - Interface to win32
67 with-out-jim-ext: {without-ext:"default|ext1,ext2,..."} => {
68 Specify jim extensions to exclude.
69 If 'default' is given, the default extensions will not be added.
71 with-jim-extmod: {with-mod:"ext1,ext2,..."} => {
72 Specify jim extensions to build as separate modules (either C or Tcl).
73 Note that not all extensions can be built as loadable modules.
75 # To help out openocd with automake
76 install-jim=1
79 # Save the user-specified LIBS
80 # We add detected libs to LDLIBS explicitly
81 set LIBS [get-define LIBS]
83 # In case -Werror is passed in CFLAGS, set -Wno-error when doing checks
84 # to prevent warnings from becoming errors
85 if {"-Werror" in [get-define CFLAGS] && [cctest -cflags -Wno-error]} {
86 cc-with {-cflags -Wno-error}
89 cc-check-types "long long"
91 define CCOPTS ""
92 define CXXOPTS ""
93 if {[cctest -cflags -fno-unwind-tables]} {
94 define-append CCOPTS -fno-unwind-tables
96 if {[cctest -cflags -fno-asynchronous-unwind-tables]} {
97 define-append CCOPTS -fno-asynchronous-unwind-tables
100 cc-check-includes sys/time.h sys/socket.h netinet/in.h arpa/inet.h netdb.h
101 cc-check-includes sys/un.h dlfcn.h unistd.h dirent.h crt_externs.h
103 define LDLIBS ""
105 # Haiku needs -lnetwork, Solaris needs -lnsl
106 if {[cc-check-function-in-lib inet_ntop {nsl network}]} {
107 # This does nothing if no libs are needed
108 cc-with [list -libs [get-define lib_inet_ntop]]
109 define-append LDLIBS [get-define lib_inet_ntop]
111 # Solaris needs -lsocket, Windows needs -lwsock32
112 if {[cc-check-function-in-lib socket socket]} {
113 define-append LDLIBS [get-define lib_socket]
116 cc-check-functions ualarm lstat fork vfork system select execvpe
117 cc-check-functions geteuid mkstemp realpath isatty
118 cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist isascii
119 cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
120 cc-check-functions shutdown socketpair isinf isnan link symlink fsync dup umask
121 cc-check-functions localtime gmtime strptime timegm clock_gettime
123 if {[cc-check-function-in-lib backtrace execinfo]} {
124 define-append LDLIBS [get-define lib_backtrace]
127 if {[cc-check-functions sysinfo]} {
128 cc-with {-includes sys/sysinfo.h} {
129 cc-check-members "struct sysinfo.uptime"
133 cc-with {-includes fcntl.h} {
134 cc-check-types "struct flock"
137 cc-check-lfs
138 cc-check-functions fseeko ftello
140 define TCL_LIBRARY [get-define prefix]/lib/jim
142 lassign [split [get-define host] -] host_cpu host_vendor host_os
143 # Scrub revision from the host_os
144 regsub -all {[0-9.]} $host_os {} host_os
146 switch -glob -- $host_os {
147 mingw* {
148 # We provide our own implementation of dlopen for mingw32
149 define-feature dlopen-compat
150 define-feature winconsole
151 define TCL_PLATFORM_OS $host_os
152 define TCL_PLATFORM_PLATFORM windows
153 define TCL_PLATFORM_PATH_SEPARATOR {;}
155 default {
156 # Note that cygwin is considered a unix platform
157 define TCL_PLATFORM_OS $host_os
158 define TCL_PLATFORM_PLATFORM unix
159 define TCL_PLATFORM_PATH_SEPARATOR :
163 # Find some tools
164 cc-check-tools ar ranlib strip
165 define tclsh [info nameofexecutable]
167 # We only support silent-rules for GNU Make
168 define NO_SILENT_RULES
169 if {[get-define AM_SILENT_RULES 0]} {
170 if {[cc-check-progs [get-define MAKE make]]} {
171 # Are we using GNU make?
172 catch {exec [get-define MAKE] --version} makeversion
173 if {[string match "GNU Make*" $makeversion]} {
174 define NO_SILENT_RULES 0
179 if {[opt-bool docs]} {
180 if {[cc-check-progs asciidoc sed]} {
181 define INSTALL_DOCS docs
182 define HAVE_ASCIIDOC
183 } else {
184 define INSTALL_DOCS shipped
186 } else {
187 define INSTALL_DOCS nodocs
190 if {![cc-check-functions _NSGetEnviron]} {
191 msg-checking "Checking environ declared in unistd.h..."
192 if {[cctest -cflags {-D_GNU_SOURCE -D_POSIX_SOURCE} -includes unistd.h -code {char **ep = environ;}]} {
193 define NO_ENVIRON_EXTERN
194 msg-result "yes"
195 } else {
196 msg-result "no"
200 # Windows has a mkdir with no permission arg
201 cc-check-includes sys/types.h sys/stat.h
202 msg-checking "Checking for mkdir with one arg..."
203 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
204 define HAVE_MKDIR_ONE_ARG
205 msg-result yes
206 } else {
207 msg-result no
210 cc-with {-includes sys/stat.h} {
211 foreach i {S_IXUSR S_IRWXG S_IRWXO} {
212 if {![cc-check-decls $i]} {
213 define $i 0
218 set extra_objs {}
219 set jimregexp 0
221 # Returns 1 if either the given option is enabled, or
222 # --full is enabled and the option isn't explicitly disabled
224 proc opt-bool-or-full {opt} {
225 if {[opt-bool $opt]} {
226 return 1
228 if {[opt-bool full] && [opt-bool -nodefault $opt] != 0} {
229 return 1
231 return 0
234 if {[opt-bool-or-full utf8]} {
235 msg-result "Enabling UTF-8"
236 define JIM_UTF8
237 define-append CCOPTS -DUSE_UTF8
238 define PARSE_UNIDATA_FLAGS ""
239 incr jimregexp
240 } else {
241 define JIM_UTF8 0
243 if {[opt-bool maintainer]} {
244 msg-result "Enabling maintainer settings"
245 define JIM_MAINTAINER
247 # If --math or --full and not --disable-math
248 if {[opt-bool-or-full math]} {
249 msg-result "Enabling math functions"
250 define JIM_MATH_FUNCTIONS
251 cc-check-function-in-lib sin m
252 define-append LDLIBS [get-define lib_sin]
254 if {[opt-bool-or-full ipv6]} {
255 msg-result "Enabling IPv6"
256 define JIM_IPV6
258 define-append PKG_CONFIG_REQUIRES ""
259 if {[opt-bool-or-full ssl]} {
260 if {[pkg-config-init 0]} {
261 foreach pkg {openssl libssl} {
262 if {[pkg-config $pkg]} {
263 define JIM_SSL
264 define-append LDLIBS [pkg-config-get $pkg LIBS]
265 define-append LDFLAGS [pkg-config-get $pkg LDFLAGS]
266 define-append CCOPTS [pkg-config-get $pkg CFLAGS]
267 msg-result "Enabling SSL ($pkg)"
268 define-append PKG_CONFIG_REQUIRES $pkg
269 break
273 if {![is-defined JIM_SSL]} {
274 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]} {
275 msg-result "Enabling SSL"
276 define JIM_SSL
277 define-append LDLIBS [get-define lib_ERR_error_string] [get-define lib_TLSv1_2_method]
278 } elseif {[opt-bool ssl]} {
279 user-error "SSL support requires OpenSSL"
283 if {[opt-bool-or-full lineedit]} {
284 if {([cc-check-includes termios.h] && [have-feature isatty]) || [have-feature winconsole]} {
285 msg-result "Enabling line editing"
286 define USE_LINENOISE
287 define-append PARSE_UNIDATA_FLAGS -width
288 lappend extra_objs linenoise.o
291 if {[opt-bool references]} {
292 msg-result "Enabling references"
293 define JIM_REFERENCES
295 if {[opt-bool shared with-jim-shared]} {
296 msg-result "Building shared library"
297 } else {
298 msg-result "Building static library"
299 define JIM_STATICLIB
301 define VERSION [format %.2f [expr {[get-define JIM_VERSION] / 100.0}]]
302 define LIBSOEXT [format [get-define SH_SOEXTVER] [get-define VERSION]]
303 define JIM_INSTALL [opt-bool install-jim]
304 define JIM_DOCS [opt-bool docs]
305 define JIM_RANDOMISE_HASH [opt-bool random-hash]
306 define docdir [opt-str docdir o {${prefix}/docs/jim}]
308 # Attributes of the extensions
309 # tcl=Pure Tcl extension
310 # static=Can't be built as a module
311 # off=Off unless explicitly enabled
312 # optional=Off by default, but selected by --full
313 # cpp=Is a C++ extension
314 global extdb
315 dict set extdb attrs {
316 aio { static }
317 array {}
318 binary { tcl optional }
319 clock {}
320 eventloop { static }
321 exec { static }
322 file {}
323 glob { tcl }
324 history {}
325 interp { }
326 load { static }
327 mk { cpp off }
328 namespace { static }
329 nshelper { tcl optional }
330 oo { tcl }
331 pack {}
332 package { static }
333 posix {}
334 readdir {}
335 readline { off }
336 regexp {}
337 rlprompt { tcl off }
338 sdl { off }
339 signal { static }
340 sqlite3 { off }
341 zlib { optional }
342 stdlib { tcl static }
343 syslog {}
344 tclcompat { tcl static }
345 tclprefix { optional }
346 tree { tcl }
347 win32 { off }
350 # Additional information about certain extensions
351 # dep=list of extensions which are required for this extension
352 # check=[expr] expression to evaluate to determine if the extension can be used
353 # libdep=list of 'define' symbols for dependent libraries
354 dict set extdb info {
355 binary { dep pack }
356 exec { check {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]} }
357 glob { dep readdir }
358 load { check {[have-feature dlopen-compat] || [cc-check-function-in-lib dlopen dl]} libdep lib_dlopen }
359 mk { check {[check-metakit]} libdep lib_mk }
360 namespace { dep nshelper }
361 posix { check {[have-feature waitpid]} }
362 readdir { check {[have-feature opendir]} }
363 readline { pkg-config readline check {[cc-check-function-in-lib readline readline]} libdep lib_readline}
364 rlprompt { dep readline }
365 tree { dep oo }
366 sdl { pkg-config SDL_gfx check {[cc-check-function-in-lib SDL_SetVideoMode SDL] && [cc-check-function-in-lib rectangleRGBA SDL_gfx]}
367 libdep {lib_SDL_SetVideoMode lib_rectangleRGBA}
369 signal { check {[have-feature sigaction]} }
370 sqlite3 { pkg-config sqlite3 check {[cc-check-function-in-lib sqlite3_prepare_v2 sqlite3]} libdep lib_sqlite3_prepare_v2 }
371 zlib { pkg-config zlib check {[cc-check-function-in-lib deflate z]} libdep lib_deflate }
372 syslog { check {[have-feature syslog]} }
373 tree { dep oo }
374 win32 { check {[have-feature windows]} }
377 # autosetup cc-check-function-in-library can't handle C++ libraries
378 proc check-metakit {} {
379 set found 0
380 msg-checking "Checking for Metakit..."
381 cc-with {-lang c++} {
382 if {[cctest -includes mk4.h -libs -lmk4 -code {c4_Storage dummy();}]} {
383 msg-result ok
384 define lib_mk -lmk4
385 incr found
386 } else {
387 msg-result "not found"
390 return $found
393 # Takes a list of module names, separated by spaces or commas
394 # and returns them as a single list
395 proc join-ext-names {list} {
396 set result {}
397 # Replace comma with space in each list then concatenate the result
398 foreach l $list {
399 lappend result {*}[string map {, " "} $l]
401 return $result
404 # Set up the withinfo array based on what the user selected
405 global withinfo
406 set withinfo(without) [join-ext-names [opt-val {without-ext with-out-jim-ext}]]
407 set withinfo(ext) [join-ext-names [opt-val {with-ext with-jim-ext}]]
408 set withinfo(mod) [join-ext-names [opt-val {with-mod with-jim-extmod}]]
409 set withinfo(nodefault) 0
410 set withinfo(optional) [opt-bool full]
411 if {$withinfo(without) eq "default"} {
412 set withinfo(without) {}
413 set withinfo(nodefault) 1
416 # Now go check everything - see autosetup/local.tcl
417 array set extinfo [check-extensions]
419 # Now special checks
420 if {[have-feature windows]} {
421 lappend extra_objs jim-win32compat.o
423 if {[llength $extinfo(module-c)] && [get-define JIM_STATICLIB]} {
424 user-error "cygwin/mingw require --shared for dynamic modules"
427 if {[have-feature termios.h]} {
428 lappend extra_objs jim-tty.o
431 if {[ext-get-status regexp] in {y m}} {
432 if {![have-feature regcomp]} {
433 # No regcomp means we need to use the built-in version
434 incr jimregexp
438 if {$jimregexp || [opt-bool jim-regexp]} {
439 msg-result "Using built-in regexp"
440 define JIM_REGEXP
442 # If the built-in regexp overrides the system regcomp, etc.
443 # jim must be built shared so that the correct symbols are found
444 if {[ext-get-status regexp] eq "m" && [get-define JIM_STATICLIB] && [have-feature regcomp]} {
445 user-error "Must use --shared with regexp module and built-in regexp"
449 # poor-man's signals
450 if {"signal" ni $extinfo(static-c)} {
451 lappend extra_objs jim-nosignal.o
454 if {[ext-get-status load] eq "n"} {
455 # If we don't have load, no need to support shared objects
456 define SH_LINKFLAGS ""
459 msg-result "Jim static extensions: [lsort [concat $extinfo(static-tcl) $extinfo(static-c)]]"
460 if {[llength $extinfo(module-tcl)]} {
461 msg-result "Jim Tcl extensions: [lsort $extinfo(module-tcl)]"
463 if {[llength $extinfo(module-c)]} {
464 msg-result "Jim dynamic extensions: [lsort $extinfo(module-c)]"
467 define STATIC_EXTS [concat $extinfo(static-c) $extinfo(static-tcl)]
468 define C_EXT_OBJS [prefix jim- [suffix .o $extinfo(static-c)]]
469 define TCL_EXT_OBJS [suffix .o $extinfo(static-tcl)]
470 define C_EXT_SHOBJS [suffix .so $extinfo(module-c)]
471 define TCL_EXTS [suffix .tcl $extinfo(module-tcl)]
472 define EXTRA_OBJS $extra_objs
474 # Restore the user-specified LIBS
475 define LIBS $LIBS
477 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8} -bare JIM_VERSION -none *
478 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_* _FILE_OFFSET*} -bare {S_I*}
479 make-template Makefile.in
480 make-template build-jim-ext.in
481 make-template jimtcl.pc.in
483 catch {exec chmod +x build-jim-ext}