summaryrefslogtreecommitdiff
path: root/set_soenv.in
blob: 53b388f687720f3db82db4245cb391837d1d7846 (plain)
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
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
1047
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
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
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
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
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
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
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
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
1434
1435
1436
1437
1438
1439
1440
1441
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
#!@PERL@ -w  # -*- Mode: perl; tab-width: 4; indent-tabs-mode: nil; -*-
#
# Program:     set_soenv.in
# Author:      Willem van Dorp, Ross Nicholson, Oisin Boydell - Sun Microsystems, Ireland.
#
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
# Description:
# set_soenv generates a file that contains all necessary
# environment variables for the build proces of OpenOffice
# on Linux, NetBSD, Solaris, Windows, Mac OS X and iOS.
#
# Program steps.
#
# I.    Checking the command-line arguments.
# IIa.  Declaring variables for the system commands, etc.
# IIb.  Declaring the environment variables.
# III.  Initialising the variables for the system commands, etc.
# IV.   Print out some important messages etc.
# V.    Initialising the environment variables.
# VI.   Open the output file.
# VII.  Writing the data to the output file.
# VIII. Closing output file.
#
#---------------------------------------------------------------------------
#
use strict;                        # pragma
use File::Basename;


#
#--------------------------------------------------------
# IIa. Declaring variables for the system commands, etc.
#--------------------------------------------------------
#
my ( $outfile, $newline, $comment,
     $ds, $ps,
     $wps, $cur_dir, $par_dir, $I, $L, $tmp, $MINGW,
     $platform,
     $empty,
     $warnfile, $Warning, $result, $unsetvars, $exportvars);
#
#-------------------------------------------------
# IIb. Declaring environment values (constants).
#-------------------------------------------------
#
# Platform independent constant values.
my ( $SOLAR_JAVA,
     $CC, $CXX);
#
# Platform dependent constant values.
my ( $ARCH,
      $OSVERSION, $OUTPATH, $INPATH,
      $DYNAMIC_CRT, $use_shl_versions );
#
#-------------------------------------------
# IIc. Declaring the environment variables.
#-------------------------------------------
#
# Help variables.
my ( $USR, $ETC, $BIN, $LIB, $LIB64, $INC, $INCLUDE, $DEV, $OPT, $LOCAL, $SOLENV, $SOLVER, $CONFIG, $DEFIMGS,
     $USR_BIN, $USR_LIB, $USR_LOCAL, $USR_CCS, $JAVA_BIN, $JAVA_LIB, $JAVA_INCLUDE,
     $SOLARENVINC, $USR_DT, $USR_OPENWIN, $XLIB, $XINC,
     $CYGWIN_PATH, $language, @languages, $ASM_PATH, $PERL_PATH, $CL_X64 );

# Environment variables.
my ( $oldPATH, $SRC_ROOT, $JAVA_HOME, $JDK, $JAVAFLAGS, $OOO_SHELL,
     $L10N_MODULE, $WITH_POOR_HELP_LOCALIZATIONS,
     $UPD, $WORK_STAMP, $gb_REPOS, $BUILD_TYPE,
     $SOLARSRC, $SOLARVER, $SOLARVERSION, $WORKDIR, $OUTDIR, $SOLARENV, $SOLARDEFIMG,
     $DMAKEROOT, $CLASSPATH, $XCLASSPATH, $COMPATH,
     $MSPDB_PATH, $MIDL_PATH, $CSC_PATH, $SHOWINCLUDES_PREFIX,
     $PATH, $SOLAREXTRAINC, $SOLAREXTRALIB, $SOLARLIB,
     $SOLARINC, $FRAMEWORKSHOME, $COMEX, $PERL,
     $COMP_ENV, $ILIB, $JAVAHOME, $WINDOWS_SDK_HOME, $DIRECTXSDK_LIB, $DOTNET_FRAMEWORK_HOME,
     $USE_DIRECTX5, $ATL_LIB, $ATL_INCLUDE, $MFC_LIB, $MFC_INCLUDE, $TMPDIR,
     $COMMON_BUILD_TOOLS, $WIN_GREP, $WIN_FIND, $WIN_LS,
     $WIN_GNUCOPY, $WIN_TOUCH,
     $PROEXT, $TARFILE_LOCATION, $GNUMAKE,
     $PYTHON, $SYSTEM_PYTHON, $SYSTEM_MOZILLA, $EPM_FLAGS,
     $MACOSX_SDK_PATH,
     $SYSBASE);
#
#-------------------------------------------
# IId. Declaring the aliases.
#-------------------------------------------
#
my ( $dmake, $build, $mkout, $deliver, $zipdep );
#

$INPATH="@INPATH@";
$OUTPATH="@OUTPATH@";

#-------------------------------------------------------------
# IIIa. Initialising constants.
#-------------------------------------------------------------
#
# $platform is needed for PathFormat()
#
$platform       = '@host@';

$UPD            = '@UPD@';          # the project's UPD
$newline        = "\n";             # Perl newline character
$ds             = "/";              # directory separator
$ps             = ":";              # path separator
$wps            = ":";              # path separator, will be set to ';' for windows later.
$cur_dir        = ".";              # current directory
$par_dir        = "..";             # parrent directory
$I              = " -I";            # include search path
$L              = " -L";            # library search path
$empty          = "";               # used as argument
$warnfile       = "warn";           # logfile configure warnings.
$Warning        = "";               # container for warning messages
$SYSTEM_PYTHON	= '@SYSTEM_PYTHON@';
if ($SYSTEM_PYTHON eq "NO") {
    $PYTHON              = "python";
}
$SYSTEM_MOZILLA = '@SYSTEM_MOZILLA@';
$JDK 		= '@JDK@';
$JAVAFLAGS 		= '@JAVAFLAGS@';
$MINGW          = '@WITH_MINGW@';    # use MinGW for Windows build
$CC             = '@CC@';            # C compiler
$CXX            = '@CXX@';           # C++ compiler
$PROEXT         = "@PROEXT@";
$EPM_FLAGS	= "";
$CL_X64 = '@CL_X64@';
$GNUMAKE        = "@GNUMAKE@";

# JAVA_HOME as argument from autoconf.
$JAVA_HOME = PathFormat('@JAVA_HOME@') ;

if ( $platform =~ m/cygwin/ ) {
   $JAVA_HOME =~ s/[\s\/]+$//;	# remove trailing \n or \/ if there is any.
}
#
#--------------------------------------------------------------------
# IV. Initialise the warning container and print a note to the user.
#--------------------------------------------------------------------
#
# Add the configure (pre-requisite) warnings to the warning container
# , $Warning.
AddWarning( "configure", "" );
#
print ("Setting up the environment for building LibreOffice $newline");
#
#--------------------------------------------------
# V. Setting the environment variables/values.
#--------------------------------------------------
#

#
# B. Gathering information from the system.
#
# 1. Path
$oldPATH = $ENV{"PATH"};
chomp( $oldPATH );                  # cut off new line
#
# C. Setting the constant values.
#
# Setting platform independent constant values.
# NB: Language options now set at 'ToFile' stage.
$SOLAR_JAVA           = "@SOLAR_JAVA@";
$comment              = "#";           # UNIX script comment character
$TARFILE_LOCATION = "@TARFILE_LOCATION@"; # where to find tarballs with external sources

# Setting platform dependent constant values.
if ( $platform =~ m/solaris/ )
{
    $COMPATH        = '@COMPATH@';
}
elsif ( $platform =~ m/netbsd/ )
{
    $COMPATH        = '@COMPATH@';
}
elsif ( $platform =~ m/kfreebsd/ )
{
# General GNU/kFreeBSD settings:
    $COMPATH        = '@COMPATH@';

}
elsif ( $platform =~ m/freebsd/ )
{
    $COMPATH        = '@COMPATH@';
    $OSVERSION      = '@OSVERSION@';
}
elsif ( $platform =~ m/openbsd/ )
{
    $COMPATH        = '@COMPATH@';
    $OSVERSION      = '@OSVERSION@';
}
elsif ( $platform =~ m/linux/ )
{
# General Linux settings:
    $COMPATH        = '@COMPATH@';

#Set platform specific values:
    if ($platform =~ m/^i[3456]86/)
    {
    }
    elsif ($platform =~ m/^x86_64/)
    {
    }
    elsif ($platform =~ m/^ia64/)
    {
    }
    elsif ($platform =~ m/^sparc/)
    {
    }
    elsif ($platform =~ m/^powerpc/)
    {
    }
    elsif ($platform =~ m/^s390/)
    {
    }
    elsif ($platform =~ m/^m68k/)
    {
    }
    elsif ($platform =~ m/^hppa/)
    {
        $EPM_FLAGS      = "-a hppa";
    }
    elsif ($platform =~ m/^alpha/)
    {
    }
    elsif ($platform =~ m/^arm.*?l-/)
    {
        $EPM_FLAGS      = "-a arm";
    }
    elsif ($platform =~ m/^arm.*-androideabi/)
    {
        $EPM_FLAGS      = "-a arm";
    }
    elsif ($platform =~ m/^mips/)
    {
        print "Setting Linux MIPS specific values... ";

        if ('@SIZEOF_LONG@' eq '8')
        {
            if ('@WORDS_BIGENDIAN@' ne 'yes')
            {
                $EPM_FLAGS = "-a mips64el";
            }
        }
        else
        {
            if ('@WORDS_BIGENDIAN@' ne 'yes')
            {
                $EPM_FLAGS = "-a mipsel";
            }
        }
    }
}
elsif ( $platform =~ m/cygwin|mingw32/ )
{
    $MSPDB_PATH     = PathFormat('@MSPDB_PATH@');
    $MIDL_PATH      = PathFormat('@MIDL_PATH@');
    $CSC_PATH       = PathFormat('@CSC_PATH@');
    $SHOWINCLUDES_PREFIX = '@SHOWINCLUDES_PREFIX@';
    $WINDOWS_SDK_HOME      = PathFormat('@WINDOWS_SDK_HOME@');
    $DIRECTXSDK_LIB = PathFormat('@DIRECTXSDK_LIB@');
    $USE_DIRECTX5   = "";
    $DOTNET_FRAMEWORK_HOME = PathFormat('@DOTNET_FRAMEWORK_HOME@');
    $DYNAMIC_CRT    = "TRUE";
    $use_shl_versions = "TRUE";
    $wps = ';' if '@build_os@' eq 'cygwin'; # Windows style path seperator
    if ( $MINGW eq "yes" )
    {
        print "Setting Windows (MinGW cross-compilation) specific values... ";

        die 'For building natively on Windows we support only MSVC' if ('@build_os@' eq 'cygwin');

        $COMPATH        = PathFormat('@COMPATH@/bin');
        $COMPATH        =~ s/\/bin$//i;
    }
    else # The MSVC section starts here
    {
        print "Setting Windows (MSVC) specific values... ";
        $COMPATH        = PathFormat('@COMPATH@');
        $COMEX          = '@COMEX@';
        if ( "@DISABLE_ACTIVEX@" )
        {
            $ATL_LIB     = $WINDOWS_SDK_HOME.$ds."lib"; # Doesn't exist for VSE
            $ATL_INCLUDE = $WINDOWS_SDK_HOME.$ds."include".$ds."atl";
            $MFC_LIB     = $WINDOWS_SDK_HOME.$ds."lib"; # Doesn't exist for VSE
            $MFC_INCLUDE = $WINDOWS_SDK_HOME.$ds."include".$ds."mfc";
        }
        else
        {
            $ATL_LIB     = $COMPATH.$ds."atlmfc".$ds."lib";
            $ATL_INCLUDE = $COMPATH.$ds."atlmfc".$ds."include";
            $MFC_LIB     = $COMPATH.$ds."atlmfc".$ds."lib";
            $MFC_INCLUDE = $WINDOWS_SDK_HOME.$ds."include".$ds."mfc";
        }
        if ($CL_X64)
        {
            $ATL_LIB     .= $ds."amd64";
            $MFC_LIB     .= $ds."amd64";
        }
    }
}
elsif ( $platform =~ m/darwin/ )
{
    $COMPATH        = '@COMPATH@';
    if ($platform =~ m/^arm/)
    {
        print "Setting values for iOS... ";
    }
    elsif ($platform =~ m/^powerpc/)
    {
        print "Setting values for Mac OS X/Darwin on PowerPC... ";
        $MACOSX_SDK_PATH='@MACOSX_SDK_PATH@';
        $FRAMEWORKSHOME = $MACOSX_SDK_PATH."/System/Library/Frameworks";
    }
    else
    {
        print "Setting values for Mac OS X/Darwin on default x86... ";
        $MACOSX_SDK_PATH='@MACOSX_SDK_PATH@';
        $FRAMEWORKSHOME = $MACOSX_SDK_PATH."/System/Library/Frameworks";
    }
}
elsif ( $platform =~ m/dragonfly/ )
{
    # General DragonFly settings:
    $COMPATH        = '@COMPATH@';
}
elsif ( $platform =~ m/aix/ )
{
    $COMPATH        = '@COMPATH@';
}
else
{
	print "\nset_soenv:  Cannot recognize the platform you are building for: $platform.\n";
	exit 1;
}
print "done\n";

#
# D. Gathering directory information from the user.
#
# If the directory does not exist something is strange.
# 1. LibreOffice build home directory.
# SRC_ROOT should already be in the env due to config_host.mk
$SRC_ROOT = $ENV{"SRC_ROOT"};
CheckPathExist( $SRC_ROOT );


# 3. bash path.
$OOO_SHELL = '@BASH@';

# ml.exe assembler path for Windows users.
if ($platform =~ m/cygwin/)
{
    $ASM_PATH = PathFormat('@ASM_HOME@');
}

#
# E. Determining the envionment values based on the information
#    that was gathered earlier on.

$USR                  = $ds."usr";
$ETC                  = $ds."etc";
$BIN                  = $ds."bin";
$LIB                  = $ds."lib";
$LIB64                = $ds."lib";
$LIB64               .= "64" if ($platform =~ m/x86_64-.*-linux/);
$LIB64               .= "64" if (($platform =~ m/powerpc64-.*-linux/) && ('@SIZEOF_LONG@' eq '8'));
$LIB64               .= "64" if (($platform =~ m/s390x-.*-linux/) && ('@SIZEOF_LONG@' eq '8'));
$LIB64               .= $ds."x64" if ($platform =~ m/cygwin/);
$INC                  = $ds."inc";
$INCLUDE              = $ds."include";
$DEV                  = $ds."dev";
$OPT                  = $ds."opt";
$LOCAL                = $ds."local";
$SOLENV               = $ds."solenv";
$SOLVER               = $ds."solver";
$DEFIMGS              = $ds."icon-themes/galaxy";
$CONFIG               = $ds."config";
$USR_BIN              = $USR.$BIN;
$USR_LIB              = $USR.$LIB64;
$USR_LOCAL            = $USR.$ds."local";
$USR_CCS              = $USR.$ds."ccs";
$USR_OPENWIN          = $USR.$ds."openwin";
$USR_DT               = $USR.$ds."dt";
$COMMON_BUILD_TOOLS   = '$SRC_ROOT'.$ds."external".$ds."common";

# Windows NT only variables
if ($platform =~ m/cygwin/)
{
   if ( $JAVA_HOME ne "" && $JAVA_HOME ne "NO_JAVA_HOME" )
   {
      $JAVA_LIB             = $JAVA_HOME.$LIB;
   }
   # Import SystemDrive enviroment variable
   use Env qw(SYSTEMDRIVE);
   # Change $SYSTEMDRIVE to lower case.
   $SYSTEMDRIVE          = lc $SYSTEMDRIVE;
   use Env qw(SYSTEMROOT);
   $CYGWIN_PATH          = PathFormat('/usr/bin'); # Windows bash path
   $WIN_GREP             = '$CYGWIN_PATH'.$ds."grep.exe";
   $WIN_FIND             = '$CYGWIN_PATH'.$ds."find.exe";
   $WIN_LS               = '$CYGWIN_PATH'.$ds."ls.exe";
   $WIN_GNUCOPY          = '$CYGWIN_PATH'.$ds."cp.exe";
   $WIN_TOUCH            = '$CYGWIN_PATH'.$ds."touch.exe";
}

if ( $JAVA_HOME ne "" && $JAVA_HOME ne "NO_JAVA_HOME" )
{
   $JAVA_BIN             = $JAVA_HOME.$BIN;
   $JAVA_INCLUDE         = $JAVA_HOME.$INCLUDE;
}


$PERL                 = PathFormat('@PERL@'); # Perl program
$PERL_PATH            = dirname('@PERL@'); # Perl Path
$XLIB                 = PathFormat('@XLIB@'); # X11 libraries
$XINC                 = PathFormat('@XINC@'); # X11 includes

# The project's workstamp.
$WORK_STAMP            = "@SOURCEVERSION@";
# Location of the source.
$SOLARSRC             = '$SRC_ROOT';

# default TARFILE_LOCATION
if ('@TARFILE_LOCATION@' eq "DEFAULT")
{	$TARFILE_LOCATION="$SRC_ROOT/src";
}

#
$SOLARENV             = PathFormat($SRC_ROOT.$SOLENV);
# Location of the solver tree.
$SOLARVER             = $SRC_ROOT.$SOLVER;

#Location of Solar version.
$SOLARVERSION         = '$SOLARVER';

#Location of gnu make directories.
$WORKDIR              = '$SRC_ROOT/workdir/$INPATH';
$OUTDIR              = '$SOLARVER/$INPATH';
#Some directories that are symlinks under rawbuild, have to use realpath on Cygwin
$SOLARDEFIMG          = PathFormat($SRC_ROOT.$DEFIMGS);


$SOLARENVINC          = '$SOLARENV'.$INC;
# Location of dmake resource.
$DMAKEROOT            = '$SOLARENVINC'.$ds."startup";
# Location of JDK classes .zip file.
# but in jdk 1.2 it is called rt.jar and it lives in jre/lib
$CLASSPATH            = '';
$CLASSPATH           .= $JAVA_HOME.$ds.'jre'.$LIB.$ds."rt.jar" if (-f $JAVA_HOME.$ds.'jre'.$LIB.$ds."rt.jar");
$CLASSPATH           .= $wps.'.' if ($CLASSPATH ne '');

# Why do we need XCLASSPATH when it has the exact same value as CLASSPATH?
$XCLASSPATH           = $CLASSPATH;

# Location of the translations module
$L10N_MODULE = PathFormat($SRC_ROOT."/translations");

# Check for poor help localizations, i.e. no help translation at all...
@languages=();
if (opendir(DIR,$L10N_MODULE . "/source"))
{
    @languages = readdir(DIR);
    closedir(DIR);
}
$WITH_POOR_HELP_LOCALIZATIONS = "";

foreach $language (@languages)
{
    if ( ($language ne ".") && ($language ne "..") && (! -d $L10N_MODULE . "/source/" . $language . "/helpcontent2") )
    {
        $WITH_POOR_HELP_LOCALIZATIONS = $WITH_POOR_HELP_LOCALIZATIONS . " " . $language;
    }
}

# Location used by the linker to create libraries.
if ($platform =~ m/solaris/)
{  $SOLAREXTRALIB     = $L.$par_dir.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$ds."lib.solaris.2.6".
                        $L.$LIB.
                        $L.$USR.$LIB.
                        $L.$USR.$LOCAL.$LIB.
                        $L.$USR_DT.$LIB.
                        $L.$USR_OPENWIN.$LIB;
}
elsif ($platform =~ m/linux|netbsd|freebsd|aix|openbsd|dragonfly/)
{
   $SOLAREXTRALIB     = $L.$par_dir.$LIB64;
}
elsif ($platform =~ m/darwin/ && $platform !~ m/^arm/)
{
  # Nothing should be needed
}
elsif ($platform !~ m/cygwin/ && $platform !~ m/mingw32/ && $platform !~ m/^arm-apple/)
{  AddWarning( "set_soenv", "$platform not configured for linkage create libraries" );
}

# Windows NT only variables
if ($platform =~ m/cygwin/)
{  $COMP_ENV          = $OUTPATH;

   $JAVAHOME          = $JAVA_HOME;

   $ILIB             = $cur_dir;

   $ILIB       .=    $wps.$SOLARVER.$ds.$INPATH.$LIB;
   if ( $JAVA_HOME ne "" && $JAVA_HOME ne "NO_JAVA_HOME" ) {
       $ILIB   .= $wps.$JAVA_HOME.$LIB;
   }
   if ( $CL_X64 ne "TRUE" ) {
       $ILIB   .= $wps.$COMPATH.$LIB.
                  $wps.$WINDOWS_SDK_HOME.$LIB;
   } else {
       $ILIB   .= $wps.$COMPATH.$LIB.$ds."amd64".
                  $wps.$WINDOWS_SDK_HOME.$LIB64;
   }
   $ILIB       .= $wps.$DOTNET_FRAMEWORK_HOME.$LIB;
   if ( '@ENABLE_DIRECTX@' ne "" ) {
       $ILIB   .= $wps.$DIRECTXSDK_LIB;
   }
   # ILIB needs to use '\' directory seperators;
   $ILIB = WinPath( $ILIB, ";" );

   $JAVAHOME          = $JAVA_HOME;

}

# The general environment path.
if ($platform =~ m/linux|netbsd|freebsd|aix|solaris|openbsd|dragonfly/)
{  $PATH              = $cur_dir.
                        $ps.'$SOLARENV'.$ds.'$OUTPATH'.$BIN.
                        $ps.'$SOLARENV'.$BIN;

   if ($platform =~ m/solaris/) {
	$PATH .= $ps.$USR_CCS.$BIN;
   }

   $PATH             .= $ps.$oldPATH;

   my @javaBits;
   if ( $JAVA_HOME ne "" && $JAVA_HOME ne "NO_JAVA_HOME"  &&  $JDK ne "gcj" ) {
      @javaBits = ( $JAVA_HOME.$BIN, 'javac' );
   } else {
      @javaBits = ();
   }
   $PATH              = GetCorrectPath ($PATH,
                                        $COMPATH, $CC,
                                        $PERL_PATH, 'perl',
                                        @javaBits);
}

elsif ($platform =~ m/cygwin/)
{  # The PATH variable is completely created from scratch. Elements
   # from oldPATH that are not yet included are appended to PATH at
   # the end.

   my ( $tmppath );

   $PATH              = $cur_dir.
                        $ps.CygFormat($SOLARENV).$ds."bin".
                        $ps.CygFormat($SOLARENV).$ds.$OUTPATH.$BIN;

   if ( $JAVA_HOME ne "" && $JAVA_HOME ne "NO_JAVA_HOME" )
   {
      # hack either "hotspot" or "client" should be used, depending on the jdk version:
      # 1.2.x   -   no such directory, unsupported
      # 1.3.x   -   hotspot, client missing
      # 1.4.x   -   client, hotspot missing

      $PATH .= $ps.CygFormat($JAVA_HOME).$BIN;
	  if ( -d $JAVA_HOME.$ds."jre".$ds."bin".$ds."hotspot" ) {
		  $PATH .= $ps.CygFormat($JAVA_HOME).$ds."jre".$ds."bin".$ds."hotspot";
	  }
	  if ( -d $JAVA_HOME.$ds."jre".$ds."bin".$ds."client" ) {
		  $PATH .= $ps.CygFormat($JAVA_HOME).$ds."jre".$ds."bin".$ds."client";
	  }
   }

   # Add path to compiler
   $tmppath = CygFormat($COMPATH).$BIN;
   $tmppath .= $ds."amd64" if $CL_X64;
   $tmppath =~ s/^\/\//\//;
   if ( "$PATH:$oldPATH" !~ /(?:[:]|\A)(?:$tmppath)(?:[:]|\Z)/ ) {
       $PATH .= $ps.$tmppath;
   }

    $tmppath = CygFormat($MSPDB_PATH);
    # for MSVC to find mspdb*.dll
    if ( "$PATH:$oldPATH" !~ /(?:[:]|\A)(?:$tmppath)(?:[:]|\Z)/ ) {
        $PATH .= $ps.$tmppath;
    }
    # need midl.exe
    $tmppath = CygFormat($MIDL_PATH);
    if ( "$PATH:$oldPATH" !~ /(?:[:]|\A)(?:$tmppath)(?:[:]|\Z)/ ) {
        $PATH .= $ps.$tmppath;
    }
    # needs csc.exe
    $tmppath = CygFormat($CSC_PATH);
    if ( "$PATH:$oldPATH" !~ /(?:[:]|\A)(?:$tmppath)(?:[:]|\Z)/ ) {
        $PATH .= $ps.$tmppath;
    }
    # Installer needs some files if the Windows Installer SDK
    $tmppath = CygFormat($WINDOWS_SDK_HOME);
    if ( "$PATH:$oldPATH" !~ /(?:[:]|\A)(?:$tmppath\/bin)(?:[:]|\Z)/i ) {
        $PATH .= $ps.$tmppath.$BIN;
    }

   if ( $ASM_PATH ne "ASM_IN_PATH" )
   {   $PATH          .= $ps.CygFormat($ASM_PATH);
   }

   # Possible cygwin paths must follow behind the OOo and MS paths.
   # What the above comment means I have no idea.

   # Check if $PERL_PATH is already set in PATH
   $tmppath = CygFormat($PERL_PATH);
   if ( "$PATH:$oldPATH" !~ /(?:[:]|\A)(?:$tmppath)(?:[:]|\Z)/ ) {
      $PATH          .= $ps.$tmppath;
   }
   # path to sn.exe (signing) for Windows users.
   my $sn_path = PathFormat('@DOTNET_FRAMEWORK_HOME@/bin');
   $tmppath = CygFormat($sn_path);
   if ( "$PATH:$oldPATH" !~ /(?:[:]|\A)(?:$tmppath)(?:[:]|\Z)/ ) {
       $PATH          .= $ps.$tmppath;
   }

   # Add the rest of the original path if it is still missing.
   my $expandedPATH = $PATH;
   $expandedPATH =~ s/(\$\w+)/$1/eeg;

   # fix situations where PATH may look like /bin:"C:\blah\bleh":/ugh
   my $fixedPATH = $oldPATH;
   if ( $oldPATH =~ /"/ ) {
   $fixedPATH = "";
   foreach my $pathentry ( split( '"',$oldPATH ) ) {
       if ( ( $pathentry =~ /^$ps/ ) || ( $pathentry =~ /$ps$/ ) ) {
       $fixedPATH .= $pathentry;
       } else {
       chomp( $pathentry = qx{cygpath -d "$pathentry"} ) ;
       chomp( $pathentry = qx{cygpath -u "$pathentry"} ) ;
       $fixedPATH .= $pathentry;
       }
   }
   }

   foreach my $pathentry (split($ps,$fixedPATH)) {
       if ( ! ( $expandedPATH =~ /(?:$ps|\A)(?:$pathentry)(?:$ps|\Z)/ ) ) {
           $PATH .= $ps.$pathentry;
           $expandedPATH .= $ps.$pathentry;
       }
   }

   # The path now is in cygwin posix format

}
elsif ($platform =~ m/mingw32/)
{
   my ( $tmppath );

   $PATH              = $cur_dir.
                        $ps.CygFormat($SOLARENV).$ds."bin".
                        $ps.CygFormat($SOLARENV).$ds.$OUTPATH.$BIN;

   $PATH              .= $ps.$oldPATH;
}
elsif ($platform =~ m/darwin/)
{  $PATH              = $cur_dir.
                        $ps.'$SOLARENV'.$ds.'$OUTPATH'.$BIN.
                        $ps.'$SOLARENV'.$BIN;

  # Append old PATH
  $PATH             .= $ps.$oldPATH;
}
else
{  AddWarning( "set_soenv", "$platform not configured for general environment paths" );
}

# Linker library search directory paths.
if ($platform =~ m/solaris/)
{  $SOLARLIB          = $L.$par_dir.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB.
                        $L.'$SOLARVER'.$ds.'$INPATH'.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB."solaris.2.6".
                        $L.$LIB.
                        $L.$USR_LIB;
   if ( $CC =~ "gcc" ) {
      $SOLARLIB      .= $L.$COMPATH.$LIB;
   }
   $SOLARLIB         .= $L.$USR_LOCAL.$LIB.
                        $L.$USR_DT.$LIB.
                        $L.$USR_OPENWIN.$LIB.
                        $L.$XLIB;

}
elsif ($platform =~ m/linux|netbsd|aix|freebsd|openbsd|dragonfly/)
{  $SOLARLIB          = $L.$par_dir.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB.
                        $L.'$SOLARVER'.$ds.'$INPATH'.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB;
   if ($platform =~ m/openbsd/) {
      $SOLARLIB       .= $L.$USR_LOCAL.$LIB;
   }
   if ( $XLIB ne "/usr/lib" && $XLIB ne "/usr/lib64" && $XLIB ne "no_x_libraries" ) {
      $SOLARLIB       .= $L.$XLIB;
   }
}
elsif ($platform =~ m/cygwin|mingw32/)
{  $SOLARLIB          = $L.$par_dir.$LIB.
                        $L.'$SOLARENV'.$ds.'$OUTPATH'.$LIB.
                        $L.'$SOLARVER'.$ds.'$INPATH'.$LIB;
}
elsif ($platform =~ m/darwin/)
{  $SOLARLIB          = $L.'$SOLARVER'.$ds.'$INPATH'.$LIB;
}

if ($SYSTEM_MOZILLA eq "YES")
{
       $SOLARLIB .= $L."@MOZ_LIB@"
}

# Location of the compiler include search directory paths.
$SOLARINC             = $I.$cur_dir.
                        $I.'$SOLARVER'.$ds.'$INPATH'.$INC.$ds."stl".
                        $I.'$SOLARVER'.$ds.'$INPATH'.$INC.$ds."external".
                        $I.'$SOLARVER'.$ds.'$INPATH'.$INC.
                        $I.'$SOLARENV'.$INC.$ds.'$OUTPATH'.
                        $I.'$SOLARENV'.$INC.
                        $I.'$SRC_ROOT'.$ds."res";

if ($platform =~ m/solaris|linux|freebsd|netbsd|aix|openbsd|dragonfly/ && '@CROSS_COMPILING@' ne 'YES')
{
    if ($platform =~ m/solaris/ && ! $CC =~ "gcc")
    {
        $SOLARINC            .= '/SC5 ';
    }
    # Platform dependent include path at the top of this list of include paths
    if ($platform =~ m/solaris/ && ! $CC =~ "gcc")
    {
        $SOLARINC         .= $I.$COMPATH.$INCLUDE;
    }

	# pickup system jpeg over java jpeg on OpenBSD
	if ($platform =~ m/openbsd/)
	{   $SOLARINC  .= $I.$USR_LOCAL.$INCLUDE;
	}
    if ( $JAVA_HOME ne "" && $JAVA_HOME ne "NO_JAVA_HOME" )
    {   $SOLARINC  .= $I.$JAVA_HOME.$INCLUDE;
	}

	#include system dependent Java include directory
	if (!($JDK eq "gcj") && $JAVA_HOME ne "" && $JAVA_HOME ne "NO_JAVA_HOME")
	{
   		if ($platform =~ m/solaris/)
   		{  $SOLARINC   .=$I.$JAVA_HOME.$INCLUDE.$ds."solaris";
   		}
   		elsif  ($platform =~ m/linux/)
   		{  $SOLARINC   .=$I.$JAVA_HOME.$INCLUDE.$ds."linux";
   		}
   		elsif ($platform =~ m/freebsd/)
   		{
      		$SOLARINC   .=$I.$JAVA_HOME.$INCLUDE.$ds."freebsd";
      		$SOLARINC   .=$I.$JAVA_HOME.$INCLUDE.$ds."bsd";
      		$SOLARINC   .=$I.$JAVA_HOME.$INCLUDE.$ds."linux";
   		}
   		elsif ($platform =~ m/netbsd/)
   		{  $SOLARINC   .=$I.$JAVA_HOME.$INCLUDE.$ds."netbsd";
   		}
		elsif ( $platform =~ m/aix/ )
		{  $SOLARINC   .=$I.$JAVA_HOME.$INCLUDE.$ds."aix";
		}
		elsif ($platform =~ m/openbsd/)
		{  $SOLARINC   .=$I.$JAVA_HOME.$INCLUDE.$ds."openbsd";
		}

   		#java threads include path

        $SOLARINC .=$I.$JAVA_HOME.$INCLUDE.$ds."native_threads".$INCLUDE;
	}
    #The tail, if needed
    if ($platform =~ m/linux|freebsd|netbsd|aix|openbsd|dragonfly/)
    {  if ( $XINC ne "/usr/include" && $XINC ne 'no_x_includes' ) {
            $SOLARINC  .= $I.$XINC;
       }
    }
}
elsif ($platform =~ m/cygwin/)
{  if ($JAVA_HOME ne "" && $JAVA_HOME ne "NO_JAVA_HOME")
   {  $SOLARINC       .= $I.$JAVA_HOME.$INCLUDE.$ds."win32".
                         $I.$JAVA_HOME.$INCLUDE;
   }
   $SOLARINC       .= $I.'$WINDOWS_SDK_HOME'.$INCLUDE.
                      $I.'$COMPATH'.$INCLUDE;
   if ( '@ENABLE_DIRECTX@' ne "" ) {
       $SOLARINC   .= $I.PathFormat('@DIRECTXSDK_HOME@').$INCLUDE;
   }
}
elsif ($platform =~ m/mingw32/)
{  if ($JAVA_HOME ne "" && $JAVA_HOME ne "NO_JAVA_HOME")
   {  if (  '@build_os' eq 'cygwin' )
      {  # Using MinGW from Cygwin. Use the normal Windows JDK
         # headers
         $SOLARINC       .= $I.$JAVA_HOME.$INCLUDE.$ds."win32".
                            $I.$JAVA_HOME.$INCLUDE;
      }
      else
      {  # Cross-compilation. Use our fake jni_md.h
         # and othewise the build platform JDK headers
         $SOLARINC       .= $I.$SOLARENVINC.$ds."win32".
                            $I.$JAVA_HOME.$INCLUDE;
      }
   }
}
elsif ($platform =~ m/darwin/ && $platform !~ m/^arm/)
{  $SOLARINC         .= $I.$FRAMEWORKSHOME.$ds."JavaVM.framework".$ds."Versions".$ds."Current".$ds."Headers".
                        $I.$FRAMEWORKSHOME.$ds."JavaVM.framework".$ds."Headers";
}
elsif ($platform =~ m/^arm-apple/)
{
}
elsif ($platform =~ m/linux-androideabi$/)
{
}
else
{  AddWarning( "set_soenv", "$platform not configured for system dependant include dir" );
}

$gb_REPOS = $SRC_ROOT;
$BUILD_TYPE = "@BUILD_TYPE@";

if ('@WITH_LANG@' ne "")
{
    $BUILD_TYPE = "@BUILD_TYPE@ TRANSLATIONS";
}
else
{
    $BUILD_TYPE = "@BUILD_TYPE@";
}

#
# F. Setting the different aliases.
#
# 1. alias for a full product make.
	$mkout           = '"perl $SOLARENV/bin/mkout.pl"';
	$deliver         = '"perl $SOLARENV/bin/deliver.pl"';
	$build           = '"perl $SOLARENV/bin/build.pl"';
	$zipdep          = '"perl $SOLARENV/bin/zipdep.pl"';

#
#--------------------------
# VI. Open the output file.
#--------------------------
#
$outfile = 'Env.Host.sh';

open( OUT, ">$SRC_ROOT/$outfile" ) ||
   die "Cannot open $SRC_ROOT/$outfile: $!\n";

#
#------------------------------------------
# VII. Writing the data to the output file.
#------------------------------------------
#
# Write file header.
CreateFileHeader( *OUT, $UPD, $platform, "sh/bash/ksh", "#" );

ToFile( "OOO_SHELL",         $OOO_SHELL,         "e" );
ToFile( "JAVA_HOME",         $JAVA_HOME,         "e" );
ToFile( "L10N_MODULE",       $L10N_MODULE,       "e" );
ToFile( "ANT_HOME",          PathFormat("@ANT_HOME@"), "e" );
ToFile( "ANT_LIB",           PathFormat("@ANT_LIB@"), "e" );
ToFile( "ANT",               PathFormat("@ANT@"), "e" );
ToFile( "JDKLIB",            $JAVA_LIB,          "e" );
ToFile( "ASM_PATH",          $ASM_PATH,          "e" );
ToFile( "FRAMEWORKSHOME",    $FRAMEWORKSHOME,    "e" );
ToFile( "Empty",             $empty,             "n" );

#
# Writing the platform independent constant values to file.
# (c = comment, e = environment variable, a = alias )
ToFile( "Platform independent constant values.", $empty, "c" );
# Languages
ToFile( "WITH_POOR_HELP_LOCALIZATIONS", $WITH_POOR_HELP_LOCALIZATIONS, "e" );

if ("@ENABLE_DEBUG@" eq "TRUE") {
ToFile( "debug",             "true",             "e" );
}
if ("@ENABLE_WERROR@" eq "FALSE") {
ToFile( "EXTERNAL_WARNINGS_NOT_ERRORS", "TRUE",  "e" );
}
ToFile( "PROEXT",            $PROEXT,            "e" );
ToFile( "nodep",             "@nodep@",          "e" );
ToFile( "TARFILE_LOCATION",  $TARFILE_LOCATION,  "e" );

#
# Writing the platform dependent constant values to file.
# (c = comment, e = environment variable, a = alias )
ToFile( "Platform dependent constant values.", $empty, "c" );
ToFile( "SOLAR_JAVA",        $SOLAR_JAVA,        "e" );
ToFile( "COMPATH",           $COMPATH,           "e" );
ToFile( "OSVERSION",         $OSVERSION,         "e" );
ToFile( "COMEX",             $COMEX,             "e" );
ToFile( "DYNAMIC_CRT",       $DYNAMIC_CRT,       "e" );
ToFile( "use_shl_versions",  $use_shl_versions,  "e" );

if ( $platform =~ m/darwin/ && $platform !~ m/^arm/)
{
# MAXOSX_DEPLOYMENT_TARGET : The minimum version required to run the build,
# build can assume functions/libraries of that version to be available
# unless you want to do runtime checks for 10.5 api, you also want to use the 10.4 sdk
# (safer/easier than dealing with the MAC_OS_X_VERSION_MAX_ALLOWED macro)
# http://developer.apple.com/technotes/tn2002/tn2064.html
    ToFile( "MACOSX_DEPLOYMENT_TARGET",       "@MACOSX_DEPLOYMENT_TARGET@",       "e" );
    ToFile( "MACOSX_SDK_PATH",                "@MACOSX_SDK_PATH@",                "e" );
    ToFile( "MAC_OS_X_VERSION_MIN_REQUIRED",  "@MAC_OS_X_VERSION_MIN_REQUIRED@", "e" );
    ToFile( "MAC_OS_X_VERSION_MAX_ALLOWED",   "@MAC_OS_X_VERSION_MAX_ALLOWED@",  "e" );
}

#
# Writing the variables to file.
# (c = comment, e = environment variable, a = alias, n = newline )
ToFile( "Variable values.",  $empty,             "c" );
if ( $platform =~ m/cygwin/ )
{  ToFile( "CYGWIN_PATH",       $CYGWIN_PATH,       "e" );
   ToFile( "WINDOWS_SDK_HOME",  $WINDOWS_SDK_HOME,  "e" );
   ToFile( "DIRECTXSDK_LIB",    $DIRECTXSDK_LIB,    "e" );
   ToFile( "USE_DIRECTX5",      $USE_DIRECTX5,      "e" );
   ToFile( "ATL_LIB",           $ATL_LIB,           "e" );
   ToFile( "ATL_INCLUDE",       $ATL_INCLUDE,       "e" );
   ToFile( "MFC_LIB",           $MFC_LIB,         "e" );
   ToFile( "MFC_INCLUDE",       $MFC_INCLUDE,       "e" );
   ToFile( "DISABLE_ACTIVEX",   "@DISABLE_ACTIVEX@","e" );
   ToFile( "DISABLE_ATL",   "@DISABLE_ATL@","e" );
   ToFile( "INCLUDE",           "",                 "e" );
   # Variables used when building the parts that needs to be available
   # also as 64-bit versions in a 32-bit LibreOffice build, like
   # the Explorer extension. If the configure script hasn't
   # found the 64-bit (cross-)compiler, then @BUILD_X64@ will be empty.
   ToFile( "BUILD_X64",         "@BUILD_X64@",      "e" );
   if ( "@BUILD_X64@" eq "TRUE" ) {
       ToFile( "CC_X64_BINARY", "@CC_X64_BINARY@",  "e" );
       ToFile( "CXX_X64_BINARY","@CXX_X64_BINARY@", "e" );
       ToFile( "LINK_X64_BINARY","@LINK_X64_BINARY@","e" );
       ToFile( "LIBMGR_X64_BINARY","@LIBMGR_X64_BINARY@","e" );
   }

   # Hack around dmake's mktmp not generating DOS paths.
   my $tmpdir = qx{cygpath -m "/tmp"};
   chomp($tmpdir);
   ToFile( "TMPDIR",     $tmpdir,            "e" );
   if ( !defined $ENV{"TMP"} || $ENV{"TMP"} eq "" ) {
      ToFile( "TMP", $tmpdir, "e" );
   } else {
      ToFile( "TMP", "$ENV{'TMP'}", "e" );
   }
}
elsif ( $platform =~ m/mingw32/ )
{  ToFile( "DISABLE_ACTIVEX",   "@DISABLE_ACTIVEX@","e" );
   ToFile( "DISABLE_ATL",       "@DISABLE_ATL@",    "e" );
   ToFile( "MINGW_CLIB_DIR",    "@MINGW_CLIB_DIR@", "e" );
   ToFile( "MINGW_SHARED_GCCLIB", "@MINGW_SHARED_GCCLIB@", "e" );
   ToFile( "MINGW_SHARED_GXXLIB", "@MINGW_SHARED_GXXLIB@", "e" );
   ToFile( "MINGW_SHARED_LIBSTDCPP", "@MINGW_SHARED_LIBSTDCPP@", "e" );
   ToFile( "MINGW_GCCDLL",      "@MINGW_GCCDLL@",   "e" );
   ToFile( "MINGW_GXXDLL",      "@MINGW_GXXDLL@",   "e" );

}

if ("@WITH_VC_REDIST@" eq "TRUE") {
ToFile( "WITH_VC_REDIST", "TRUE",  "e" );
}
ToFile( "PERL",              $PERL,              "e" );
ToFile( "WORK_STAMP",        $WORK_STAMP,        "e" );
ToFile( "SOLARVER",          $SOLARVER,          "e" );
ToFile( "SOLARVERSION",      $SOLARVERSION,      "e" );
ToFile( "WORKDIR",           $WORKDIR,           "e" );
ToFile( "OUTDIR",            $OUTDIR,            "e" );
ToFile( "SOLARENV",          $SOLARENV,          "e" );
ToFile( "SOLARDEFIMG",       $SOLARDEFIMG,       "e" );
ToFile( "SOLARENVINC",       $SOLARENVINC,       "e" );
ToFile( "DMAKEROOT",         $DMAKEROOT,         "e" );
if ( $JDK ne "gcj" ) {
   ToFile( "CLASSPATH",         $CLASSPATH,         "e" );
   ToFile( "XCLASSPATH",        $XCLASSPATH,        "e" );
   ToFile( "JAVACISKAFFE",     '@JAVACISKAFFE@',    "e" );
}
else {
   ToFile( "JAVACISGCJ",       '@JAVACISGCJ@',      "e" );
}
if ( '@JDK@' ne '' )
{
   ToFile( "JDK",             "@JDK@",           "e" );
   ToFile( "JAVAFLAGS",             "@JAVAFLAGS@",           "e" );
   ToFile( "JAVA_SOURCE_VER", "@JAVA_SOURCE_VER@","e" );
   ToFile( "JAVA_TARGET_VER", "@JAVA_TARGET_VER@","e" );
   ToFile( "JAVAINTERPRETER", PathFormat("@JAVAINTERPRETER@"), "e" );
   ToFile( "JAVAIFLAGS",      "@JAVAIFLAGS@",    "e" );
   ToFile( "JAVACOMPILER",    PathFormat("@JAVACOMPILER@"), "e" );
   ToFile( "JAVADOC",         PathFormat("@JAVADOC@"), "e" );
   ToFile( "JVM_ONE_PATH_CHECK", "@JVM_ONE_PATH_CHECK@", "e" );
}
ToFile( "SOLAREXTRAINC",     $SOLAREXTRAINC,     "e" );
ToFile( "SOLAREXTRALIB",     $SOLAREXTRALIB,     "e" );
if ( '@CROSS_COMPILING@' eq 'YES' )
{
   # Obviously we shouldn't set PATH to contain host binaries
   ToFile( "PATH",           "@PATH_FOR_BUILD@", "e" );
}
else
{
   ToFile( "PATH",           $PATH,              "e" );
}
ToFile( "SOLARLIB",          $SOLARLIB,          "e" );
ToFile( "SOLARINC",          $SOLARINC,          "e" );
ToFile( "COMP_ENV",          $COMP_ENV,          "e" );
ToFile( "JAVAHOME",          $JAVAHOME,          "e" );
ToFile( "CC",                $CC,                "e" );
if ( defined $ENV{SYSBASE} )
{  $SYSBASE = $ENV{SYSBASE};
}
else
{  $SYSBASE = '';
}
ToFile( "SYSBASE",           "$SYSBASE",         "e" );
ToFile( "BUILD_PLATFORM",    "@build@",          "e" );
ToFile( "HOST_PLATFORM",     "@host@",           "e" );
if ( '@CROSS_COMPILING@' eq 'YES' )
{
   ToFile( "CC_FOR_BUILD",      "@CC_FOR_BUILD@",   "e" );
   ToFile( "CXX_FOR_BUILD",     "@CXX_FOR_BUILD@",  "e" );
   ToFile( "GXX_INCLUDE_PATH_FOR_BUILD", "@GXX_INCLUDE_PATH_FOR_BUILD@", "e" );
   ToFile( "MACOSX_DEPLOYMENT_TARGET_FOR_BUILD", "@MACOSX_DEPLOYMENT_TARGET_FOR_BUILD@", "e" );
   ToFile( "SYSTEM_LIBXSLT_FOR_BUILD", "@SYSTEM_LIBXSLT_FOR_BUILD@", "e" );
   ToFile( "OUTDIR_FOR_BUILD",  "@OUTDIR_FOR_BUILD@", "e");
   ToFile( "SOLARINC_FOR_BUILD", "@SOLARINC_FOR_BUILD@", "e");
   ToFile( "SOLARLIB_FOR_BUILD", "@SOLARLIB_FOR_BUILD@", "e");
   ToFile( "WORKDIR_FOR_BUILD", "@WORKDIR_FOR_BUILD@", "e");
}
else
{
   ToFile( "CC_FOR_BUILD",      $CC,             "e" );
   ToFile( "CXX_FOR_BUILD",     $CXX,            "e" );
   ToFile( "GXX_INCLUDE_PATH_FOR_BUILD", PathFormat("@GXX_INCLUDE_PATH@"), "e" );
   ToFile( "SYSTEM_LIBXSLT_FOR_BUILD", "@SYSTEM_LIBXSLT@", "e" );
   ToFile( "OUTDIR_FOR_BUILD",  $OUTDIR,         "e" );
   ToFile( "PATH_FOR_BUILD",    $PATH,           "e" );
   ToFile( "SOLARINC_FOR_BUILD", $SOLARINC,      "e" );
   ToFile( "SOLARLIB_FOR_BUILD", $SOLARLIB,      "e" );
   ToFile( "WORKDIR_FOR_BUILD", $WORKDIR,        "e" );
}
ToFile( "CXX",               $CXX,               "e" );
ToFile( "BUILD_TYPE",        "$BUILD_TYPE",      "e" );
if ( '@ENABLE_RPATH@' eq "no" ) {
  ToFile( "LINKFLAGSRUNPATH",'',                   "e" );
}
ToFile( "EPM_FLAGS",         $EPM_FLAGS,           "e" );
ToFile( "GXX_INCLUDE_PATH",  PathFormat("@GXX_INCLUDE_PATH@"), "e" );
ToFile( "COMMON_BUILD_TOOLS",$COMMON_BUILD_TOOLS,  "e" );

if ($platform !~ m/cygwin/) {
   if ( !defined $ENV{"TMPDIR"} || $ENV{"TMPDIR"} eq "" ) {
      ToFile( "TMPDIR",      "/tmp",               "e" );
   } else {
      ToFile( "TMPDIR",      "$ENV{'TMPDIR'}",     "e" );
   }
}
ToFile( "SOLARSRC",           $SOLARSRC,           "e" );
ToFile( "SRCDIR",           $SOLARSRC,           "e" );

if ( $platform =~ m/cygwin/ )
{
   ToFile( "ILIB",              $ILIB,              "e" );
   ToFile( "GREP",              $WIN_GREP,          "e" );
   ToFile( "FIND",              $WIN_FIND,          "e" );
   ToFile( "LS",                $WIN_LS,            "e" );
   ToFile( "GNUCOPY",           $WIN_GNUCOPY,       "e" );
   ToFile( "TOUCH",             $WIN_TOUCH,         "e" );
}

ToFile( "DELIVER",       "deliver.pl",     "e" );
ToFile( "MKOUT",         "mkout.pl",       "e" );
ToFile( "ZIPDEP",        "zipdep.pl",      "e" );

#
# Writing the aliases to file.
ToFile( "Aliases.",          $empty,             "c" );
ToFile( "Don't set aliases when bootstrapping", $empty, "c" );

ToFile( "alias mkout",       $mkout,             "a" );
ToFile( "alias deliver",     $deliver,           "a" );
ToFile( "alias build",       $build,             "a" );
ToFile( "alias zipdep",      $zipdep,            "a" );

# on Solaris, MacOSX and FreeBSD, set GNUCOPY and GNUPATCH
if ($platform =~ m/solaris|darwin|freebsd/)
{
  ToFile( "GNUPATCH",   "@GNUPATCH@",	"e");
}

ToFile( "ENV_SCRIPT", "$outfile", "e" );
#
# Writing unset variables you might not need to file.
#
print OUT "export $exportvars$newline";
print OUT "unset $unsetvars$newline";

#
#---------------------------
# VIII. Closing output file.
#---------------------------
#
close( OUT ) || print "Can't close $SRC_ROOT/$outfile: $!";

#--------------------------------------------------------
# XII. Message at the end.
#--------------------------------------------------------
#
#
print "$newline";
print "*********************************************************".
      "*******************$newline*$newline";
print "* LibreOffice configuration finished. $newline*$newline";

if ( $Warning ne "" )
{  print "$Warning*$newline";
}

print "*********************************************************".
      "******************* $newline";

print "To build, issue:\n$GNUMAKE\n\n";
print "To install when the build is finished, issue:\n$GNUMAKE install\n\n";
print "If you want to develop LibreOffice, you might prefer:\n$GNUMAKE dev-install\n\n";
print "If you want to run the smoketest, issue:\n$GNUMAKE check\n\n";

if ("@STALE_MAKE@" eq "TRUE" && $platform =~ m/cygwin/ ) {
print << 'EOS'
WARNING:
Your make version is known to be horribly slow, and hard to debug
problems with. To get a reasonably functional make please do:

to install a pre-compiled binary make for cygwin

mkdir -p /opt/lo/bin
cd /opt/lo/bin
wget http://dev-www.libreoffice.org/bin/cygwin/make
chmod +x make

to install from source:
place yourself in a working directory of you choice.

git clone git://anongit.freedesktop.org/libreoffice/contrib/dev-tools
cd dev-tools/make-3.82-gbuild
./configure --prefix=/opt/lo
make
sudo make install

Then re-run autogen.sh

Note: autogen.sh will try to use /opt/lo/bin/make if the environment variable GNUMAKE is not already defined.
Alternatively, you can install the 'new' make where ever you want and make sure that `which make` finds it.

EOS
}

if ( $Warning ne "" ) {
	print "***** WARNINGS ISSUED *****\n";
}

#
#-----------------
# XII. Functions.
#-----------------
#
#-------------------------------------------------------------
# Function name: CheckPathName
# Description:   chops off the '/' character if it's the last
#                character in a pathname. also adds the '/'
#                character if it's not the first character
#                in a path.
# Arguments:     1. Path (string)
# Return value:  Path (string)
#-------------------------------------------------------------
sub CheckPathName
{  my $retrn = $_[ 0 ];
   if ($platform =~ m/cygwin/)
   {  # Check if the first character is not a '/'.
      if ( !( $_[ 0 ] =~ /^\// ) )
      {  $retrn = $ds.$_[ 0 ];
      }
   }
   # kill the last '/','\','\n' if they exists.
   $retrn =~ s![\s/\\]+$!!;
   # Done!
   return( $retrn );
}
#-------------------------------------------------------------
# Function name: CheckPathExist
# Description:   Checks whether the directory that is given
#                as an argument exists. If not abort.
# Arguments:     1. Path (string)
# Return value:  void
#-------------------------------------------------------------
sub CheckPathExist
{  my $dir = $_[ 0 ];
   if ( !( -d $dir ) )
   {  print ( "The directory $_[ 0 ] does not exist. Please create first.\n" );
      exit 1;
   }
   else
   {  # Don't check under ActiveState Perl (Windows). The path is possibly
      # posix and it cannot handle it.
      # Hmm, but the above test also checks for existance, so presumably
      # the mention of ActiveState in the above comment is just a red
      # herring.
      return "true";
   }
}
#------------------------------------------------------------
# Function name: CreateFileHeader
# Description:   Creates a header for the outfile.
# Arguments:     1. File to write to
#                2. UPD (string)
#                3. Platform (string)
#                4. name of shell for this file
#                5. comment to use for this file
# Return value:  void
#------------------------------------------------------------
sub CreateFileHeader
{  my $timestamp = `date`;
   chomp( $timestamp );
   my $filehandle = $_[0];
   my $comment = $_[4];
   print { $filehandle } "$comment #################################################################";
   print { $filehandle } $newline;
   print { $filehandle } "$comment LibreOffice $_[ 1 ] build environment file for: $_[ 2 ]. $newline";
   print { $filehandle } "$comment Generated on: $timestamp $newline";
   print { $filehandle } "$comment Source this file to set up the build environment. $newline";
   print { $filehandle } "$comment 1. exec $_[3] $newline";
   print { $filehandle } "$comment 2. source $outfile $newline";
   print { $filehandle } "$comment #################################################################";
   print { $filehandle } $newline;
   print { $filehandle } 'if test -z "$SRC_ROOT" ; then';
   print { $filehandle } $newline;
   print { $filehandle } " . $SRC_ROOT/config_host.mk $newline";
   print { $filehandle } "fi $newline";
   print { $filehandle } $newline;
}
#---------------------------------------------------------
# Function name: ToFile
# Description:   Writes the environment variable in the
#                output file.
# Arguments:     1. Name of environment variable (string)
#                2. Value of environment variable (string)
#                3. e - env. var
#                   a - alias
#                   c - comment
#                   n - newline
#                   z - raw, write as is to OUT
# Return value:  void
#---------------------------------------------------------
sub ToFile {
   if ( $_[ 2 ] eq "e" ) {
      # Write an environment variable to file.
      if (defined $_[ 1 ] && $_[ 1 ] ne "" ) {
         my $envvar = $_[ 1 ];

         # Tcsh/bash needs backslashes quoted
         $envvar =~ s/\\/\\\\/g;

         printf("%-12s %-17s %-10s %s\n", "The variable", $_[ 0 ], "is set to:", $envvar) if ( '@VERBOSE@' eq 'TRUE' );
         print OUT "$_[ 0 ]=\"$envvar\"$newline";      # to sh file
         $exportvars .= " $_[ 0 ]";                        # add to export list for sh file

      } else {
         printf("%-12s %-17s %-10s %s\n", "The variable", $_[ 0 ], "is set to:", "unset") if ( '@VERBOSE@' eq 'TRUE' );
         $unsetvars .= " $_[ 0 ]";                             # for sh file
      }
   }
   elsif ( $_[ 2 ] eq "a" )
   {  # Write an alias to file.
      print "The $_[ 0 ] is set to: $_[ 1 ]\n" if ( '@VERBOSE@' eq 'TRUE' );    # to stdout
      print OUT "$_[ 0 ]=$_[ 1 ]$newline";      # to sh file
   }
   elsif ( $_[ 2 ] eq "c" )
   {  # Write a comment to file.
      if ( '@VERBOSE@' eq 'TRUE' )
      {
         print "$newline";
         print "$comment$newline";
         print "$comment $_[ 0 ]$newline";
         print "$comment$newline";
      }
      print OUT "$newline";
      print OUT "$comment$newline";
      print OUT "$comment $_[ 0 ]$newline";
      print OUT "$comment$newline";
   }
   elsif ( $_[ 2 ] eq "n" )
   {  #Write a newline to a file
      print OUT "$newline";
   }
   elsif ( $_[ 2 ] eq "z" )
   {
      #Write first argument as is, and nothing else
      print OUT "$_[ 0 ]$newline";
   }
   else
   {  print "Unknown type!$newline";
   }
}
#----------------------------------------------------------
# Function name: PathFormat
# Description:   Reformat path to either POSIX or mixed mode style.
# Arguments:     1. Variable (string)
# Return value:  Reformatted String
#----------------------------------------------------------
sub PathFormat
{  my ( $variable, $d1, $d2 );
   $variable = $_[ 0 ];

   if ( $platform =~ m/cygwin/ )
   {   $variable =~ s/(\$\{?\w+\}?)/$1/eeg ; # expand the variables
       $variable =~ s/(\$\{?\w+\}?)/$1/eeg ; # expand the variables twice!

       # Complain if PosixPath is used on a PATH-like string
       if ( $variable =~ m/;/ ) {
           die( "Do not use on PATH lists (i.e., 'c:\\foo;d:\\bar')");
       }

       # Replace path with space with short dos path
       if ( $variable =~ / / ) {
           chomp( $variable = qx{cygpath -d "$variable"} ) ;
       }

       # Replace absolute paths or DOS paths with ...
       if ( ( $variable =~ m/^\// ) or ( $variable =~ m/:/ ) ) {
           # mixed mode paths
           chomp( $variable = qx{realpath "$variable"} ) unless ($variable =~ m/:/);
           chomp( $variable = qx{cygpath -m "$variable"} );
       }
   }
   return $variable;
}
#----------------------------------------------------------
# Function name: CygFormat
# Description:   Format variables to cygwin posix style path
#                unless .
# Arguments:     1. Variable (string)
# Return value:  Reformatted String
#----------------------------------------------------------
sub CygFormat
{  my ( $variable, $d1, $d2 );
   $variable = $_[ 0 ];
   # ToDo: Do the replacement only if Windows and var contains "\" and ":"
   if ( $platform =~ m/cygwin/ )
   {
       # Complain if PosixPath is used on a PATH-like string
       if ( $variable =~ m/;/ ) {
           die( "Do not use on PATH lists (i.e., 'c:\\foo;d:\\bar')");
       }

       # Replace DOS paths with posix paths
       if ( ( $variable =~ m/\\/ ) or ( $variable =~ m/:/ ) ) {
           chomp( $variable = qx{cygpath -u "$variable"} );
       }
   }
   return $variable;
}
#----------------------------------------------------------
# Function name: WinPath
# Description:   Reformat a $sep seperated path using DOS paths.
# Arguments:     1. Variable (string)
#                2. Separaror (string)
# Return value:  Reformatted String
#----------------------------------------------------------
sub WinPath
{
    my ( $variable, $d1, $sep, @split_var );

    if ( $platform =~ m/cygwin/ ) {
        $variable = $_[ 0 ];
        $sep = $_[ 1 ];
        $variable =~ s/^\s+//g ; #remove leading spaces
        $variable =~ s/\s+$//g ; #remove trailing spaces
        $variable =~ s/(\$\{?\w+\}?)/$1/eeg ; # expand the variables
        $variable =~ s/(\$\{?\w+\}?)/$1/eeg ; # expand the variables twice!

        @split_var = split(/$sep/,$variable);
        foreach $d1 ( @split_var ) {
            if ( $d1 =~ /(?:^\/[\w\.~ ]+)+/ ) {
                if ( $d1 =~ / / ) {
                    # Use DOS 8.3 style to avoid quoting
                    chomp( $d1 = qx{cygpath -d "$d1"} );
                } else {
                    # Use "normal" filenames
                    chomp( $d1 = qx{cygpath -w "$d1"} );
                }
            }
        }
        $variable = join(';',@split_var);

        $variable =~ s/\//\\/g; # Remaining \ come from e.g.: ../foo/baa
    }

    return $variable;
}

#--------------------------------------------------------
# Function name: GetCorrectPath
# Description:   Creates the build environment.
# Arguments:     1.   existing / original path
#                2... pairs of <path, executable>
# Return value:  String - Correct Path
#--------------------------------------------------------
sub GetCorrectPath
{
	sub PathLookup
	{
	    my $cmd = shift;
	    while (@_) {
		my $elem = shift;

		-x "$elem/$cmd" && return $elem;
	    }
	    return '';
	}

	sub SaneGrep
	{
	    # Perl grep is unbelievably strange.
	    my $needle = shift;
	    while (@_) {
		my $haystack = shift;
		if ($needle eq $haystack) {
		    return 1;
		}
	    }
	    return 0;
	}

	sub CleanupPath
	{
	    my @elements = @_;
	    my @cleanName = ();

	    while (@elements) {
		my $elem = shift @elements;
		if (!SaneGrep ($elem, @cleanName)) {
			push @cleanName, $elem;
		}
	    }

	    return @cleanName;
	}

	my $oldPath = shift;
	my @originalPairs = @_;
	my @pairs = @originalPairs;
	my @Path = split /$ps/, $oldPath;

	while (@pairs) {
	    my $path = shift @pairs;
	    my $cmd = shift @pairs;
	    my $to_append = 1;
	    my $elem;

	    if (! -x "$path/$cmd") {
		AddWarning ("Missing executable $path/$cmd\n");
	    }

	    for $elem (@Path) {
		if ($elem eq $path) {
#		    print "Hit duplicate path in path; break\n";
		    $to_append = 0;
		    last;
		}
		if (-f "$elem/$cmd") {
#		    print "Element already in path ...\n";
		    unshift @Path, $path;
		    $to_append = 0;
		    last;
		} else {
#		    print "No file $elem/$cmd\n";
		}
	    }
	    if ($to_append) {
		push @Path, $path;
	    }
	}

	@pairs = @originalPairs;
	while (@pairs) {
	    my $path = shift @pairs;
	    my $cmd = shift @pairs;
	    my $realpath;

	    $realpath = PathLookup ($cmd, @Path);
	    if (!($realpath eq $path)) {
		AddWarning ("Path conflict for executables " .
                            "$path/$cmd against $realpath");
	    }
	}

	return join $ps, CleanupPath (@Path);
}

#------------------------------------------------------------
# Function name: AddWarning
# Description:   Adds any kind of warning for the user.
#                The warning will be shown at the end
#                of this script.
# Arguments:     1. Add the configure warnings or the set_soenv
#                   warning (string).
#                2. Warning (string).
# Return value:  void
#------------------------------------------------------------
sub AddWarning
{  if ( $_[ 0 ] eq "configure" )
   {  open( IN, $warnfile );
      while ( <IN> )
      {  $Warning = $Warning."* - ".$_;
      }
      close( IN );
      # Remove the temporary warning file.
      # unlink ( $warnfile );
   }
   elsif ( $_[ 0 ] eq "set_soenv" )
   {  my ( $arg1 );
      $arg1 = $_[ 1 ];
      chomp( $arg1 );                            # cut off new line
      $Warning = $Warning."* - set_soenv: warning: $arg1 $newline";  # add the warning
   }
}

# vim:set shiftwidth=4 softtabstop=4 expandtab: #