Changes to autosetup/README.autosetup.
Changes to autosetup/autosetup.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
-
+
+
-
+
-
+
|
#!/bin/sh
# Copyright (c) 2006-2011 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# vim:se syntax=tcl:
# \
dir=`dirname "$0"`; exec "`$dir/find-tclsh`" "$0" "$@"
dir=`dirname "$0"`; exec "`$dir/autosetup-find-tclsh`" "$0" "$@"
# Note that the version has a trailing + on unreleased versions
set autosetup(version) 0.6.6
set autosetup(version) 0.6.9
# Can be set to 1 to debug early-init problems
set autosetup(debug) 0
set autosetup(debug) [expr {"--debug" in $argv}]
##################################################################
#
# Main flow of control, option handling
#
proc main {argv} {
global autosetup define
|
︙ | | |
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
+
+
-
-
+
-
+
+
+
+
+
+
+
-
+
-
+
-
+
-
+
-
+
-
+
+
+
+
+
+
|
set autosetup(argv) $argv
set autosetup(cmdline) {}
# options is a list of known options
set autosetup(options) {}
# optset is a dictionary of option values set by the user based on getopt
set autosetup(optset) {}
# optdefault is a dictionary of default values for options
# optdefault is a dictionary of default values
set autosetup(optdefault) {}
# options-defaults is a dictionary of overrides for default values for options
set autosetup(options-defaults) {}
set autosetup(optionhelp) {}
set autosetup(showhelp) 0
use util
# Parse options
use getopt
# At the is point we don't know what is a valid option
# We simply parse anything that looks like an option
set autosetup(getopt) [getopt argv]
#"=Core Options:"
options-add {
help:=local => "display help and options. Optionally specify a module name, such as --help=system"
licence license => "display the autosetup license"
version => "display the version of autosetup"
ref:=text manual:=text
reference:=text => "display the autosetup command reference. 'text', 'wiki', 'asciidoc' or 'markdown'"
debug => "display debugging output as autosetup runs"
install:=. => "install autosetup to the current or given directory (in the 'autosetup/' subdirectory)"
install:=. => "install autosetup to the current or given directory"
}
if {$autosetup(installed)} {
# hidden options so we can produce a nice error
options-add {
sysinstall:path
}
} else {
options-add {
sysinstall:path => "install standalone autosetup to the given directory (e.g.: /usr/local)"
}
}
options-add {
force init:=help => "create initial auto.def, etc. Use --init=help for known types"
# Undocumented options
option-checking=1
nopager
quiet
timing
conf:
}
if {[opt-bool version]} {
puts $autosetup(version)
exit 0
}
# autosetup --conf=alternate-auto.def
if {[opt-val conf] ne ""} {
set autosetup(autodef) [opt-val conf]
if {[opt-str conf o]} {
set autosetup(autodef) $o
}
# Debugging output (set this early)
incr autosetup(debug) [opt-bool debug]
incr autosetup(force) [opt-bool force]
incr autosetup(msg-quiet) [opt-bool quiet]
incr autosetup(msg-timing) [opt-bool timing]
# If the local module exists, source it now to allow for
# project-local customisations
if {[file exists $autosetup(libdir)/local.tcl]} {
use local
}
# Now any auto-load modules
foreach file [glob -nocomplain $autosetup(libdir)/*.auto $autosetup(libdir)/*/*.auto] {
automf_load source $file
}
autosetup_load_auto_modules
if {[opt-val help] ne ""} {
if {[opt-str help o]} {
incr autosetup(showhelp)
use help
autosetup_help [opt-val help]
autosetup_help $o
}
if {[opt-bool licence license]} {
use help
autosetup_show_license
exit 0
}
if {[opt-val {manual ref reference}] ne ""} {
if {[opt-str {manual ref reference} o]} {
use help
autosetup_reference [opt-val {manual ref reference}]
autosetup_reference $o
}
# Allow combining --install and --init
set earlyexit 0
if {[opt-val install] ne ""} {
if {[opt-str install o]} {
use install
autosetup_install [opt-val install]
autosetup_install $o
incr earlyexit
}
if {[opt-val init] ne ""} {
if {[opt-str init o]} {
use init
autosetup_init [opt-val init]
autosetup_init $o
incr earlyexit
}
if {$earlyexit} {
exit 0
}
if {[opt-str sysinstall o]} {
use install
autosetup_install $o 1
exit 0
}
if {![file exists $autosetup(autodef)]} {
# Check for invalid option first
options {}
user-error "No auto.def found in \"$autosetup(srcdir)\" (use [file tail $::autosetup(exe)] --init to create one)"
}
|
︙ | | |
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
+
|
}
define AUTOREMAKE [file-normalize $autosetup(exe)]
define-append AUTOREMAKE [get-define CONFIGURE_OPTS]
# Log how we were invoked
configlog "Invoked as: [getenv WRAPPER $::argv0] [quote-argv $autosetup(argv)]"
configlog "Tclsh: [info nameofexecutable]"
# Note that auto.def is *not* loaded in the global scope
source $autosetup(autodef)
# Could warn here if options {} was not specified
show-notices
|
︙ | | |
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
-
+
-
+
|
# @opt-bool ?-nodefault? option ...
#
# Check each of the named, boolean options and if any have been explicitly enabled
# or disabled by the user, return 1 or 0 accordingly.
#
# If the option was specified more than once, the last value wins.
# e.g. With --enable-foo --disable-foo, [opt-bool foo] will return 0
# e.g. With '--enable-foo --disable-foo', '[opt-bool foo]' will return 0
#
# If no value was specified by the user, returns the default value for the
# first option. If -nodefault is given, this behaviour changes and
# first option. If '-nodefault' is given, this behaviour changes and
# -1 is returned instead.
#
proc opt-bool {args} {
set nodefault 0
if {[lindex $args 0] eq "-nodefault"} {
set nodefault 1
set args [lrange $args 1 end]
|
︙ | | |
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
-
+
-
+
-
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
if {$nodefault} {
return -1
}
# Default value is the default for the first option
return [dict get $::autosetup(optdefault) [lindex $args 0]]
}
# @opt-val option-list ?default=""?
# @opt-val optionlist ?default=""?
#
# Returns a list containing all the values given for the non-boolean options in 'option-list'.
# Returns a list containing all the values given for the non-boolean options in '$optionlist'.
# There will be one entry in the list for each option given by the user, including if the
# same option was used multiple times.
# If only a single value is required, use something like:
#
## lindex [opt-val $names] end
# If no options were set, '$default' is returned (exactly, not as a list).
#
# If no options were set, $default is returned (exactly, not as a list).
# Note: For most use cases, 'opt-str' should be preferred.
#
proc opt-val {names {default ""}} {
option-check-names {*}$names
foreach opt $names {
if {[dict exists $::autosetup(optset) $opt]} {
lappend result {*}[dict get $::autosetup(optset) $opt]
}
}
if {[info exists result]} {
return $result
}
return $default
}
# @opt-str optionlist varname ?default?
#
# Sets '$varname' in the callers scope to the value for one of the given options.
#
# For the list of options given in '$optionlist', if any value is set for any option,
# the option value is taken to be the *last* value of the last option (in the order given).
#
# If no option was given, and a default was specified with 'options-defaults',
# that value is used.
#
# If no 'options-defaults' value was given and '$default' was given, it is used.
#
# If none of the above provided a value, no value is set.
#
# The return value depends on whether '$default' was specified.
# If it was, the option value is returned.
# If it was not, 1 is returns if a value was set, or 0 if not.
#
# Typical usage is as follows:
#
## if {[opt-str {myopt altname} o]} {
## do something with $o
## }
#
# Or:
## define myname [opt-str {myopt altname} o "/usr/local"]
#
proc opt-str {names varname args} {
global autosetup
option-check-names {*}$names
upvar $varname value
if {[llength $args]} {
# A default was given, so always return the string value of the option
set default [lindex $args 0]
set retopt 1
} else {
# No default, so return 0 or 1 to indicate if a value was found
set retopt 0
}
foreach opt $names {
if {[dict exists $::autosetup(optset) $opt]} {
set result [lindex [dict get $::autosetup(optset) $opt] end]
}
}
if {![info exists result]} {
# No user-specified value. Has options-defaults been set?
foreach opt $names {
if {[dict exists $::autosetup(options-defaults) $opt]} {
set result [dict get $autosetup(options-defaults) $opt]
}
}
}
if {[info exists result]} {
set value $result
if {$retopt} {
return $value
}
return 1
}
if {$retopt} {
set value $default
return $value
}
return 0
}
proc option-check-names {args} {
foreach o $args {
if {$o ni $::autosetup(options)} {
autosetup-error "Request for undeclared option --$o"
}
}
|
︙ | | |
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
|
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
|
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
|
set opt [lindex $opts $i]
if {[string match =* $opt]} {
# This is a special heading
lappend autosetup(optionhelp) $opt ""
set header {}
continue
}
unset -nocomplain defaultvalue equal value
#puts "i=$i, opt=$opt"
regexp {^([^:=]*)(:)?(=)?(.*)$} $opt -> name colon equal value
if {$name in $autosetup(options)} {
autosetup-error "Option $name already specified"
}
#puts "$opt => $name $colon $equal $value"
# Find the corresponding value in the user options
# and set the default if necessary
if {[string match "-*" $opt]} {
# This is a documentation-only option, like "-C <dir>"
set opthelp $opt
} elseif {$colon eq ""} {
# Boolean option
lappend autosetup(options) $name
# Check for override
if {[dict exists $autosetup(options-defaults) $name]} {
# A default was specified with options-defaults, so use it
set value [dict get $autosetup(options-defaults) $name]
}
if {$value eq "1"} {
set opthelp "--disable-$name"
} else {
set opthelp "--$name"
}
# Set the default
if {$value eq ""} {
set value 0
}
set defaultvalue $value
dict set autosetup(optdefault) $name $value
dict set autosetup(optdefault) $name $defaultvalue
if {[dict exists $autosetup(getopt) $name]} {
# The option was specified by the user. Look at the last value.
lassign [lindex [dict get $autosetup(getopt) $name] end] type setvalue
if {$type eq "str"} {
# Can we convert the value to a boolean?
if {$setvalue in {1 enabled yes}} {
set setvalue 1
} elseif {$setvalue in {0 disabled no}} {
set setvalue 0
} else {
user-error "Boolean option $name given as --$name=$setvalue"
}
}
dict set autosetup(optset) $name $setvalue
#puts "Found boolean option --$name=$setvalue"
}
} else {
# String option.
lappend autosetup(options) $name
if {$colon eq ":"} {
# Was ":name=default" given?
# If so, set $value to the display name and $defaultvalue to the default
# (This is the preferred way to set a default value for a string option)
if {[regexp {^([^=]+)=(.*)$} $value -> value defaultvalue]} {
dict set autosetup(optdefault) $name $defaultvalue
}
}
# Maybe override the default value
if {[dict exists $autosetup(options-defaults) $name]} {
# A default was specified with options-defaults, so use it
set defaultvalue [dict get $autosetup(options-defaults) $name]
dict set autosetup(optdefault) $name $defaultvalue
} elseif {![info exists defaultvalue]} {
# For backward compatibility, if ":name" was given, use name as both
# the display text and the default value, but only if the user
# specified the option without the value
set defaultvalue $value
}
if {$equal eq "="} {
# String option with optional value
set opthelp "--$name?=$value?"
} else {
# String option with required value
set opthelp "--$name=$value"
}
dict set autosetup(optdefault) $name $value
# Get the values specified by the user
if {[dict exists $autosetup(getopt) $name]} {
set listvalue {}
foreach pair [dict get $autosetup(getopt) $name] {
lassign $pair type setvalue
if {$type eq "bool" && $setvalue} {
if {$equal ne "="} {
user-error "Option --$name requires a value"
}
# If given as a boolean, use the default value
set setvalue $value
set setvalue $defaultvalue
}
lappend listvalue $setvalue
}
#puts "Found string option --$name=$listvalue"
dict set autosetup(optset) $name $listvalue
}
}
# Now create the help for this option if appropriate
if {[lindex $opts $i+1] eq "=>"} {
set desc [lindex $opts $i+2]
if {[info exists defaultvalue]} {
set desc [string map [list @default@ $defaultvalue] $desc]
}
#string match \n* $desc
if {$header ne ""} {
lappend autosetup(optionhelp) $header ""
set header ""
}
# A multi-line description
lappend autosetup(optionhelp) $opthelp $desc
|
︙ | | |
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
|
-
+
-
+
+
-
-
+
+
-
-
+
+
+
+
+
-
-
+
+
-
+
|
puts $desc
} else {
options-wrap-desc [string trim $desc] $cols " " $indent [expr $max + 2]
}
}
}
# @options options-spec
# @options optionspec
#
# Specifies configuration-time options which may be selected by the user
# and checked with opt-val and opt-bool. The format of options-spec follows.
# and checked with 'opt-str' and 'opt-bool'. '$optionspec' contains a series
# of options specifications separated by newlines, as follows:
#
# A boolean option is of the form:
#
## name[=0|1] => "Description of this boolean option"
#
# The default is name=0, meaning that the option is disabled by default.
# If name=1 is used to make the option enabled by default, the description should reflect
# The default is 'name=0', meaning that the option is disabled by default.
# If 'name=1' is used to make the option enabled by default, the description should reflect
# that with text like "Disable support for ...".
#
# An argument option (one which takes a parameter) is of the form:
#
## name:[=]value => "Description of this option"
#
# If the name:value form is used, the value must be provided with the option (as --name=myvalue).
# If the name:=value form is used, the value is optional and the given value is used as the default
# If the 'name:value' form is used, the value must be provided with the option (as '--name=myvalue').
# If the 'name:=value' form is used, the value is optional and the given value is used as the default
# if it is not provided.
#
# The description may contain '@default@', in which case it will be replaced with the default
# value for the option (taking into account defaults specified with 'options-defaults'.
#
# Undocumented options are also supported by omitting the "=> description.
# These options are not displayed with --help and can be useful for internal options or as aliases.
# Undocumented options are also supported by omitting the '=> description'.
# These options are not displayed with '--help' and can be useful for internal options or as aliases.
#
# For example, --disable-lfs is an alias for --disable=largefile:
# For example, '--disable-lfs' is an alias for '--disable=largefile':
#
## lfs=1 largefile=1 => "Disable large file support"
#
proc options {optlist} {
# Allow options as a list or args
options-add $optlist "Local Options:"
|
︙ | | |
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
|
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
|
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
+
+
+
+
+
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
+
-
+
-
+
-
+
|
foreach o [dict keys $::autosetup(getopt)] {
if {$o ni $::autosetup(options)} {
user-error "Unknown option --$o"
}
}
}
}
# @options-defaults dictionary
#
# Specifies a dictionary of options and a new default value for each of those options.
# Use before any 'use' statements in 'auto.def' to change the defaults for
# subsequently included modules.
proc options-defaults {dict} {
foreach {n v} $dict {
dict set ::autosetup(options-defaults) $n $v
}
}
proc config_guess {} {
if {[file-isexec $::autosetup(dir)/config.guess]} {
if {[file-isexec $::autosetup(dir)/autosetup-config.guess]} {
exec-with-stderr sh $::autosetup(dir)/config.guess
if {[catch {exec-with-stderr sh $::autosetup(dir)/config.guess} alias]} {
if {[catch {exec-with-stderr sh $::autosetup(dir)/autosetup-config.guess} alias]} {
user-error $alias
}
return $alias
} else {
configlog "No config.guess, so using uname"
configlog "No autosetup-config.guess, so using uname"
string tolower [exec uname -p]-unknown-[exec uname -s][exec uname -r]
}
}
proc config_sub {alias} {
if {[file-isexec $::autosetup(dir)/config.sub]} {
if {[catch {exec-with-stderr sh $::autosetup(dir)/config.sub $alias} alias]} {
if {[file-isexec $::autosetup(dir)/autosetup-config.sub]} {
if {[catch {exec-with-stderr sh $::autosetup(dir)/autosetup-config.sub $alias} alias]} {
user-error $alias
}
}
return $alias
}
# @define name ?value=1?
#
# Defines the named variable to the given value.
# These (name, value) pairs represent the results of the configuration check
# and are available to be checked, modified and substituted.
# and are available to be subsequently checked, modified and substituted.
#
proc define {name {value 1}} {
set ::define($name) $value
#dputs "$name <= $value"
}
# @undefine name
#
# Undefine the named variable
# Undefine the named variable.
#
proc undefine {name} {
unset -nocomplain ::define($name)
#dputs "$name <= <undef>"
}
# @define-append name value ...
#
# Appends the given value(s) to the given 'defined' variable.
# If the variable is not defined or empty, it is set to $value.
# Appends the given value(s) to the given "defined" variable.
# If the variable is not defined or empty, it is set to '$value'.
# Otherwise the value is appended, separated by a space.
# Any extra values are similarly appended.
# If any value is already contained in the variable (as a substring) it is omitted.
#
proc define-append {name args} {
if {[get-define $name ""] ne ""} {
# Make a token attempt to avoid duplicates
# Avoid duplicates
foreach arg $args {
if {$arg eq ""} {
continue
}
set found 0
if {[string first $arg $::define($name)] == -1} {
foreach str [split $::define($name) " "] {
if {$str eq $arg} {
incr found
}
}
if {!$found} {
append ::define($name) " " $arg
}
}
} else {
set ::define($name) [join $args]
}
#dputs "$name += [join $args] => $::define($name)"
}
# @get-define name ?default=0?
#
# Returns the current value of the 'defined' variable, or $default
# Returns the current value of the "defined" variable, or '$default'
# if not set.
#
proc get-define {name {default 0}} {
if {[info exists ::define($name)]} {
#dputs "$name => $::define($name)"
return $::define($name)
}
#dputs "$name => $default"
return $default
}
# @is-defined name
#
# Returns 1 if the given variable is defined.
#
proc is-defined {name} {
info exists ::define($name)
}
# @is-define-set name
#
# Returns 1 if the given variable is defined and is set
# to a value other than "" or 0
#
proc is-define-set {name} {
if {[get-define $name] in {0 ""}} {
return 0
}
return 1
}
# @all-defines
#
# Returns a dictionary (name value list) of all defined variables.
# Returns a dictionary (name, value list) of all defined variables.
#
# This is suitable for use with 'dict', 'array set' or 'foreach'
# and allows for arbitrary processing of the defined variables.
#
proc all-defines {} {
array get ::define
}
# @get-env name default
#
# If $name was specified on the command line, return it.
# If $name was set in the environment, return it.
# Otherwise return $default.
# If '$name' was specified on the command line, return it.
# Otherwise if '$name' was set in the environment, return it.
# Otherwise return '$default'.
#
proc get-env {name default} {
if {[dict exists $::autosetup(cmdline) $name]} {
return [dict get $::autosetup(cmdline) $name]
}
getenv $name $default
}
# @env-is-set name
#
# Returns 1 if the $name was specified on the command line or in the environment.
# Returns 1 if '$name' was specified on the command line or in the environment.
# Note that an empty environment variable is not considered to be set.
#
proc env-is-set {name} {
if {[dict exists $::autosetup(cmdline) $name]} {
return 1
}
if {[getenv $name ""] ne ""} {
return 1
}
return 0
}
# @readfile filename ?default=""?
#
# Return the contents of the file, without the trailing newline.
# If the file doesn't exist or can't be read, returns $default.
# If the file doesn't exist or can't be read, returns '$default'.
#
proc readfile {filename {default_value ""}} {
set result $default_value
catch {
set f [open $filename]
set result [read -nonewline $f]
close $f
}
return $result
}
# @writefile filename value
#
# Creates the given file containing $value.
# Creates the given file containing '$value'.
# Does not add an extra newline.
#
proc writefile {filename value} {
set f [open $filename w]
puts -nonewline $f $value
close $f
}
|
︙ | | |
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
|
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
|
-
+
-
+
-
-
-
-
-
+
+
-
-
+
+
+
-
+
+
+
-
-
-
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
+
-
-
-
-
-
-
+
-
-
-
|
set args {}
foreach arg $argv {
lappend args [quote-if-needed $arg]
}
join $args
}
# @suffix suf list
# @list-non-empty list
#
# Takes a list and returns a new list with $suf appended
# Returns a copy of the given list with empty elements removed
# to each element
#
## suffix .c {a b c} => {a.c b.c c.c}
#
proc suffix {suf list} {
proc list-non-empty {list} {
set result {}
foreach p $list {
if {$p ne ""} {
lappend result $p$suf
}
lappend result $p
}
}
return $result
}
# @prefix pre list
# @find-executable-path name
#
# Searches the path for an executable with the given name.
# Note that the name may include some parameters, e.g. 'cc -mbig-endian',
# Takes a list and returns a new list with $pre prepended
# to each element
#
# in which case the parameters are ignored.
# The full path to the executable if found, or "" if not found.
# Returns 1 if found, or 0 if not.
## prefix jim- {a.c b.c} => {jim-a.c jim-b.c}
#
proc prefix {pre list} {
set result {}
foreach p $list {
lappend result $pre$p
}
return $result
proc find-executable-path {name} {
# Ignore any parameters
set name [lindex $name 0]
# The empty string is never a valid executable
if {$name ne ""} {
foreach p [split-path] {
dputs "Looking for $name in $p"
set exec [file join $p $name]
if {[file-isexec $exec]} {
dputs "Found $name -> $exec"
return $exec
}
}
}
return {}
}
# @find-executable name
#
# Searches the path for an executable with the given name.
# Note that the name may include some parameters, e.g. "cc -mbig-endian",
# Note that the name may include some parameters, e.g. 'cc -mbig-endian',
# in which case the parameters are ignored.
# Returns 1 if found, or 0 if not.
#
proc find-executable {name} {
# Ignore any parameters
set name [lindex $name 0]
if {$name eq ""} {
# The empty string is never a valid executable
if {[find-executable-path $name] eq {}} {
return 0
}
foreach p [split-path] {
dputs "Looking for $name in $p"
set exec [file join $p $name]
if {[file-isexec $exec]} {
dputs "Found $name -> $exec"
return 1
return 1
}
}
return 0
}
# @find-an-executable ?-required? name ...
#
# Given a list of possible executable names,
# searches for one of these on the path.
#
|
︙ | | |
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
|
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
|
-
+
|
}
}
return ""
}
# @configlog msg
#
# Writes the given message to the configuration log, config.log
# Writes the given message to the configuration log, 'config.log'.
#
proc configlog {msg} {
if {![info exists ::autosetup(logfh)]} {
set ::autosetup(logfh) [open config.log w]
}
puts $::autosetup(logfh) $msg
}
|
︙ | | |
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
|
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
|
-
-
+
+
|
set ::autosetup(msg-checking) 0
show-notices
}
}
# @msg-quiet command ...
#
# msg-quiet evaluates it's arguments as a command with output
# from msg-checking and msg-result suppressed.
# 'msg-quiet' evaluates it's arguments as a command with output
# from 'msg-checking' and 'msg-result' suppressed.
#
# This is useful if a check needs to run a subcheck which isn't
# of interest to the user.
proc msg-quiet {args} {
incr ::autosetup(msg-quiet)
set rc [uplevel 1 $args]
incr ::autosetup(msg-quiet) -1
|
︙ | | |
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
|
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
|
-
+
|
#
# Usage errors such as wrong command line options
# @user-error msg
#
# Indicate incorrect usage to the user, including if required components
# or features are not found.
# autosetup exits with a non-zero return code.
# 'autosetup' exits with a non-zero return code.
#
proc user-error {msg} {
show-notices
puts stderr "Error: $msg"
puts stderr "Try: '[file tail $::autosetup(exe)] --help' for options"
exit 1
}
|
︙ | | |
885
886
887
888
889
890
891
892
893
894
895
896
897
898
|
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
|
+
+
+
+
+
+
+
+
+
+
+
|
}
proc maybe-show-timestamp {} {
if {$::autosetup(msg-timing) && $::autosetup(msg-checking) == 0} {
puts -nonewline [format {[%6.2f] } [expr {([clock millis] - $::autosetup(start)) % 10000 / 1000.0}]]
}
}
# @autosetup-require-version required
#
# Checks the current version of 'autosetup' against '$required'.
# A fatal error is generated if the current version is less than that required.
#
proc autosetup-require-version {required} {
if {[compare-versions $::autosetup(version) $required] < 0} {
user-error "autosetup version $required is required, but this is $::autosetup(version)"
}
}
proc autosetup_version {} {
return "autosetup v$::autosetup(version)"
}
##################################################################
#
|
︙ | | |
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
|
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
|
+
+
+
+
+
+
-
+
-
-
-
+
+
+
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
|
# or 'autosetup/X/init.tcl'
#
# The latter form is useful for a complex module which requires additional
# support file. In this form, '$::usedir' is set to the module directory
# when it is loaded.
#
proc use {args} {
global autosetup libmodule modsource
set dirs [list $autosetup(libdir)]
if {[info exists autosetup(srcdir)]} {
lappend dirs $autosetup(srcdir)/autosetup
}
foreach m $args {
if {[info exists ::libmodule($m)]} {
if {[info exists libmodule($m)]} {
continue
}
set ::libmodule($m) 1
if {[info exists ::modsource($m)]} {
automf_load eval $::modsource($m)
set libmodule($m) 1
if {[info exists modsource(${m}.tcl)]} {
automf_load eval $modsource(${m}.tcl)
} else {
set sources [list $::autosetup(libdir)/${m}.tcl $::autosetup(libdir)/${m}/init.tcl]
set locs [list ${m}.tcl ${m}/init.tcl]
set found 0
foreach dir $dirs {
foreach loc $locs {
foreach source $sources {
if {[file exists $source]} {
incr found
set source $dir/$loc
if {[file exists $source]} {
incr found
break
}
}
if {$found} {
break
}
}
if {$found} {
# For the convenience of the "use" source, point to the directory
# it is being loaded from
set ::usedir [file dirname $source]
automf_load source $source
autosetup_add_dep $source
} else {
autosetup-error "use: No such module: $m"
}
}
}
}
proc autosetup_load_auto_modules {} {
global autosetup modsource
# First load any embedded auto modules
foreach mod [array names modsource *.auto] {
automf_load eval $modsource($mod)
}
# Now any external auto modules
foreach file [glob -nocomplain $autosetup(libdir)/*.auto $autosetup(libdir)/*/*.auto] {
automf_load source $file
}
}
# Load module source in the global scope by executing the given command
proc automf_load {args} {
if {[catch [list uplevel #0 $args] msg opts] ni {0 2 3}} {
autosetup-full-error [error-dump $msg $opts $::autosetup(debug)]
}
}
# Initial settings
set autosetup(exe) $::argv0
set autosetup(istcl) 1
set autosetup(start) [clock millis]
set autosetup(installed) 0
set autosetup(sysinstall) 0
set autosetup(msg-checking) 0
set autosetup(msg-quiet) 0
set autosetup(inittypes) {}
# Embedded modules are inserted below here
set autosetup(installed) 1
set autosetup(sysinstall) 0
# ----- module asciidoc-formatting -----
# ----- @module asciidoc-formatting.tcl -----
set modsource(asciidoc-formatting) {
set modsource(asciidoc-formatting.tcl) {
# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module which provides text formatting
# asciidoc format
use formatting
|
︙ | | |
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
|
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
|
-
+
-
+
-
+
|
}
set defn [string trim [join $args \n]]
regsub -all "\n\n" $defn "\n ::\n" defn
puts $defn
}
}
# ----- module formatting -----
# ----- @module formatting.tcl -----
set modsource(formatting) {
set modsource(formatting.tcl) {
# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module which provides common text formatting
# This is designed for documenation which looks like:
# This is designed for documentation which looks like:
# code {...}
# or
# code {
# ...
# ...
# }
# In the second case, we need to work out the indenting
|
︙ | | |
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
|
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
|
-
+
-
+
|
}
# Return the result
return $lines
}
}
# ----- module getopt -----
# ----- @module getopt.tcl -----
set modsource(getopt) {
set modsource(getopt.tcl) {
# Copyright (c) 2006 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Simple getopt module
# Parse everything out of the argv list which looks like an option
# Everything which doesn't look like an option, or is after --, is left unchanged
|
︙ | | |
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
|
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
|
-
+
-
+
-
+
|
break
}
if {[regexp {^--([^=][^=]+)=(.*)$} $arg -> name value]} {
# --name=value
dict lappend opts $name [list str $value]
} elseif {[regexp {^--(enable-|disable-)?([^=]*)$} $arg -> prefix name]} {
if {$prefix in {enable- with- ""}} {
if {$prefix in {enable- ""}} {
set value 1
} else {
set value 0
}
dict lappend opts $name [list bool $value]
} else {
lappend nargv $arg
}
}
#puts "getopt: argv=[join $argv] => [join $nargv]"
#array set getopt $opts
#parray getopt
set argv $nargv
return $opts
}
}
# ----- module help -----
# ----- @module help.tcl -----
set modsource(help) {
set modsource(help.tcl) {
# Copyright (c) 2010 WorkWare Systems http://workware.net.au/
# All rights reserved
# Module which provides usage, help and the command reference
proc autosetup_help {what} {
use_pager
|
︙ | | |
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
|
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
user-error "Unknown module: $what"
} else {
options-show
}
}
exit 0
}
proc autosetup_show_license {} {
global modsource autosetup
use_pager
if {[info exists modsource(LICENSE)]} {
puts $modsource(LICENSE)
return
}
foreach dir [list $autosetup(libdir) $autosetup(srcdir)] {
set path [file join $dir LICENSE]
if {[file exists $path]} {
puts [readfile $path]
return
}
}
puts "LICENSE not found"
}
# If not already paged and stdout is a tty, pipe the output through the pager
# This is done by reinvoking autosetup with --nopager added
proc use_pager {} {
if {![opt-bool nopager] && [getenv PAGER ""] ne "" && [isatty? stdin] && [isatty? stdout]} {
if {[catch {
exec [info nameofexecutable] $::argv0 --nopager {*}$::argv |& {*}[getenv PAGER] >@stdout <@stdin 2>@stderr
|
︙ | | |
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
|
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
|
+
+
+
+
+
+
|
exit 0
}
proc autosetup_output_block {type lines} {
if {[llength $lines]} {
switch $type {
section {
section $lines
}
subsection {
subsection $lines
}
code {
codelines $lines
}
p {
p [join $lines]
}
list {
|
︙ | | |
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
|
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
|
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
|
}
# Generate a command reference from inline documentation
proc automf_command_reference {} {
lappend files $::autosetup(prog)
lappend files {*}[lsort [glob -nocomplain $::autosetup(libdir)/*.tcl]]
# We want to process all non-module files before module files
# and then modules in alphabetical order.
# So examine all files and extract docs into doc($modulename) and doc(_core_)
#
# Each entry is a list of {type data} where $type is one of: section, subsection, code, list, p
section "Core Commands"
set type p
set lines {}
set cmd {}
# and $data is a string for section, subsection or a list of text lines for other types.
# XXX: Should commands be in alphabetical order too? Currently they are in file order.
set doc(_core_) {}
lappend doc(_core_) [list section "Core Commands"]
foreach file $files {
set modulename [file rootname [file tail $file]]
set current _core_
set f [open $file]
while {![eof $f]} {
set line [gets $f]
# Find embedded module names
if {[regexp {^#.*@module ([^ ]*)} $line -> modulename]} {
continue
}
# Find lines starting with "# @*" and continuing through the remaining comment lines
if {![regexp {^# @(.*)} $line -> cmd]} {
continue
}
# Synopsis or command?
if {$cmd eq "synopsis:"} {
set current $modulename
section "Module: [file rootname [file tail $file]]"
lappend doc($current) [list section "Module: $modulename"]
} else {
subsection $cmd
lappend doc($current) [list subsection $cmd]
}
set lines {}
set type p
# Now the description
while {![eof $f]} {
|
︙ | | |
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
|
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
|
-
+
-
+
+
+
+
+
+
+
+
+
+
-
+
-
+
|
set t p
}
#puts "hash=$hash, oldhash=$oldhash, lines=[llength $lines], cmd=$cmd"
if {$t ne $type || $cmd eq ""} {
# Finish the current block
autosetup_output_block $type $lines
lappend doc($current) [list $type $lines]
set lines {}
set type $t
}
if {$cmd ne ""} {
lappend lines $cmd
}
}
autosetup_output_block $type $lines
lappend doc($current) [list $type $lines]
}
close $f
}
# Now format and output the results
# _core_ will sort first
foreach module [lsort [array names doc]] {
foreach item $doc($module) {
autosetup_output_block {*}$item
}
}
}
}
# ----- module init -----
# ----- @module init.tcl -----
set modsource(init) {
set modsource(init.tcl) {
# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module to help create auto.def and configure
proc autosetup_init {type} {
set help 0
|
︙ | | |
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
|
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
|
-
+
-
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
-
+
-
+
+
+
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
-
-
-
+
+
+
+
+
+
-
+
+
-
-
+
+
+
-
+
+
-
+
+
+
+
+
+
-
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
-
+
|
} else {
puts "I don't see $filename, so I will create it."
}
writefile $filename $contents
}
}
# ----- module install -----
# ----- @module install.tcl -----
set modsource(install) {
set modsource(install.tcl) {
# Copyright (c) 2006-2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module which can install autosetup
# autosetup(installed)=1 means that autosetup is not running from source
# autosetup(sysinstall)=1 means that autosetup is running from a sysinstall version
# shared=1 means that we are trying to do a sysinstall. This is only possible from the development source.
proc autosetup_install {dir} {
proc autosetup_install {dir {shared 0}} {
global autosetup
if {$shared} {
if {$autosetup(installed) || $autosetup(sysinstall)} {
user-error "Can only --sysinstall from development sources"
}
} elseif {$autosetup(installed) && !$autosetup(sysinstall)} {
user-error "Can't --install from project install"
}
if {$autosetup(sysinstall)} {
# This is the sysinstall version, so install just uses references
cd $dir
puts "[autosetup_version] creating configure to use system-installed autosetup"
autosetup_create_configure 1
puts "Creating autosetup/README.autosetup"
file mkdir autosetup
autosetup_install_readme autosetup/README.autosetup 1
return
}
if {[catch {
if {$shared} {
set target $dir/bin/autosetup
set installedas $target
} else {
if {$dir eq "."} {
set installedas autosetup
} else {
set installedas $dir/autosetup
}
cd $dir
file mkdir autosetup
set f [open autosetup/autosetup w]
cd $dir
file mkdir autosetup
set target autosetup/autosetup
}
set targetdir [file dirname $target]
file mkdir $targetdir
set f [open $target w]
set publicmodules [glob $::autosetup(libdir)/*.auto]
set publicmodules {}
# First the main script, but only up until "CUT HERE"
set in [open $::autosetup(dir)/autosetup]
set in [open $autosetup(dir)/autosetup]
while {[gets $in buf] >= 0} {
if {$buf ne "##-- CUT HERE --##"} {
puts $f $buf
continue
}
# Insert the static modules here
# i.e. those which don't contain @synopsis:
# All modules are inserted if $shared is set
puts $f "set autosetup(installed) 1"
puts $f "set autosetup(sysinstall) $shared"
foreach file [lsort [glob $::autosetup(libdir)/*.tcl]] {
foreach file [lsort [glob $autosetup(libdir)/*.{tcl,auto}]] {
set modname [file tail $file]
set ext [file ext $modname]
set buf [readfile $file]
if {!$shared} {
if {[string match "*\n# @synopsis:*" $buf]} {
lappend publicmodules $file
continue
}
set modname [file rootname [file tail $file]]
puts $f "# ----- module $modname -----"
if {$ext eq ".auto" || [string match "*\n# @synopsis:*" $buf]} {
lappend publicmodules $file
continue
}
}
dputs "install: importing lib/[file tail $file]"
puts $f "# ----- @module $modname -----"
puts $f "\nset modsource($modname) \{"
puts $f $buf
puts $f "\}\n"
}
if {$shared} {
foreach {srcname destname} [list $autosetup(libdir)/README.autosetup-lib README.autosetup \
$autosetup(srcdir)/LICENSE LICENSE] {
dputs "install: importing $srcname as $destname"
puts $f "\nset modsource($destname) \\\n[list [readfile $srcname]\n]\n"
}
}
}
close $in
close $f
exec chmod 755 autosetup/autosetup
catch {exec chmod 755 $target}
set installfiles {autosetup-config.guess autosetup-config.sub autosetup-test-tclsh}
set removefiles {}
if {!$shared} {
autosetup_install_readme $targetdir/README.autosetup 0
# Install public modules
foreach file $publicmodules {
autosetup_install_file $file autosetup
}
# Install public modules
foreach file $publicmodules {
set tail [file tail $file]
autosetup_install_file $file $targetdir/$tail
}
lappend installfiles jimsh0.c autosetup-find-tclsh LICENSE
lappend removefiles config.guess config.sub test-tclsh find-tclsh
} else {
lappend installfiles {sys-find-tclsh autosetup-find-tclsh}
}
# Install support files
foreach file {config.guess config.sub jimsh0.c find-tclsh test-tclsh LICENSE} {
autosetup_install_file $::autosetup(dir)/$file autosetup
foreach fileinfo $installfiles {
if {[llength $fileinfo] == 2} {
lassign $fileinfo source dest
} else {
lassign $fileinfo source
set dest $source
}
autosetup_install_file $autosetup(dir)/$source $targetdir/$dest
}
exec chmod 755 autosetup/config.sub autosetup/config.guess autosetup/find-tclsh
# Remove obsolete files
foreach file $removefiles {
if {[file exists $targetdir/$file]} {
file delete $targetdir/$file
}
writefile autosetup/README.autosetup \
"This is [autosetup_version]. See http://msteveb.github.com/autosetup/\n"
}
} error]} {
user-error "Failed to install autosetup: $error"
}
if {$shared} {
set type "system"
} else {
set type "local"
}
puts "Installed [autosetup_version] to autosetup/"
puts "Installed $type [autosetup_version] to $installedas"
if {!$shared} {
# Now create 'configure' if necessary
autosetup_create_configure
# Now create 'configure' if necessary
autosetup_create_configure 0
}
}
proc autosetup_create_configure {} {
proc autosetup_create_configure {shared} {
if {[file exists configure]} {
if {!$::autosetup(force)} {
# Could this be an autosetup configure?
if {![string match "*\nWRAPPER=*" [readfile configure]]} {
puts "I see configure, but not created by autosetup, so I won't overwrite it."
puts "Remove it or use --force to overwrite."
return
}
} else {
puts "I will overwrite the existing configure because you used --force."
}
} else {
puts "I don't see configure, so I will create it."
}
if {$shared} {
writefile configure \
writefile configure \
{#!/bin/sh
WRAPPER="$0"; export WRAPPER; "autosetup" "$@"
}
} else {
writefile configure \
{#!/bin/sh
dir="`dirname "$0"`/autosetup"
WRAPPER="$0"; export WRAPPER; exec "`$dir/find-tclsh`" "$dir/autosetup" "$@"
WRAPPER="$0"; export WRAPPER; exec "`"$dir/autosetup-find-tclsh"`" "$dir/autosetup" "$@"
}
}
catch {exec chmod 755 configure}
}
# Append the contents of $file to filehandle $f
proc autosetup_install_append {f file} {
dputs "install: include $file"
set in [open $file]
puts $f [read $in]
close $in
}
proc autosetup_install_file {file dir} {
if {![file exists $file]} {
error "Missing installation file '$file'"
proc autosetup_install_file {source target} {
dputs "install: $source => $target"
if {![file exists $source]} {
error "Missing installation file '$source'"
}
writefile $target [readfile $source]\n
# If possible, copy the file mode
file stat $source stat
set mode [format %o [expr {$stat(mode) & 0x1ff}]]
catch {exec chmod $mode $target}
}
writefile [file join $dir [file tail $file]] [readfile $file]\n
proc autosetup_install_readme {target sysinstall} {
set readme "README.autosetup created by [autosetup_version]\n\n"
if {$sysinstall} {
append readme \
{This is the autosetup directory for a system install of autosetup.
Loadable modules can be added here.
}
} else {
append readme \
{This is the autosetup directory for a local install of autosetup.
It contains autosetup, support files and loadable modules.
if {$::autosetup(installed)} {
user-error "autosetup can only be installed from development source, not from installed copy"
}
}
}
append readme {
*.tcl files in this directory are optional modules which
can be loaded with the 'use' directive.
*.auto files in this directory are auto-loaded.
For more information, see http://msteveb.github.com/autosetup/
}
dputs "install: autosetup/README.autosetup"
writefile $target $readme
# ----- module markdown-formatting -----
}
}
# ----- @module markdown-formatting.tcl -----
set modsource(markdown-formatting) {
set modsource(markdown-formatting.tcl) {
# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module which provides text formatting
# markdown format (kramdown syntax)
use formatting
|
︙ | | |
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
|
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
|
-
+
-
+
|
puts -nonewline ": "
regsub -all "\n\n" $defn "\n: " defn
}
puts "$defn"
}
}
# ----- module misc -----
# ----- @module misc.tcl -----
set modsource(misc) {
set modsource(misc.tcl) {
# Copyright (c) 2007-2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module containing misc procs useful to modules
# Largely for platform compatibility
set autosetup(istcl) [info exists ::tcl_library]
|
︙ | | |
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
|
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
|
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
-
+
-
-
-
+
+
+
-
-
+
+
-
-
+
+
-
+
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
|
# Remove the trailing newline
string trim $result
}
}
}
# ----- module text-formatting -----
# ----- @module text-formatting.tcl -----
set modsource(text-formatting) {
set modsource(text-formatting.tcl) {
# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module which provides text formatting
use formatting
proc wordwrap {text length {firstprefix ""} {nextprefix ""}} {
set len 0
set space $firstprefix
foreach word [split $text] {
set word [string trim $word]
if {$word == ""} {
continue
}
if {$len && [string length $space$word] + $len >= $length} {
puts ""
set len 0
set space $nextprefix
}
incr len [string length $space$word]
set len 0
set space $firstprefix
foreach word [split $text] {
set word [string trim $word]
if {$word eq ""} {
continue
}
if {[info exists partial]} {
append partial " " $word
if {[string first $quote $word] < 0} {
# Haven't found end of quoted word
continue
}
# Finished quoted word
set word $partial
unset partial
unset quote
} else {
set quote [string index $word 0]
if {$quote in {' *}} {
if {[string first $quote $word 1] < 0} {
# Haven't found end of quoted word
# Not a whole word.
set first [string index $word 0]
# Start of quoted word
set partial $word
continue
}
}
}
if {$len && [string length $space$word] + $len >= $length} {
puts ""
set len 0
set space $nextprefix
}
incr len [string length $space$word]
# Use man-page conventions for highlighting 'quoted' and *quoted*
# single words.
# Use x^Hx for *bold* and _^Hx for 'underline'.
#
# less and more will both understand this.
# Pipe through 'col -b' to remove them.
if {[regexp {^'(.*)'([^a-zA-Z0-9_]*)$} $word -> bareword dot]} {
regsub -all . $bareword "_\b&" word
append word $dot
} elseif {[regexp {^[*](.*)[*]([^a-zA-Z0-9_]*)$} $word -> bareword dot]} {
regsub -all . $bareword "&\b&" word
append word $dot
}
puts -nonewline $space$word
set space " "
}
if {$len} {
puts ""
}
# Use man-page conventions for highlighting 'quoted' and *quoted*
# single words.
# Use x^Hx for *bold* and _^Hx for 'underline'.
#
# less and more will both understand this.
# Pipe through 'col -b' to remove them.
if {[regexp {^'(.*)'(.*)} $word -> quoted after]} {
set quoted [string map {~ " "} $quoted]
regsub -all . $quoted "&\b&" quoted
set word $quoted$after
} elseif {[regexp {^[*](.*)[*](.*)} $word -> quoted after]} {
set quoted [string map {~ " "} $quoted]
regsub -all . $quoted "_\b&" quoted
set word $quoted$after
}
puts -nonewline $space$word
set space " "
}
if {[info exists partial]} {
# Missing end of quote
puts -nonewline $space$partial
}
if {$len} {
puts ""
}
}
proc title {text} {
underline [string trim $text] =
nl
underline [string trim $text] =
nl
}
proc p {text} {
wordwrap $text 80
nl
wordwrap $text 80
nl
}
proc codelines {lines} {
foreach line $lines {
puts " $line"
}
nl
foreach line $lines {
puts " $line"
}
nl
}
proc nl {} {
puts ""
puts ""
}
proc underline {text char} {
regexp "^(\[ \t\]*)(.*)" $text -> indent words
puts $text
puts $indent[string repeat $char [string length $words]]
regexp "^(\[ \t\]*)(.*)" $text -> indent words
puts $text
puts $indent[string repeat $char [string length $words]]
}
proc section {text} {
underline "[string trim $text]" -
nl
underline "[string trim $text]" -
nl
}
proc subsection {text} {
underline "$text" ~
nl
underline "$text" ~
nl
}
proc bullet {text} {
wordwrap $text 76 " * " " "
wordwrap $text 76 " * " " "
}
proc indent {text} {
wordwrap $text 76 " " " "
wordwrap $text 76 " " " "
}
proc defn {first args} {
if {$first ne ""} {
underline " $first" ~
}
foreach p $args {
if {$p ne ""} {
indent $p
}
}
if {$first ne ""} {
underline " $first" ~
}
foreach p $args {
if {$p ne ""} {
indent $p
}
}
}
}
# ----- @module util.tcl -----
set modsource(util.tcl) {
# Copyright (c) 2012 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module which contains miscellaneous utility functions
# @compare-versions version1 version2
#
# Versions are of the form 'a.b.c' (may be any number of numeric components)
#
# Compares the two versions and returns:
## -1 if v1 < v2
## 0 if v1 == v2
## 1 if v1 > v2
#
# If one version has fewer components than the other, 0 is substituted to the right. e.g.
## 0.2 < 0.3
## 0.2.5 > 0.2
## 1.1 == 1.1.0
#
proc compare-versions {v1 v2} {
foreach c1 [split $v1 .] c2 [split $v2 .] {
if {$c1 eq ""} {
set c1 0
}
if {$c2 eq ""} {
set c2 0
}
if {$c1 < $c2} {
return -1
}
if {$c1 > $c2} {
return 1
}
}
return 0
}
# @suffix suf list
#
# Takes a list and returns a new list with '$suf' appended
# to each element
#
## suffix .c {a b c} => {a.c b.c c.c}
#
proc suffix {suf list} {
set result {}
foreach p $list {
lappend result $p$suf
}
return $result
}
# @prefix pre list
#
# Takes a list and returns a new list with '$pre' prepended
# to each element
#
## prefix jim- {a.c b.c} => {jim-a.c jim-b.c}
#
proc prefix {pre list} {
set result {}
foreach p $list {
lappend result $pre$p
}
return $result
}
# @lpop list
#
# Removes the last entry from the given list and returns it.
proc lpop {listname} {
upvar $listname list
set val [lindex $list end]
set list [lrange $list 0 end-1]
return $val
}
}
# ----- module wiki-formatting -----
# ----- @module wiki-formatting.tcl -----
set modsource(wiki-formatting) {
set modsource(wiki-formatting.tcl) {
# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
# All rights reserved
# Module which provides text formatting
# wiki.tcl.tk format output
use formatting
|
︙ | | |
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
|
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
|
-
+
|
# Entry/Exit
#
if {$autosetup(debug)} {
main $argv
}
if {[catch {main $argv} msg opts] == 1} {
show-notices
autosetup-full-error [error-dump $msg $opts $::autosetup(debug)]
autosetup-full-error [error-dump $msg $opts $autosetup(debug)]
if {!$autosetup(debug)} {
puts stderr "Try: '[file tail $autosetup(exe)] --debug' for a full stack trace"
}
exit 1
}
|
Added autosetup/autosetup-config.guess.