Simplify approach for generated code
[jimtcl.git] / auto.def
blob0ac4dde1a9867cccc547e40af097f5e69a979688
1 # vim:se syn=tcl:
4 # Note: modules which support options *must* be included before 'options'
5 use cc cc-shared
7 options {
8 utf8 => "include support for utf8-encoded strings"
9 lineedit=1 => "disable line editing"
10 references=1 => "disable support for references"
11 math => "include support for math functions"
12 ipv6 => "include ipv6 support in the aio extension"
13 maintainer => {enable the [debug] command and JimPanic}
14 full => "Enable some optional features: ipv6, math, utf8, binary, oo, tree"
15 with-jim-shared shared => "build a shared library instead of a static library"
16 jim-regexp => "use the built-in (Tcl-compatible) regexp, even if POSIX regex is available"
17 with-jim-ext: {with-ext:"ext1 ext2 ..."} => {
18 Specify additional jim extensions to include.
19 These are enabled by default:
21 aio - ANSI I/O, including open and socket
22 eventloop - after, vwait, update
23 array - Tcl-compatible array command
24 clock - Tcl-compatible clock command
25 exec - Tcl-compatible exec command
26 file - Tcl-compatible file command
27 glob - Tcl-compatible glob command
28 readdir - Required for glob
29 package - Package management with the package command
30 load - Load binary extensions at runtime with load or package
31 posix - Posix APIs including os.fork, os.wait, pid
32 regexp - Tcl-compatible regexp, regsub commands
33 signal - Signal handling
34 stdlib - Built-in commands including lassign, lambda, alias
35 syslog - System logging with syslog
36 tclcompat - Tcl compatible read, gets, puts, parray, case, ...
38 These are disabled by default:
40 nvp - Name-value pairs C-only API
41 oo - Jim OO extension
42 tree - OO tree structure, similar to tcllib ::struct::tree
43 binary - Tcl-compatible 'binary' command
44 readline - Interface to libreadline
45 rlprompt - Tcl wrapper around the readline extension
46 sqlite - Interface to sqlite
47 sqlite3 - Interface to sqlite3
48 win32 - Interface to win32
50 with-out-jim-ext: {without-ext:"default|ext1 ext2 ..."} => {
51 Specify jim extensions to exclude.
52 If 'default' is given, the default extensions will not be added.
54 with-jim-extmod: {with-mod:"ext1 ext2 ..."} => {
55 Specify jim extensions to build as separate modules (either C or Tcl).
56 Note that not all extensions can be built as loadable modules.
60 cc-check-types "long long"
62 cc-check-includes sys/socket.h netinet/in.h arpa/inet.h netdb.h
63 cc-check-includes sys/un.h dlfcn.h unistd.h crt_externs.h
65 cc-check-functions ualarm sysinfo lstat fork vfork system select
66 cc-check-functions backtrace geteuid mkstemp realpath strptime gettimeofday
67 cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist
68 cc-check-functions syslog opendir readlink sleep usleep pipe inet_ntop getaddrinfo
70 define TCL_LIBRARY [get-define prefix]/lib/jim
72 lassign [split [get-define host] -] host_cpu host_vendor host_os
73 # Scrub revision from the host_os
74 regsub -all {[0-9.]} $host_os {} host_os
76 switch -glob -- $host_os {
77 mingw* {
78 # We provide our own implementation of dlopen for mingw32
79 define-feature dlopen-compat
80 define TCL_PLATFORM_OS $host_os
81 define TCL_PLATFORM_PLATFORM windows
82 define TCL_PLATFORM_PATH_SEPARATOR {;}
84 default {
85 # Note that cygwin is considered a unix platform
86 define TCL_PLATFORM_OS $host_os
87 define TCL_PLATFORM_PLATFORM unix
88 define TCL_PLATFORM_PATH_SEPARATOR :
92 # Find some tools
93 cc-check-tools ar ranlib strip
94 define tclsh [info nameofexecutable]
96 if {![cc-check-functions _NSGetEnviron]} {
97 msg-checking "Checking environ declared in unistd.h..."
98 if {[cctest -cflags -D_GNU_SOURCE -includes unistd.h -code {char **ep = environ;}]} {
99 define NO_ENVIRON_EXTERN
100 msg-result "yes"
101 } else {
102 msg-result "no"
106 # Windows has a mkdir with no permission arg
107 cc-check-includes sys/types.h sys/stat.h
108 msg-checking "Checking for mkdir with one arg..."
109 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
110 define HAVE_MKDIR_ONE_ARG
111 msg-result yes
112 } else {
113 msg-result no
116 set extra_objs {}
117 set jimregexp 0
119 if {[opt-bool utf8 full]} {
120 msg-result "Enabling UTF-8"
121 define JIM_UTF8
122 incr jimregexp
123 } else {
124 define JIM_UTF8 0
126 if {[opt-bool maintainer]} {
127 msg-result "Enabling maintainer settings"
128 define JIM_MAINTAINER
130 if {[opt-bool math full]} {
131 msg-result "Enabling math functions"
132 define JIM_MATH_FUNCTIONS
133 define-append LIBS -lm
135 if {[opt-bool ipv6 full]} {
136 msg-result "Enabling IPv6"
137 define JIM_IPV6
139 if {[opt-bool lineedit full] && [cc-check-includes termios.h]} {
140 msg-result "Enabling line editing"
141 define USE_LINENOISE
142 lappend extra_objs linenoise.o
144 if {[opt-bool references]} {
145 msg-result "Enabling references"
146 define JIM_REFERENCES
148 if {[opt-bool shared with-jim-shared]} {
149 msg-result "Building shared library"
150 define JIM_LIBTYPE shared
151 } else {
152 msg-result "Building static library"
153 define JIM_LIBTYPE static
156 # Note: Extension handling is mapped directly from the configure.ac
157 # implementation
159 set without [join [opt-val {without-ext with-out-jim-ext}]]
160 set withext [join [opt-val {with-ext with-jim-ext}]]
161 set withmod [join [opt-val {with-mod with-jim-extmod}]]
163 # Tcl extensions
164 set ext_tcl "stdlib glob tclcompat tree rlprompt oo binary"
165 # C extensions
166 set ext_c "load package readdir array clock exec file posix regexp signal aio eventloop pack syslog nvp readline sqlite sqlite3 win32"
168 # Tcl extensions which can be modules
169 set ext_tcl_mod "glob tree rlprompt oo binary"
170 # C extensions which can be modules
171 set ext_c_mod "readdir array clock file posix regexp syslog readline pack sqlite sqlite3 win32"
173 # All extensions
174 set ext_all [concat $ext_c $ext_tcl]
176 # Default static extensions
177 set ext_default "stdlib load package readdir glob array clock exec file posix regexp signal tclcompat aio eventloop syslog"
179 if {[opt-bool full]} {
180 lappend ext_default tree binary
183 if {$without eq "default"} {
184 set ext_default stdlib
185 set without {}
188 # Check valid extension names
189 foreach i [concat $withext $without $withmod] {
190 if {$i ni $ext_all} {
191 user-error "Unknown extension: $i"
195 # needs_xxx="expression" means that the expr must eval to 1 to select the extension
196 # dep_xxx="yyy zzz" means that if xxx is selected, so is yyy and zzz
197 set dep(glob) readdir
198 set dep(rlprompt) readline
199 set dep(tree) oo
200 set dep(binary) pack
202 set needs(aio) {expr {[cc-check-function-in-lib socket socket] || 1}}
203 set needs(exec) {expr {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]}}
204 set needs(load) {expr {[cc-check-function-in-lib dlopen dl] || [have-feature dlopen-compat]}}
205 set needs(posix) {have-feature waitpid}
206 set needs(readdir) {have-feature opendir}
207 set needs(readline) {cc-check-function-in-lib readline readline}
208 set needs(signal) {expr {[have-feature sigaction] && [have-feature vfork]}}
209 set needs(sqlite) {cc-check-function-in-lib sqlite_open sqlite}
210 set needs(sqlite3) {cc-check-function-in-lib sqlite3_open sqlite3}
211 set needs(syslog) {have-feature syslog}
212 set needs(eventloop) {expr {[have-feature select] || [have-feature usleep]}}
213 set needs(win32) {have-feature windows}
215 # First handle dependencies. If an extension is enabled, also enable its dependency
216 foreach i [concat $ext_default $withext] {
217 if {$i in $without} {
218 continue
220 if {[info exists dep($i)]} {
221 lappend withext {*}$dep($i)
225 foreach i $withmod {
226 if {[info exists dep($i)]} {
227 # Theoretically, a mod could depend upon something which must be static
228 # If already configured static, don't make it a module
229 foreach d $dep($i) {
230 if {$d ni $withext} {
231 lappend withmod $d
237 # Now that we know what the platform supports:
239 # For all known extensions:
240 # - If it is disabled, remove it
241 # - Otherwise, check to see if it's pre-requisites are met
242 # - If yes, add it if it is enabled or is a default
243 # - If no, error if it is enabled, or do nothing otherwise
244 # - Modules may be either C or Tcl
246 set extmodtcl {}
247 set extmod {}
248 set ext {}
250 foreach i [lsort $ext_all] {
251 # First discard the extension if disabled or not enabled
252 if {$i in $without} {
253 msg-result "Extension $i...disabled"
254 continue
256 if {$i ni [concat $withext $withmod $ext_default]} {
257 msg-result "Extension $i...not enabled"
258 continue
261 # Check dependencies
262 set met 1
263 if {[info exists needs($i)]} {
264 set met [eval $needs($i)]
267 msg-checking "Extension $i..."
269 # Selected as a module?
270 if {$i in $withmod} {
271 if {$i in $ext_tcl_mod} {
272 # Easy, a Tcl module
273 msg-result "tcl"
274 lappend extmodtcl $i
275 continue
277 if {$i ni $ext_c_mod} {
278 user-error "not a module"
280 if {!$met} {
281 user-error "dependencies not met"
283 msg-result "module"
284 lappend extmod $i
285 continue
288 # Selected as a static extension?
289 if {$i in $withext} {
290 if {!$met} {
291 user-error "dependencies not met"
293 msg-result "enabled"
294 lappend ext $i
295 continue
298 # Enabled by default?
299 if {$i in $ext_default} {
300 if {!$met} {
301 msg-result "disabled (dependencies)"
302 continue
304 msg-result "enabled (default)"
305 lappend ext $i
306 continue
310 if {[have-feature windows]} {
311 lappend extra_objs jim-win32compat.o
313 if {$extmod ne "" && [get-define JIM_LIBTYPE] eq "static"} {
314 user-error "cygwin/mingw require --shared for dynamic modules"
318 if {"regexp" in "$ext $extmod"} {
319 # No regcomp means we need to use the built-in version
320 if {![have-feature regcomp]} {
321 incr jimregexp
325 if {$jimregexp || [opt-bool jim-regexp]} {
326 msg-result "Using built-in regexp"
327 define JIM_REGEXP
329 # If the built-in regexp overrides the system regcomp, etc.
330 # jim must be built shared so that the correct symbols are found
331 if {"regexp" in $extmod && [get-define JIM_LIBTYPE] eq "static" && [have-feature regcomp]} {
332 user-error "Must use --shared with regexp module and built-in regexp"
335 if {"load" ni $ext} {
336 # If we don't have load, no need to support shared objects
337 define SH_LINKFLAGS ""
340 msg-result "Jim static extensions: [lsort $ext]"
341 if {$extmodtcl ne ""} {
342 msg-result "Jim Tcl extensions: [lsort $extmodtcl]"
344 if {$extmod ne ""} {
345 msg-result "Jim dynamic extensions: [lsort $extmod]"
348 # Separate out the static extensions into C and Tcl
349 set ext_static_c {}
350 set ext_static_tcl {}
351 foreach e $ext {
352 define jim_ext_$e
353 if {$e in $ext_tcl} {
354 lappend ext_static_tcl $e
355 } else {
356 lappend ext_static_c $e
360 define JIM_STATIC_C_EXTS $ext_static_c
361 define JIM_STATIC_TCL_EXTS $ext_static_tcl
362 define JIM_TCL_EXTENSIONS $extmodtcl
363 define JIM_MOD_EXTENSIONS $extmod
364 define EXTRA_OBJS $extra_objs
366 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8} -none *
367 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_*}
368 make-template Makefile.in