forked from OpenDDS/OpenDDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·2990 lines (2698 loc) · 93.8 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
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
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
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
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
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
832
833
834
835
836
837
838
839
840
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
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/perl
# -*- CPerl -*-
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q'
if 0;
# configure script for OpenDDS
# Distributed under the OpenDDS License.
# See: http://www.opendds.org/license.html
use strict;
use warnings;
use Getopt::Long;
use Dumpvalue;
use File::Spec;
use File::Basename;
use File::Copy;
use File::Path;
use File::Temp ();
use FileHandle;
use Cwd;
use POSIX qw(strftime);
use B qw/perlstring/;
use Digest::MD5;
use FindBin;
use lib "$FindBin::RealBin/tools/scripts/modules";
use command_utils;
use ChangeDir;
use ini qw/read_ini_file/;
my $backup_timestamp = strftime "%Y-%m-%d-%H-%M-%S", localtime time;
# save args before Getopt modifies them
my @ARGS = @ARGV;
my @default_configh = (
'#define ACE_DISABLE_MKTEMP',
'#define ACE_DISABLE_READDIR_R',
'#define ACE_DISABLE_TEMPNAM',
'#define TAO_HAS_UIOP 0',
);
sub perlOS_to_host {
return 'win32' if $^O eq 'MSWin32';
return 'macos' if $^O eq 'darwin';
return $^O;
}
sub perlOS_to_java_platform {
return 'win32' if $^O eq 'MSWin32';
return $^O;
}
my $targetUsageIndent = "\t\t";
my %platforminfo =
('win32' => {
'compilers' => ['cl'],
'libpath' => 'PATH',
'cl_versions' => {13.1 => 'vc71', 14 => 'vc8', 15 => 'vc9',
16 => 'vc10', 17 => 'vc11', 18 => 'vc12',
19 => 'vc14', 19.1 => 'vs2017',
19.2 => 'vs2019', 19.3 => 'vs2022'},
'cl_archs' => {'x64' => 1, 'Win32' => 1, 'ARM64' => 0, 'ARM' => 0}, # 1 if supported
},
'macos' => {
'compilers' => ['clang++'],
'libpath' => 'DYLD_LIBRARY_PATH',
'aceconfig' => 'macosx',
'aceplatform' => 'macosx',
},
'macos-cross' => {
'compilers' => ['clang++'],
'libpath' => 'DYLD_LIBRARY_PATH',
'aceconfig' => 'macosx',
'aceplatform' => 'macosx',
'no_host' => 1,
'java_platform' => 'darwin',
'usage' => ['Use --target-arch or --target-compiler to ' .
'specify how the target', 'build should work'],
},
'linux' => {
'compilers' => ['g++', 'clang++', 'clang'],
'libpath' => 'LD_LIBRARY_PATH',
'aceplatform' => 'linux_$NONSTDCOMP', # $NONSTDCOMP = clang
},
'linux-cross' => {
'libpath' => 'LD_LIBRARY_PATH',
'aceplatform' => 'linux',
'aceconfig' => 'linux',
'no_host' => 1,
'java_platform' => 'linux',
'usage' => ['Use --target-compiler to specify the ' .
'cross-compiler binary',
],
},
'freebsd' => {
'compilers' => ['clang++'],
'libpath' => 'LD_LIBRARY_PATH',
},
'lynxos-178' => {
'libpath' => 'LD_LIBRARY_PATH',
'no_host' => 1,
'aceplatform' => 'lynxos',
'compiler_root_env' => 'ENV_PREFIX',
'usage' => ['Set up the cross compile using '.
'the script from LynxOS',
],
},
'vxworks' => {
'libpath' => 'LD_LIBRARY_PATH',
'no_host' => 1,
'usage' => ['Use the wrenv script before running configure',
'Specify the VSB with --macros=VSB_DIR=<dir>',
],
},
'android' => {
'libpath' => 'LD_LIBRARY_PATH',
'aceplatform' => 'android',
'aceconfig' => 'android',
'no_host' => 1,
'usage' => [
"Use --macros=ANDROID_ABI=<ARCH> to specify the",
"target architecture.",
"Use --macros=android_sdk=<SDK_PATH> and",
"--macros=android_target_api=<API_NUMBER> to specify",
"where to find android.jar.",
],
'needs_i2jrt_corba' => 1,
'java_platform' => 'android',
},
'ios' => {
'compilers' => ['clang++'],
'libpath' => 'DYLD_LIBRARY_PATH',
'no_host' => 1,
'aceconfig' => 'macosx-iOS',
'aceplatform' => 'macosx_iOS',
'usage' => [
"Use --macros=IPHONE_TARGET=SIMULATOR or",
"--macros=IPHONE_TARGET=HARDWARE",
"to specify the target architecture."
],
}
);
sub targetUsage {
my $status = shift;
print "Cross-compile targets: specify --target=TGT where TGT is one of:\n";
for my $k (sort keys %platforminfo) {
if ($platforminfo{$k}->{'no_host'}) {
print "\t$k\n";
if ($platforminfo{$k}->{'usage'}) {
for my $line (@{$platforminfo{$k}->{'usage'}}) {
print "${targetUsageIndent}$line\n";
}
}
}
}
exit $status;
}
## arg processing and usage
my $argPadding = 29;
my $argIndent = "\n " . (' ' x $argPadding);
# Array of array-refs, each inner array is an option group which
# has the format [Group Description, Opt1 Spec, Opt1 Description,
# Opt2 Spec, Opt2 Description, ...]
# <default>OPT is a custom token marking a string option that
# defaults to $opts{'OPT'} = '' and can be overridden by opts by passing
# --no-OPT or --OPT with a value.
# <hidden>OPT hides the option from --help
# <usage>OPT hides the option from GetOpt::Long
my @specs =
(
['Options controlling the configure script:',
'help|h|?', 'Show this help and exit',
'target-help', 'Show details of cross-compile target configs',
'verbose|v', 'Trace script execution',
'dry-run|n', 'Don\'t do anything',
'backup!', 'Make backup of build configuration files (yes)',
'<hidden>force-clone-submodules', 'Get submodules as if this wasn\'t a git repo',
],
['Build platform and compiler:',
'host=s', 'Host (auto detect: linux, win32, macosx)',
'compiler=s', 'Compiler (auto detect / guess by searching PATH)',
'std=s', 'C++ standard version (compiler default)',
'target=s', 'Cross-compile target (none): see --target-help',
'target-arch=s', 'Architecture for target (none): see --target-help',
'target-compiler=s', 'Compiler for target (if req\'d): see --target-help',
'host-tools=s', 'DDS_ROOT of host tools for cross compile (build)',
'host-ace=s', 'Define host ACE_ROOT (uses relative path from' .
$argIndent . 'target DDS_ROOT to target ACE_ROOT)',
'host-tools-only!', 'Just build the host tools (no)',
'prefix=s', 'Installation prefix (none)',
'install-origin-relative!', 'Install with RPATH relative to $ORIGIN (no)',
'workspace=s', 'Custom MPC workspace file to copy and use' .
$argIndent . '(Use a builtin one)',
],
['Build flags:',
'debug!', 'Debugging (yes)',
'optimize!', 'Optimization (no)',
'inline!', 'Inlining (yes)',
'static!', 'Static libraries (no)',
'ipv6!', 'IPv6 support (no)',
'sanitize=s@', 'Build with a sanitizer, can pass multiple times' .
$argIndent . 'or one list separated by commas, combining asan' .
$argIndent . "and tsan isn't recommended (no sanitizers)" .
$argIndent . ' asan: Address Sanitizer, gcc/clang only' .
$argIndent . ' tsan: Thread Sanitizer, gcc/clang only' .
$argIndent . ' ubsan: Undefined Behavior Sanitizer, clang only',
'compile-warnings=s', 'Enable additional compiler warnings' .
$argIndent . '(default compiler warnings)' .
$argIndent . ' WARNING: enable additional warnings' .
$argIndent . ' ERROR: enable additional warnings that are' .
$argIndent . ' treated as errors',
],
['Required dependencies for OpenDDS:',
'ace=s', 'ACE (use ACE_ROOT, ACE_wrappers, or download)',
'tao=s', 'TAO (use TAO_ROOT, ACE_ROOT/TAO, or download)',
'mpc=s', 'MPC (use MPC_ROOT, ACE_ROOT/MPC, or download)',
'doc-group|doc_group!', 'Use the DOC Group release of TAO 2.5.x (yes)',
'doc-group3|doc_group3!', 'Use the DOC Group release of TAO 3.x (no)',
'ace-github-latest!', 'Clone latest ACE/TAO/MPC from GitHub (no)',
'force-ace-tao', 'Force configuration of ACE/TAO (no)',
'no-disable-deprecated', 'Turn off disabling deprecated interfaces when' .
$argIndent . 'configuring ACE/TAO (no)',
],
['Advanced configuration:',
'configh=s@', 'Extra text for config.h',
'macros=s@', 'Extra text for platform_macros.GNU',
'features=s@', 'Extra text for default.features',
'mpcopts=s@', 'Extra command-line options for MPC' .
$argIndent . 'This option can be given multiple times' .
$argIndent . 'For example:' .
$argIndent . ' --mpcopts=-value_template --mpcopts=build_flags+="-Wall -Werror"' .
$argIndent . 'turns into the following arguments for MPC:' .
$argIndent . ' -value_template build_flags+="-Wall -Werror"',
'<usage>mpc:OPT=VALUE', 'Extra command-line options for MPC' .
$argIndent . 'For example:' .
$argIndent . ' --mpc:value_template build_flags+="-Wall -Werror"' .
$argIndent . 'turns into the following arguments for MPC:' .
$argIndent . ' -value_template build_flags+="-Wall -Werror"' .
$argIndent . 'This option can be given multiple times',
'boottime!', 'Use CLOCK_BOOTTIME for timers (no)',
],
['Optional dependencies for OpenDDS (disabled by default unless noted otherwise):',
'java:s', 'Java development kit (use JAVA_HOME)',
'jboss:s', 'JBoss application server (use JBOSS_HOME)',
'ant:s', 'Ant for JBoss (use ANT_HOME or system pkg)',
'wireshark:s',
'Wireshark dev headers or source not built with' .
$argIndent . 'CMake (use WIRESHARK_SRC or system pkg)' .
$argIndent . 'Implies --glib',
'wireshark-cmake|wireshark_cmake:s',
'Wireshark source built with CMake, requires' .
$argIndent . '--wireshark-build. Requires --wireshark-lib if' .
$argIndent . 'guessing fails (use WIRESHARK_SRC)' .
$argIndent . 'Implies --glib',
'wireshark-build|wireshark_build=s', 'Wireshark CMake Build Location',
'wireshark-lib|wireshark_lib=s',
'Optional Wireshark CMake libraries location' .
$argIndent . 'relative to wireshark-build (guesses)',
'glib:s', 'GLib for Wireshark (use GLIB_ROOT or system pkg)',
'<default>rapidjson:s',
'RapidJSON for Wireshark dissector and JSON' .
$argIndent . 'Sample Serialization (Enabled by default,' .
$argIndent . 'use git submodule, RAPIDJSON_ROOT, or system pkg)',
'qt:s', 'Qt5 (use QTDIR or system pkg)',
'qt-include:s', 'Qt include dir (use QT5_INCDIR, QTDIR/include,' .
$argIndent . 'or system package)',
'xerces3:s', 'Xerces-C++ 3 for QoS XML handling, DDS Security',
'openssl:s', 'OpenSSL for DDS Security',
'cmake:s', 'Path to CMake for compiling GoogleTest' .
$argIndent . '(Check PATH and normal locations)',
'gtest:s', 'Path to GoogleTest, required for tests' .
$argIndent . '(uses GTEST_ROOT)' .
$argIndent . 'If not built, will try to build using CMake.',
],
['Optional OpenDDS features:',
'built-in-topics!', 'Built-in Topics (yes)',
'content-subscription!', 'Content-Subscription Profile (yes)',
'content-filtered-topic!', 'ContentFilteredTopic (CS Profile) (yes)',
'multi-topic!', 'MultiTopic (CS Profile) (yes)',
'query-condition!', 'QueryCondition (CS Profile) (yes)',
'ownership-profile!', 'Ownership Profile (yes)',
'ownership-kind-exclusive!', 'Exclusive Ownership (Ownership Profile) (yes)',
'object-model-profile!', 'Object Model Profile (yes)',
'persistence-profile!', 'Persistence Profile (yes)',
'safety-profile:s', 'Safety Profile: base or extended (none)',
'tests!', 'Build tests, examples, and performance tests (no)' .
$argIndent . 'Requires --gtest if missing git submodule',
'security!', 'DDS Security plugin (no) Implies --openssl and' .
$argIndent . '--xerces3',
],
);
sub iterate {
my $callback = shift;
for my $group (@specs) {
for my $n (1 .. (scalar @{$group} / 2)) {
my $opt = ${$group}[$n * 2 - 1];
my $descr = ${$group}[$n * 2];
$opt =~ /(\<\w+\>)?([\w-]+)/;
my $optkey = (defined $1 ? $1 : "") . $2;
&$callback(${$group}[0], $opt, $descr, $optkey, @_);
}
}
}
sub usage {
my $status = shift;
my $current;
my $ver;
open VER, 'dds/Version.h' or die "ERROR: can't open dds/Version.h, stopped";
while (<VER>) {
$ver = $1 if /#define OPENDDS_VERSION "([^"]+)"/;
}
close VER;
print <<"EOT";
Welcome to OpenDDS version $ver
Options for this script are listed below, with the default behavior described
in parenthesis after the option description.
Boolean options can take the form "--opt" or "--no-opt", the more commonly
needed one (the one that changes the default behavior) is shown below.
Options that require arguments are shown as "--opt=VAL". Options with optional
arguments are shown as "--opt[=VAL]". Options that can be repeated with
cumulative effect are shown with a trailing "...". Some third-party
optional dependencies can be automatically located if they are installed in the
expected locations (see entries below marked with "system pkg"). In those
cases, specify the option as --opt without an = to enable the corresponding
feature in OpenDDS and use the default installation location.
EOT
iterate(sub {
my ($group, $opt, $descr, $optkey) = @_;
if (!defined $current || $group ne $current) {
$current = $group;
print "\n$group\n";
}
$optkey .= '=VAL' if $opt =~ /=s/;
$optkey .= '[=VAL]' if $opt =~ /:s/;
$optkey = "[no-]$optkey" if ($opt =~ /!$/ && $descr =~ / \(yes\)/);
if ($optkey =~ /^\<hidden\>/) {
return;
}
if ($opt =~ /^\<usage\>(.*)$/) {
$optkey = $1;
}
$optkey =~ s/^\<default\>(.*)$/\[no-\]$1/g;
$optkey .= '...' if $opt =~ /s\@$/;
my $pad = $argPadding - length $optkey;
print "--$optkey" . ' ' x (($pad > 0) ? $pad : 0) . " $descr\n";
}
);
exit $status;
}
my $defaulted = {};
sub parseArgs {
my @getopts = ();
my @default = ();
iterate(sub {
my ($group, $opt, $descr, $optkey) = @_;
if ($opt =~ /^\<usage\>/) {
return;
}
if ($opt =~ /^<default>(.*)$/) {
push @getopts, $1;
$optkey =~ /^<default>(.*)$/;
push @getopts, "no-$1";
push @default, $1;
}
else {
$opt =~ s/^\<hidden\>(.*)$/$1/;
push @getopts, $opt;
}
}
);
if (! -r 'rules.dds.GNU') {
print "ERROR: this script must be run from its own directory\n";
exit 1;
}
my $opts = {};
Getopt::Long::Configure('pass_through');
GetOptions($opts, @getopts) or usage(1);
usage(0) if $opts->{'help'};
targetUsage(0) if $opts->{'target-help'};
while (@ARGV != 0) {
my $arg = shift(@ARGV);
if ($arg =~ /^--mpc:([^=]*)(?:=(.*))?$/) {
my $key = $1;
my $value = $2;
if (defined($value)) {
push(@{$opts->{'mpcopts'}}, '-' . $key, $value);
}
elsif (@ARGV != 0) {
$value = shift(@ARGV);
push(@{$opts->{'mpcopts'}}, '-' . $key, $value);
} else {
print STDERR "ERROR: $arg requires a value\n";
usage(1);
}
} else {
print STDERR "ERROR: unknown argument $arg\n";
usage(1);
}
}
if ($opts->{'verbose'}) {
print "Options:\n";
new Dumpvalue()->dumpValue($opts);
}
for my $opt (@default) {
if ($opt eq 'rapidjson' && defined $opts->{'safety-profile'}) {
print("Although it's a default, rapidjson is not compatible with Safety ".
"Profile so it will not be enabled\n") if $opts->{'verbose'};
next;
}
if (!exists $opts->{$opt} && !exists $opts->{"no-$opt"}) {
$opts->{$opt} = '';
$defaulted->{$opt} = 1;
print("By default, --$opt is added to the options\n") if $opts->{'verbose'};
}
}
return $opts;
}
my $cross_compile = 0;
my %opts = %{parseArgs()};
my $debug = exists $opts{'debug'} ? $opts{'debug'} : 1;
my $backup = exists $opts{'backup'} ? $opts{'backup'} : 1;
my $force_ace_tao = exists $opts{'force-ace-tao'} ? $opts{'force-ace-tao'} : 0;
my $no_disable_deprecated = exists $opts{'no-disable-deprecated'} ? $opts{'no-disable-deprecated'} : 0;
my $cxx_std;
if (exists($opts{'std'})) {
$cxx_std = $opts{'std'};
# Accept any of --std=17, --std=stdcpp17, --std=c++17, etc.
$cxx_std =~ s/^(std)?(cpp|c\+\+)//;
}
my @mpcopts;
push(@mpcopts, @{$opts{'mpcopts'}}) if exists($opts{'mpcopts'});
my @features;
push(@features, @{$opts{'features'}}) if exists($opts{'features'});
$opts{'host'} = perlOS_to_host() unless $opts{'host'};
my $is_windows = $opts{'host'} eq 'win32';
my ($slash, $exeext) = $is_windows ? ('\\', '.exe') : ('/', '');
my %specific =
($is_windows ?
('ext' => 'cmd', 'pathsep' => ';', 'refpre' => '%',
'refpost' => '%', 'comment' => '::') :
('ext' => 'sh', 'pathsep' => ':', 'refpre' => '${',
'refpost' => '}', 'comment' => '#')
);
sub might_be_executable {
my $path = shift;
return -x $path && -f $path; # On Windows -x can return true for directories
}
sub which {
my $file = shift;
for my $p (File::Spec->path()) {
next if $p eq '.';
my $path = "$p/$file";
if (might_be_executable($path)) {
return $path;
}
elsif ($exeext ne '') {
$path .= $exeext;
if (might_be_executable($path)) {
return $path;
}
}
}
return undef;
}
sub addCurLibPathRef {
my $buildEnvRef = shift;
my $platform = $opts{$buildEnvRef->{'build'}};
my $libpathname = $platforminfo{$platform}->{'libpath'};
my $curLibPathRef = $specific{'refpre'} . $libpathname . $specific{'refpost'};
$buildEnvRef->{$libpathname} = $curLibPathRef;
}
sub run_command {
my $command = shift;
return command_utils::run_command(
$command,
script_name => 'configure',
dry_run => $opts{'dry-run'},
verbose => $opts{'verbose'},
@_,
);
}
sub git_clone {
my $dest = shift;
my $url = shift;
my %args = @_;
my $branch = $args{branch};
my $commit = $args{commit};
print "Cloning git repo $url ", $branch // $commit, "\n";
my $failed;
if (defined($commit)) {
# Git can't directly clone a specific commit. Could use clone and checkout,
# but can't do a single shallow clone that way.
my $chdir = ChangeDir->new($dest);
$failed = run_command(['git', 'init', '--quiet']) ||
run_command(['git', 'remote', 'add', 'origin', $url]) ||
run_command(['git', 'fetch', '--quiet', '--depth=1', 'origin', $commit]) ||
run_command(['git', 'checkout', '--quiet', 'FETCH_HEAD']);
}
else {
my @cmd = ('git', 'clone', '--quiet', '--depth=1', $url, $dest);
push(@cmd, '--branch', $branch) if (defined($branch));
$failed = run_command(\@cmd);
}
if (!$failed) {
run_command(['git', '--no-pager', 'log', '-1', '--oneline'], chdir => $dest);
}
return $failed;
}
sub git_submodule_prop {
my $path = shift;
my $prop_name = shift;
my $full_prop_name = "submodule.$path.$prop_name";
open(my $fd, "-|", "git config --file .gitmodules --get $full_prop_name")
or die("git_submodule_prop open failed: $!\nStopped");
my $prop_value = <$fd>;
close($fd);
chomp($prop_value) if (defined($prop_value));
if (!$prop_value) {
die("Couldn't get $full_prop_name from .gitmodules\nStopped");
}
return $prop_value;
}
sub git_ensure_submodule {
my $path = shift;
if (!which('git')) {
print STDERR "Can't ensure we have $path becuase we can't find the git command\n";
return 0;
}
my $commit_prop = 'openddsConfigureCommit';
my $commit = git_submodule_prop($path, $commit_prop);
if (!$opts{'force-clone-submodules'} &&
!run_command(['git', 'submodule', 'update', '--init', $path])) {
# This doesn't affect us in this run, but since we can get the actual
# submodule commit, make sure it matches the commit from .gitmodules for
# the case when the source tree is not a git repo.
open(my $fd, "-|", "git ls-tree HEAD $path")
or die("git_ensure_submodule open failed: $!\nStopped");
my $real_commit = <$fd>;
close($fd);
chomp($real_commit);
$real_commit =~ s/^\S+ \S+ ([0-9a-f]+).*$/$1/;
if ($real_commit ne $commit) {
print STDERR "WARNING: for submodule $path $commit_prop = $commit ",
"from .gitmodules doesn't match actual commit $real_commit\n";
}
return 1;
}
return !git_clone($path, git_submodule_prop($path, 'url'), commit => $commit);
}
sub md5sum {
my $path = shift();
my $expected_hash = shift();
my $md5 = Digest::MD5->new;
open(my $fh, $path) or die("Couldn't open \"$path\": $!");
binmode $fh;
$md5->addfile($fh);
my $hash = $md5->hexdigest();
my $failed = $expected_hash ne $hash;
if ($failed) {
print(
"MD5 hash mismatch for $path\n",
" expected: $expected_hash\n",
" got: $hash\n");
}
return $failed;
}
my $curpathRef = $specific{'refpre'} . 'PATH' . $specific{'refpost'};
my %hostEnv = ('build' => 'host', 'PATH' => $curpathRef);
my %targetEnv = ('build' => 'target', 'PATH' => $curpathRef);
my $would_download; # can dry-run assume directories that don't exist yet?
sub locate_mpc {
my $ace_src = shift;
if (defined $opts{'mpc'}) {
setEnv('MPC_ROOT', $opts{'mpc'});
}
elsif (!$ENV{'MPC_ROOT'} && (-r $ace_src . '/MPC/MPC.ico'
|| ($opts{'dry-run'} && $would_download))) {
setEnv('MPC_ROOT', $ace_src . $slash . 'MPC');
}
elsif (!$ENV{'MPC_ROOT'}) {
die "ERROR: Can't find MPC. Please set MPC_ROOT or make sure MPC exists".
"\n in the 'MPC' directory under ACE_ROOT ($ace_src), stopped";
}
else {
$targetEnv{'MPC_ROOT'} = $ENV{'MPC_ROOT'};
}
$hostEnv{'MPC_ROOT'} = $targetEnv{'MPC_ROOT'};
}
if (!exists $platforminfo{$opts{'host'}} ||
$platforminfo{$opts{'host'}}->{'no_host'}) {
die "ERROR: unknown host $opts{'host'}, stopped";
}
print "host system is: $opts{'host'}\n" if $opts{'verbose'};
$opts{'target'} = $opts{'host'} unless $opts{'target'};
if (!exists $platforminfo{$opts{'target'}}) {
die "ERROR: unknown target $opts{'target'}, stopped";
}
if (exists($opts{'workspace'})) {
if (!-r $opts{'workspace'}) {
die "ERROR: workspace file $opts{'workspace'} isn't a readable file, stopped";
}
$opts{'workspace'} = Cwd::realpath($opts{'workspace'});
}
if (exists($opts{'prefix'}) && !File::Spec->file_name_is_absolute($opts{'prefix'})) {
die("ERROR: --prefix argument $opts{'prefix'} is not an absolute path, stopped");
}
# Set initial libpath
addCurLibPathRef(\%hostEnv);
addCurLibPathRef(\%targetEnv);
if (defined $opts{'safety-profile'} && $opts{'safety-profile'} eq '') {
print "Defaulting safety profile to extended\n";
$opts{'safety-profile'} = 'extended';
}
my $build_host_tools = 0;
if ($opts{'host'} ne $opts{'target'} || $opts{'safety-profile'}) {
$build_host_tools = !$opts{'host-tools'};
print "Cross-compile build " .
($build_host_tools ? 'including' : 'excluding') . " host tools\n"
if $opts{'verbose'};
$cross_compile = 1;
}
my $has_host_compiler = $build_host_tools || !$cross_compile;
if ($platforminfo{$opts{'target'}}->{'compiler_root_env'}) {
# This target puts its cross-compiler in the PATH before the host compiler,
# we will need to override (not append to) PATH for the host build.
my $root_env = $platforminfo{$opts{'target'}}->{'compiler_root_env'};
my $root_dir = $ENV{$root_env};
my @oldpath = split /$specific{'pathsep'}/, $ENV{'PATH'};
my $newpath = join($specific{'pathsep'}, grep {!/^$root_dir/} @oldpath);
$hostEnv{'PATH'} =~
s/\Q$specific{'refpre'}\EPATH\Q$specific{'refpost'}\E/$newpath/;
}
if (!exists $platforminfo{$opts{'target'}}->{'needs_i2jrt_corba'}) {
$platforminfo{$opts{'target'}}->{'needs_i2jrt_corba'} = 0;
}
## compiler
if ($has_host_compiler) {
if ($opts{'compiler'}) {
my $standard = 0;
for my $stdcomp (@{$platforminfo{$opts{'host'}}->{'compilers'}}) {
$standard = 1 if $opts{'compiler'} eq $stdcomp;
}
$opts{'nonstdcompiler'} = 1 unless $standard;
}
else {
print "Auto-detecting compiler\n" if $opts{'verbose'};
for my $stdcomp (@{$platforminfo{$opts{'host'}}->{'compilers'}}) {
my $path = which($stdcomp);
if ($path) {
print "Found $stdcomp at: $path\n" if $opts{'verbose'};
$opts{'compiler'} = $stdcomp;
last;
}
}
if (!defined $opts{'compiler'}) {
die "ERROR: Can't find a compiler, set PATH or run this script with the ".
"--compiler option.\n" . ($is_windows ? " For Microsoft Visual C++, ".
"run this script from the Visual Studio ".
"Command Prompt.\n" : '') . "Stopped";
}
}
print "compiler is: $opts{'compiler'}\n" if $opts{'verbose'};
if ($opts{'compiler'} =~ /cl(\.exe)?$/i) {
my $savepath = $ENV{'PATH'};
my $clpath = which($opts{'compiler'});
if ($clpath) {
$clpath =~ s/vc\\bin(\\(x86_)?amd64)?/common7\\ide/i;
$ENV{'PATH'} .= ";$clpath";
}
# Have CL Tell Us Its Target Architecture and Version
my ($tmp_fd, $tmp_filename) = File::Temp::tempfile();
my $cl_check = << "EOF";
#ifdef _M_X64
# define ARCH x64
#elif defined(_M_IX86)
# define ARCH Win32
#elif defined(_M_ARM64)
# define ARCH ARM64
#elif defined(_M_ARM)
# define ARCH ARM
#else
# define ARCH Unknown
#endif
CL is _MSC_VER ARCH
EOF
print $tmp_fd $cl_check;
close($tmp_fd);
my $cl_command = "\"$opts{'compiler'}\" /EP $tmp_filename 2>&1";
print "Running $cl_command\n" if $opts{'verbose'};
open(my $cl_out_fd, "-|", $cl_command)
or die "ERROR: Could not detect Visual C++ version, try running this ".
"script from the Visual Studio Command Prompt.\nStopped";
my $ver = 0;
my $arch = '';
while (my $line = <$cl_out_fd>) {
chomp ($line);
print "CL says: $line\n" if $opts{'verbose'} && $line !~ /^\s*$/;
# Convert _MSC_VER to the form \d+\.\d
if ($line =~ /^CL is (\d+)\d (\w+)$/) {
$ver = int($1) / 10;
$arch = $2;
last;
}
}
close($cl_out_fd);
unlink($tmp_filename)
or warn "Unable to delete temporary file $tmp_filename: $!";
print "CL Version is $ver, architecture is $arch\n" if $opts{'verbose'};
if (!$ver && !$arch) {
die "cl version probe failed, invalid output from cl\nStopped";
}
if ($arch eq 'Unknown') {
die "cl version probe failed, no known architecture macro was defined\nStopped";
}
if (!exists $platforminfo{'win32'}->{'cl_archs'}->{$arch}) {
die "cl version probe failed, invalid architecture \"$arch\"\nStopped";
}
if (!$platforminfo{'win32'}->{'cl_archs'}->{$arch}) {
die "ERROR: Windows for $arch isn't supported\nStopped";
}
if (!exists $platforminfo{'win32'}->{'cl_versions'}->{$ver}) {
die "ERROR: Unknown or unsupported Visual C++ compiler version: $ver\n"
. "Stopped";
}
$opts{'compiler_version'} = $platforminfo{'win32'}->{'cl_versions'}->{$ver};
$opts{'compiler_target_architecture'} = $arch;
if ($ver >= 19) {
push(@features, 'no_cxx11=0');
print "Visual C++ has >= C++11 support\n" if $opts{'verbose'};
}
if ($opts{'std'}) {
my $std = "stdcpp$cxx_std";
push(@mpcopts, '-value_template', "LanguageStandard=$std");
print "Setting Visual C++ LanguageStandard to $std\n" if $opts{'verbose'};
if ($opts{'std'} eq 'latest' || $cxx_std >= 17) {
push(@features, 'no_cxx17=0');
print "Visual C++ has >= C++17 support\n" if $opts{'verbose'};
}
}
$ENV{'PATH'} = $savepath;
print "Detected Visual C++ version: $opts{'compiler_version'}\n"
if $opts{'verbose'};
}
elsif ($opts{'compiler'} =~ /g\+\+|clang/) {
my $version_string = `$opts{'compiler'} --version`;
print "Compiler version: $version_string\n" if $opts{'verbose'};
$opts{'is apple clang'} = $version_string =~ /^Apple/;
if ($opts{'std'}) {
push(@{$opts{'macros'}}, 'CCFLAGS += -std=' . $opts{'std'});
print "Added platform_macros for -std=$opts{std}\n" if $opts{'verbose'};
}
elsif ($opts{'compiler'} !~ /clang/) {
$version_string =~ /\(.*\) (\d+)\.\d+/;
if ($1 >= 11) {
$opts{'std'} = 'gnu++17';
print "Detected GCC >= 11, default -std=gnu++17\n" if $opts{'verbose'};
}
elsif ($1 >= 6) {
$opts{'std'} = 'gnu++14';
print "Detected GCC >= 6, default -std=gnu++14\n" if $opts{'verbose'};
}
}
elsif ($opts{'compiler'} =~ /clang/ && $version_string !~ /^Apple / &&
$version_string =~ /(\d+)\.(\d+)\.(\d+)/) {
# Apple's version of Clang doesn't default to c++11 or higher, users
# can pass --std= to change the C++ standard version used.
if ($1 >= 16) {
$opts{'std'} = 'gnu++17';
print "Detected Clang >= 16, default -std=gnu++17\n" if $opts{'verbose'};
}
elsif ($1 >= 6) {
# Non-Apple versions of Clang, if version 6 or newer, default to C++14 like GCC
$opts{'std'} = 'gnu++14';
print "Detected Clang >= 6, default -std=gnu++14\n" if $opts{'verbose'};
}
}
if ($opts{'std'} && $opts{'std'} =~ /(0x|11|1y|14|1z|17|2a|20|2b|23)$/) {
push(@features, 'no_cxx11=0');
print "Compiler has >= C++11 support\n" if $opts{'verbose'};
}
}
}
my $compile_warnings = $opts{'compile-warnings'} // '';
if ($compile_warnings eq 'WARNING' or $compile_warnings eq 'ERROR') {
my ($section_names, $sections) = read_ini_file("$FindBin::RealBin/build.ini");
my %compiler_map = ( 'g++' => 'GNU', 'clang' => 'Clang', 'cl' => 'MSVC', 'cl.exe' => 'MSVC');
my $section = $compiler_map{$opts{'compiler'}};
if ($opts{'is apple clang'}) {
$section = 'AppleClang';
}
my $warning_flags = $sections->{$section}{'warning'};
my $error_flags = $sections->{$section}{'error'};
push(@mpcopts, '-value_template', "compile_flags+=${warning_flags}");
if ($compile_warnings eq 'ERROR') {
push(@mpcopts, '-value_template', "compile_flags+=${error_flags}");
}
}
sub looksRelative {
my $val = shift;
return substr($val, 0, 1) ne $slash && ($slash eq '/' || $val !~ /^[a-z]:/i);
}
sub normalizePath {
my $val = shift;
return Cwd::abs_path($val) if $val && -d $val && $val =~ /../;
return $val;
}
sub setSomeEnv {
my($hashref, $name, $val, $notdir) = @_;
$val = Cwd::abs_path($val) if -d $val;
if ($opts{'dry-run'} && !$notdir && looksRelative($val)) {
$val = getcwd . $slash . $val;
}
$val =~ s!/!\\!g if $is_windows;
$hashref->{$name} = $val;
}
sub setEnv {
setSomeEnv(\%targetEnv, @_);
}
sub setHostEnv {
setSomeEnv(\%hostEnv, @_);
}
## ace
my $ace_src;
if ($opts{'ace'}) {
if ($opts{'ace'} ne 'download') {
if (!-r $opts{'ace'} . '/ace/ACE.h') {
die "ERROR: Can't find ACE at $opts{'ace'}.\nStopped";
}
$ace_src = $opts{'ace'};
}
}
elsif ($ENV{'ACE_ROOT'}) {
if (!-r $ENV{'ACE_ROOT'} . '/ace/ACE.h') {
die "ERROR: Can't find ACE at $ENV{'ACE_ROOT'}.\nStopped";
}
$ace_src = $ENV{'ACE_ROOT'};
}
elsif (-r '../ACE_wrappers/ace/ACE.h') {
die "ERROR: Older versions of this script would default to using ACE at " .
"../ACE_wrappers, but this version doesn't. Use the --ace command line " .
"option to override this error. Use --ace=download to have this script " .
"download an ACE+TAO package and expand it to ACE_wrappers.\nStopped";
}
elsif (-r 'ACE_wrappers/ace/ACE.h') {
$ace_src = 'ACE_wrappers';
}
elsif (-r 'ATCD/ACE/ace/ACE.h') {
$ace_src = 'ATCD/ACE';
}
elsif (-r 'ACE_TAO/ACE/ace/ACE.h') {
$ace_src = 'ACE_TAO/ACE';
}
$ace_src = normalizePath($ace_src);
## tao
my $tao_src;
if ($opts{'tao'}) {
if (!-r $opts{'tao'} . '/tao/ORB.h') {
die "ERROR: Can't find TAO at $opts{'tao'}.\nStopped";
}
$tao_src = $opts{'tao'};
}
elsif ($ENV{'TAO_ROOT'}) {
if (!-r $ENV{'TAO_ROOT'} . '/tao/ORB.h') {
die "ERROR: Can't find TAO at $ENV{'TAO_ROOT'}.\nStopped";
}
$tao_src = $ENV{'TAO_ROOT'};
}
elsif (defined $ace_src && -r $ace_src . '/TAO/tao/ORB.h') {
$tao_src = $ace_src . $slash . 'TAO';
}
elsif (defined $ace_src && -r $ace_src . '/../TAO/tao/ORB.h') {
$tao_src = (File::Spec->splitpath($ace_src))[1] .'TAO';
}
$tao_src = normalizePath($tao_src);
if ($opts{'safety-profile'}) {
# convert to lower case
$opts{'safety-profile'} = lc($opts{'safety-profile'});
}
## Download ACE+TAO
if (!$ace_src || !$tao_src) {
if ($opts{'ace-github-latest'}) {
die "ERROR: Git not found in path (required to clone ACE/TAO/MPC)"
if ! which('git');
my $urlbase = 'https://github.com/DOCGroup';
my $branch = 'ace6tao2';
if ($opts{'doc-group3'}) {
$branch = 'master';
}
my $err = git_clone('ACE_TAO', "$urlbase/ACE_TAO", branch => $branch);
die "ERROR: Failed to clone ACE/TAO from GitHub\nStopped"
if $err ||
! -r 'ACE_TAO/ACE/ace/ACE.h' ||
! -r 'ACE_TAO/TAO/tao/ORB.h';
$err = git_clone('ACE_TAO/ACE/MPC', "$urlbase/MPC", branch => 'master');
die "ERROR: Failed to clone MPC (into ACE_TAO/ACE/MPC) from GitHub\nStopped"
if $err ||
! -r 'ACE_TAO/ACE/MPC/mwc.pl';
$ace_src = normalizePath('ACE_TAO/ACE');
$tao_src = normalizePath('ACE_TAO/TAO');
}
else {
# Get ACE/TAO version info
my ($section_names, $sections) = read_ini_file("$FindBin::RealBin/acetao.ini");
my $ace_tao_version = $opts{'doc-group3'} ? $sections->{ace7tao3} : $sections->{ace6tao2};
if ($opts{verbose}) {
print("ACE/TAO Version Info:");
new Dumpvalue()->dumpValue($ace_tao_version);
}
my $ext = $is_windows ? 'zip' : 'tar.gz';
my $file = $ace_tao_version->{"$ext-filename"};
my $url = $ace_tao_version->{"$ext-url"};
my $md5_hash = $ace_tao_version->{"$ext-md5"};
# Check for an existing file
if (-r $file) {
if (md5sum($file, $md5_hash)) {
if ($opts{'dry-run'}) {
print("Would remove existing $file and attempt to download\n");