Implement full [exec] on mingw/msys
[jimtcl.git] / auto.def
blobc24a0096c6dd4544f6f9e5f584e996e9fee461f8
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 mk - Interface to Metakit
47 sqlite - Interface to sqlite
48 sqlite3 - Interface to sqlite3
49 win32 - Interface to win32
51 with-out-jim-ext: {without-ext:"default|ext1 ext2 ..."} => {
52 Specify jim extensions to exclude.
53 If 'default' is given, the default extensions will not be added.
55 with-jim-extmod: {with-mod:"ext1 ext2 ..."} => {
56 Specify jim extensions to build as separate modules (either C or Tcl).
57 Note that not all extensions can be built as loadable modules.
59 # To help out openocd with automake
60 install-jim=1
63 cc-check-types "long long"
65 cc-check-includes sys/socket.h netinet/in.h arpa/inet.h netdb.h
66 cc-check-includes sys/un.h dlfcn.h unistd.h crt_externs.h
68 define LDLIBS ""
70 # Haiku needs -lnetwork, Solaris needs -lnsl
71 if {[cc-check-function-in-lib inet_ntop {nsl network}]} {
72 # This does nothing if no libs are needed
73 cc-with [list -libs [get-define lib_inet_ntop]]
74 define-append LDLIBS [get-define lib_inet_ntop]
76 # Solaris needs -lsocket, Windows needs -lwsock32
77 if {[cc-check-function-in-lib socket socket]} {
78 define-append LDLIBS [get-define lib_socket]
81 cc-check-functions ualarm lstat fork vfork system select
82 cc-check-functions backtrace geteuid mkstemp realpath strptime gettimeofday
83 cc-check-functions regcomp waitpid sigaction sys_signame sys_siglist
84 cc-check-functions syslog opendir readlink sleep usleep pipe getaddrinfo utimes
85 if {[cc-check-functions sysinfo]} {
86 cc-with {-includes sys/sysinfo.h} {
87 cc-check-members "struct sysinfo.uptime"
91 define TCL_LIBRARY [get-define prefix]/lib/jim
93 lassign [split [get-define host] -] host_cpu host_vendor host_os
94 # Scrub revision from the host_os
95 regsub -all {[0-9.]} $host_os {} host_os
97 switch -glob -- $host_os {
98 mingw* {
99 # We provide our own implementation of dlopen for mingw32
100 define-feature dlopen-compat
101 define TCL_PLATFORM_OS $host_os
102 define TCL_PLATFORM_PLATFORM windows
103 define TCL_PLATFORM_PATH_SEPARATOR {;}
105 default {
106 # Note that cygwin is considered a unix platform
107 define TCL_PLATFORM_OS $host_os
108 define TCL_PLATFORM_PLATFORM unix
109 define TCL_PLATFORM_PATH_SEPARATOR :
113 # Find some tools
114 cc-check-tools ar ranlib strip
115 define tclsh [info nameofexecutable]
117 if {![cc-check-functions _NSGetEnviron]} {
118 msg-checking "Checking environ declared in unistd.h..."
119 if {[cctest -cflags -D_GNU_SOURCE -includes unistd.h -code {char **ep = environ;}]} {
120 define NO_ENVIRON_EXTERN
121 msg-result "yes"
122 } else {
123 msg-result "no"
127 # Windows has a mkdir with no permission arg
128 cc-check-includes sys/types.h sys/stat.h
129 msg-checking "Checking for mkdir with one arg..."
130 if {[cctest -includes {sys/types.h sys/stat.h} -code {mkdir("/dummy");}]} {
131 define HAVE_MKDIR_ONE_ARG
132 msg-result yes
133 } else {
134 msg-result no
137 # autosetup can't handle C++ libraries
138 proc check-metakit {} {
139 set found 0
140 cc-with {-lang c++} {
141 msg-checking "Checking for Metakit..."
142 if {[cctest -includes mk4.h -libs -lmk4 -code {c4_Storage dummy();}]} {
143 msg-result ok
144 define lib_mk -lmk4
145 incr found
146 } else {
147 msg-result "not found"
150 return $found
153 set extra_objs {}
154 set jimregexp 0
156 if {[opt-bool utf8 full]} {
157 msg-result "Enabling UTF-8"
158 define JIM_UTF8
159 incr jimregexp
160 } else {
161 define JIM_UTF8 0
163 if {[opt-bool maintainer]} {
164 msg-result "Enabling maintainer settings"
165 define JIM_MAINTAINER
167 if {[opt-bool math full]} {
168 msg-result "Enabling math functions"
169 define JIM_MATH_FUNCTIONS
170 cc-check-function-in-lib sin m
171 define-append LDLIBS [get-define lib_sin]
173 if {[opt-bool ipv6 full]} {
174 msg-result "Enabling IPv6"
175 define JIM_IPV6
177 if {[opt-bool lineedit full] && [cc-check-includes termios.h] && [cc-check-functions isatty]} {
178 msg-result "Enabling line editing"
179 define USE_LINENOISE
180 lappend extra_objs linenoise.o
181 cc-check-functions isatty
183 if {[opt-bool references]} {
184 msg-result "Enabling references"
185 define JIM_REFERENCES
187 if {[opt-bool shared with-jim-shared]} {
188 msg-result "Building shared library"
189 } else {
190 msg-result "Building static library"
191 define JIM_STATICLIB
193 define JIM_INSTALL [opt-bool install-jim]
195 # Note: Extension handling is mapped directly from the configure.ac
196 # implementation
198 set without [join [opt-val {without-ext with-out-jim-ext}]]
199 set withext [join [opt-val {with-ext with-jim-ext}]]
200 set withmod [join [opt-val {with-mod with-jim-extmod}]]
202 # Tcl extensions
203 set ext_tcl "stdlib glob tclcompat tree rlprompt oo binary"
204 # Native extensions
205 set ext_c "load package readdir array clock exec file posix regexp signal aio eventloop pack syslog nvp readline mk sqlite sqlite3 win32"
207 # C++ extensions
208 set ext_cxx "mk"
210 # Tcl extensions which can be modules
211 set ext_tcl_mod "glob tree rlprompt oo binary"
212 # Native extensions which can be modules
213 set ext_c_mod "readdir array clock file posix regexp syslog readline pack mk sqlite sqlite3 win32"
215 # All extensions
216 set ext_all [concat $ext_c $ext_tcl]
218 # Default static extensions
219 set ext_default "stdlib load package readdir glob array clock exec file posix regexp signal tclcompat aio eventloop syslog"
221 if {[opt-bool full]} {
222 lappend ext_default tree binary
225 if {$without eq "default"} {
226 set ext_default stdlib
227 set without {}
230 # Check valid extension names
231 foreach i [concat $withext $without $withmod] {
232 if {$i ni $ext_all} {
233 user-error "Unknown extension: $i"
237 # needs_xxx="expression" means that the expr must eval to 1 to select the extension
238 # dep_xxx="yyy zzz" means that if xxx is selected, so is yyy and zzz
239 set dep(glob) readdir
240 set dep(rlprompt) readline
241 set dep(tree) oo
242 set dep(binary) pack
244 set needs(exec) {expr {([have-feature vfork] && [have-feature waitpid]) || [have-feature system]}}
245 set needs(load) {expr {[cc-check-function-in-lib dlopen dl] || [have-feature dlopen-compat]}}
246 set libdep(load) lib_dlopen
247 set needs(posix) {have-feature waitpid}
248 set needs(readdir) {have-feature opendir}
249 set needs(readline) {cc-check-function-in-lib readline readline}
250 set libdep(readline) lib_readline
251 set needs(signal) {expr {[have-feature sigaction] && [have-feature vfork]}}
252 set needs(mk) {check-metakit}
253 set libdep(mk) lib_mk
254 set needs(sqlite) {cc-check-function-in-lib sqlite_open sqlite}
255 set libdep(sqlite) lib_sqlite_open
256 set needs(sqlite3) {cc-check-function-in-lib sqlite3_open sqlite3}
257 set libdep(sqlite3) lib_sqlite3_open
258 set needs(syslog) {have-feature syslog}
259 set needs(win32) {have-feature windows}
261 # First handle dependencies. If an extension is enabled, also enable its dependency
262 foreach i [concat $ext_default $withext] {
263 if {$i in $without} {
264 continue
266 if {[info exists dep($i)]} {
267 lappend withext {*}$dep($i)
271 foreach i $withmod {
272 if {[info exists dep($i)]} {
273 # Theoretically, a mod could depend upon something which must be static
274 # If already configured static, don't make it a module
275 foreach d $dep($i) {
276 if {$d ni $withext} {
277 lappend withmod $d
283 # Now that we know what the platform supports:
285 # For all known extensions:
286 # - If it is disabled, remove it
287 # - Otherwise, check to see if it's pre-requisites are met
288 # - If yes, add it if it is enabled or is a default
289 # - If no, error if it is enabled, or do nothing otherwise
290 # - Modules may be either C or Tcl
292 set extmodtcl {}
293 set extmod {}
294 set ext {}
296 foreach i [lsort $ext_all] {
297 # First discard the extension if disabled or not enabled
298 if {$i in $without} {
299 msg-result "Extension $i...disabled"
300 continue
302 if {$i ni [concat $withext $withmod $ext_default]} {
303 msg-result "Extension $i...not enabled"
304 continue
307 # Check dependencies
308 set met 1
309 if {[info exists needs($i)]} {
310 set met [eval $needs($i)]
313 define LDLIBS_$i ""
315 msg-checking "Extension $i..."
317 # Selected as a module?
318 if {$i in $withmod} {
319 if {$i in $ext_tcl_mod} {
320 # Easy, a Tcl module
321 msg-result "tcl"
322 lappend extmodtcl $i
323 continue
325 if {$i ni $ext_c_mod} {
326 user-error "not a module"
328 if {!$met} {
329 user-error "dependencies not met"
331 msg-result "module"
332 lappend extmod $i
333 if {[info exists libdep($i)]} {
334 define-append LDLIBS_$i [get-define $libdep($i) ""]
336 continue
339 # Selected as a static extension?
340 if {$i in $withext} {
341 if {!$met} {
342 user-error "dependencies not met"
344 msg-result "enabled"
345 } elseif {$i in $ext_default} {
346 if {!$met} {
347 msg-result "disabled (dependencies)"
348 continue
350 msg-result "enabled (default)"
351 } else {
352 continue
355 lappend ext $i
356 if {[info exists libdep($i)]} {
357 define-append LDLIBS [get-define $libdep($i) ""]
361 if {[have-feature windows]} {
362 lappend extra_objs jim-win32compat.o
364 if {$extmod ne "" && [get-define JIM_LIBTYPE] eq "static"} {
365 user-error "cygwin/mingw require --shared for dynamic modules"
369 if {"regexp" in "$ext $extmod"} {
370 # No regcomp means we need to use the built-in version
371 if {![have-feature regcomp]} {
372 incr jimregexp
376 if {$jimregexp || [opt-bool jim-regexp]} {
377 msg-result "Using built-in regexp"
378 define JIM_REGEXP
380 # If the built-in regexp overrides the system regcomp, etc.
381 # jim must be built shared so that the correct symbols are found
382 if {"regexp" in $extmod && [get-define JIM_LIBTYPE] eq "static" && [have-feature regcomp]} {
383 user-error "Must use --shared with regexp module and built-in regexp"
386 if {"load" ni $ext} {
387 # If we don't have load, no need to support shared objects
388 define SH_LINKFLAGS ""
391 msg-result "Jim static extensions: [lsort $ext]"
392 if {$extmodtcl ne ""} {
393 msg-result "Jim Tcl extensions: [lsort $extmodtcl]"
395 if {$extmod ne ""} {
396 msg-result "Jim dynamic extensions: [lsort $extmod]"
399 # Separate out the static extensions into C and Tcl
400 set ext_static_c {}
401 set ext_static_tcl {}
402 foreach e $ext {
403 define jim_ext_$e
404 if {$e in $ext_tcl} {
405 lappend ext_static_tcl $e
406 } else {
407 lappend ext_static_c $e
411 # If there are any static C++ extensions, jimsh must be linked using
412 # the C++ compiler
413 foreach e $ext_static_c {
414 if {$e in $ext_cxx} {
415 define HAVE_CXX_EXTENSIONS
419 define STATIC_EXTS [concat $ext_static_c $ext_static_tcl]
420 define C_EXT_OBJS [prefix jim- [suffix .o $ext_static_c]]
421 define TCL_EXT_OBJS [suffix .o $ext_static_tcl]
422 define C_EXT_SHOBJS [suffix .so $extmod]
423 define TCL_EXTS [suffix .tcl $extmodtcl]
424 define EXTRA_OBJS $extra_objs
426 make-config-header jim-config.h -auto {HAVE_LONG_LONG* JIM_UTF8} -none *
427 make-config-header jimautoconf.h -auto {jim_ext_* TCL_PLATFORM_* TCL_LIBRARY USE_* JIM_*}
428 make-template Makefile.in