-
Notifications
You must be signed in to change notification settings - Fork 146
/
egs_install_conf.cpp
1667 lines (1529 loc) · 62.9 KB
/
egs_install_conf.cpp
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
/*
###############################################################################
#
# EGSnrc configuration GUI utilities and tests
# Copyright (C) 2015 National Research Council Canada
#
# This file is part of EGSnrc.
#
# EGSnrc is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
#
# Author: Ernesto Mainegra-Hing, 2015
#
# Contributors:
#
###############################################################################
*/
#include "egs_install.h"
#include <QCoreApplication>
#include<QAbstractButton>
#define MY_VERSION "1.0"
#ifdef WIN32
#define TEST_XML "tests_win.xml"
#define TEST_C_XML "tests_unix.xml"
#else
#define TEST_XML "tests_unix.xml"
#endif
void QInstallPage::run_tests(){
printProgress(fc->version());
QString xmlf = henHouse() + QString("pieces") + QDir::separator() + QString(TEST_XML);
QString msg;
if( ! QFile::exists( xmlf ) ){
msg = QString("\n\n Test file ") + xmlf + QString(" does not exist !\n\n");
printProgress( msg );
//setFinishEnabled( currentPage(), true );
//setBackEnabled( currentPage(), true );
return;
}
else{
msg = QString("\n Using xml test file ") + xmlf + QString("\n");
}
printProgress( msg );
if( ft ) ft=0;
ft = new MTest( screen, xmlf, config_file );
connect( ft, SIGNAL( testsFinished() ),
this, SLOT( create_egs_c_utils() ) );
connect( ft, SIGNAL( taskFinished() ),
this, SLOT( updateProgress() ) );
ft->setCompilers( fc, cc );
resetProgressBar( ft->getTotalTasks() + n_config_steps );
ft->reset();
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
environment.insert("PWD",QDir::currentPath());
ft->copyEnvironment( environment );
ft->launch();
}
#define NO_EGS_UTILS_C "\nFailed to compile egs_c_utils.c. This may be due to a variety of reasons"\
"\n(e.g. non-standard include files, unsupported file lock operations, etc."\
"\nWill disable now the availability of a C compiler. "\
"\nIf you want to try to make the new parallel processing implementation in "\
"\ncavrznrc and dosrznrc work, "\
"\n 1. Go to $machine_mortran_dir "\
"\n 2. Edit egs_c_utils.h and egs_c_utils.c to make them compile with your"\
" \n C compiler"\
" \n 3. Put "\
"\n REPLACE {$HAVE_C_COMPILER(#);} WITH {{EMIT;{P1}define HAVE_C_COMPILER};}"\
" \n in machine.macros"\
" \n 4. Put "\
" \n $HAVE_C_COMPILER(#);"\
" \n near the beginning of your user code."\
"\n 5. If your compiler requires some unusual options, include directives, etc., "\
"\n change the variable C_FLAGS in the spec file $conf_file in the "\
"\n $HEN_HOUSE/specs/ directory. \n"
#define NO_LOAD_BEAMLIB "\n **** Failed to compile load_beamlib.c!!! ****"\
"\n This is the tool for loading BEAM as a particle source for other user codes."
#define NO_LOAD_VCULIB "\n **** Failed to compile load_vculib.c!!! ****"\
"\n This is the tool for using sources 20 and 21 in BEAMnrc."
//--------------------------------------------------------------------
// Updates template for egs_config1.h and copies to
// $HEN_HOUSE/lib/my_machine the sources for egs_config1.h, egs_c_utils
// and load_beamlib.
//
// Try to build C tools.
//
//--------------------------------------------------------------------
void QInstallPage::create_egs_c_utils(){
printProgress( "\n===> Creating C Utilities for EGSnrc...\n\n");
QString define = "#define F77_OBJ(fname,FNAME) ",
define_ = "#define F77_OBJ_(fname,FNAME) ";
MTestAnswer &a = ft->getAnswers();
QString f77_function1,
f77_function2;
if( a["Decoration"] == "lower case, no underscores" ){
f77_function1= define + (QString)"fname";
f77_function2= define_ + (QString)"fname";
}
else if( a["Decoration"] == "lower case, _ and _" ){
f77_function1= define + (QString)"fname##_";
f77_function2= define_ + (QString)"fname##_";
}
else if( a["Decoration"] == "lower case, _ and __" ){
f77_function1= define + (QString)"fname##_";
f77_function2= define_ + (QString)"fname##__";
}
else if( a["Decoration"] == "upper case, no underscores" ){
f77_function1= define + (QString)"FNAME";
f77_function2= define_ + (QString)"FNAME";
}
else if( a["Decoration"] == "upper case, _ and _" ){
f77_function1= define + (QString)"FNAME##_";
f77_function2= define_ + (QString)"FNAME##_";
}
else if( a["Decoration"] == "upper case, _ and __" ){
f77_function1= define + (QString)"FNAME##_";
f77_function2= define_ + (QString)"FNAME##__";
}
else{ // unknown mangling scheme, using a default
f77_function1="FNAME";
f77_function2="FNAME";
}
/************************************************************/
/* C utils need egs_config1.h or else they won't be compiled*/
/************************************************************/
QString s = readFile2QString( henHouse() + QString("pieces/egs_config1.h"),
QString(NO_EGS_UTILS_C) );
if ( s.isEmpty() ){
printProgress(tr("\nCould not read egs_config1.h, C utils not built!\n"));
emit egsCUtilsEnded();
return;
}
s.replace((QString)"__f77_function1__", f77_function1 );
s.replace((QString)"__f77_function2__", f77_function2 );
s.replace((QString)"__config_name__", my_machine() );
if ( ! writeQString2File( s, egsLibDir + QString("egs_config1.h") )){
printProgress(tr("\nCould not write egs_config1.h needed for the") +
tr("\nC interface. You won't be able to build the\n")+
tr("\nC utilities nor to write C user-codes.\n"));
// One needs to build egs_c_utils and load_beamlib and for that egs_config1.h is crucial !!!!!!
printProgress(QString("\n\n") + QString(NO_EGS_UTILS_C));
printProgress(QString("\n\n") + QString(NO_LOAD_BEAMLIB));
emit egsCUtilsFailed();
return;
}
/************************************************************/
QStringList task_f, task_q;
task_f.append("egs_c_utils.c");
task_q.append("Could egs_c_utils.c be compiled? ");
task_f.append("load_beamlib.c");
task_q.append("Could load_beamlib.c be compiled? ");
task_f.append("load_vculib.c");
task_q.append("Could load_vculib.c be compiled? ");
task_f.append("read_write_pardose.c");
task_q.append("Could read_write_pardose.c be compiled? ");
if(!cc->exists() ){
egs_c_utils_ok = false;
load_beamlib_ok = false;
read_write_pardose_ok=false;
printProgress(
tr("WARNING:\n") + tr("========\n") +
tr("No C compiler passed to the configuration process.\n") +
tr("C utilities for parallel runs and BEAM source engine\n") +
tr("will not be available for this configuration!!!\n\n")
);
emit egsCUtilsFailed();
return;
}
//*************************************************
// Compile all or missing C utilites, including
// read_write_pardose.c so DOSXYZnrc can be build.
//*********************************************
if (!copy( henHouse() + (QString)"cutils/egs_c_utils.h",
egsLibDir + (QString)"egs_c_utils.h") ||
!copy( henHouse() + (QString)"cutils/egs_c_utils.c",
egsLibDir + (QString)"egs_c_utils.c") ||
!copy( henHouse() + (QString)"cutils/load_beamlib.c",
egsLibDir + (QString)"load_beamlib.c") ||
!copy( henHouse() + (QString)"cutils/load_vculib.c",
egsLibDir + (QString)"load_vculib.c") ||
!copy( henHouse() + (QString)"user_codes/dosxyznrc/read_write_pardose.c",
egsLibDir + (QString)"read_write_pardose.c")
)
{
printProgress(tr("\n\nThere were errors copying the C utilities sources")+
tr("\nto $HEN_HOUSE/lib/my_machine."));
printProgress(tr("\nYou won't be able to: \n") +
tr("\n- Use parallel job submission in your C/C++ user-codes\n") +
tr("\n- Use a BEAM simulation as a source\n") +
tr("\n- Compile DOSXYZnrc\n") );
}
Tasks* task = new Tasks[task_f.size()];
for (int itask=0; itask < task_f.size(); itask++){
task[itask].setFName(egsLibDir + task_f[itask]);
task[itask].setDeleteFlag( false );
task[itask].setProgram( QString::null );
task[itask].setTaskName( task_q[itask] );
task[itask].setLanguage( "C" );
#ifdef WIN32
task[itask].setOptions( cc->optimization() + " " + cc->options() + " -c -DWIN32" );
#else
task[itask].setOptions( cc->optimization() + " " + cc->options() + " -c" );
#endif
}
if ( ct ) ct=0;
ct = new MTest( screen, task_f.size() , config_file );
connect( ct, SIGNAL( taskFinished() ),
this, SLOT( updateProgress() ) );
connect( ct, SIGNAL( testsFinished() ),
this, SLOT( check_egs_c_utils() ) );
connect( ct, SIGNAL( criticalError() ),
this, SLOT( check_egs_c_utils() ) );
ct->setTitle( (QString)"\nBuilding the utilities object file ... " );
ct->setEndStr( QString() );
ct->setCompilers( fc, cc );
ct->reset();
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
environment.insert("PWD",QDir::currentPath());
ct->copyEnvironment( environment );
ct->setTasks( task );
ct->launch();
}
void QInstallPage::check_egs_c_utils(){
/**********************************************/
/* Check outcome from compiling egs_c_utils.c */
/**********************************************/
bool all_ok=true;
Tasks* task = ct->tasks(); int ntasks = ct->getTotalTasks();
for (ushort itask=0; itask < ntasks; itask++){
if ( ct->successful_test(itask) ) {
QString obj_n = task[itask].objName();
obj_n = obj_n.right(obj_n.length() - obj_n.lastIndexOf(QDir::separator())- 1);
if ( fileExists( obj_n ) ){
move_file( obj_n, task[itask].objName());
}
if (obj_n.contains("egs_c_utils"))
egs_c_utils_ok = true;
else if (obj_n.contains("load_beamlib"))
load_beamlib_ok = true;
else if (obj_n.contains("load_vculib"))
load_vculib_ok = true;
else if (obj_n.contains("read_write_pardose"))
read_write_pardose_ok = true;
}
else all_ok = false;
}
if (!egs_c_utils_ok)
printProgress((QString)NO_EGS_UTILS_C);
if (!load_beamlib_ok)
printProgress((QString)NO_LOAD_BEAMLIB);
if (!load_vculib_ok)
printProgress((QString)NO_LOAD_VCULIB);
if (!read_write_pardose_ok)
printProgress(QString("\nFailed compiling read_write_pardose.c!"
"\nThis is required to compile DOSXYZnrc!"));
if (!all_ok)
if(ct) ct->stop();
updateProgress();
emit egsCUtilsCreated();
}
/*******************************************************
* Here we check whehter the egs_c_util object file can
* be linked to a Fortran file.
*******************************************************/
#define EGS_C_UTIL_VERSION " program EGSCUTIL\n"\
" integer i\n"\
" call egs_create_control_file(\"test.lock\",i)\n"\
" end\n"
void QInstallPage::test_c_utils(){
if (!egs_c_utils_ok){
printProgress("\n\nTesting egs_c_utils skipped due to previous errors...\n");
updateProgress();
emit egsCUtilsTested();
return;
}
QString test_util( EGS_C_UTIL_VERSION );
if ( ! writeQString2File( test_util, (QString)"test_c_utils.f" ) ) {
printProgress( (QString)"\n Critical error: could not create file " +
(QString)"test_c_utils.f" );
egs_c_utils_ok = false;
printProgress(tr(NO_EGS_UTILS_C));
updateProgress();
emit egsCUtilsEnded();
return;
}
if ( ct ) ct = 0;
ct = new MTest( screen, 1, config_file );
connect( ct, SIGNAL( taskFinished() ),
this, SLOT( updateProgress() ) );
connect( ct, SIGNAL( testsFinished() ),
this, SLOT( get_test_c_utils_result()));
connect( ct, SIGNAL( criticalError() ),
this, SLOT( get_test_c_utils_result()));
ct->setTitle( (QString)"\n\nTesting the C utilities object file ... " );
ct->setEndStr( QString::null );
ct->setCompilers( fc, cc );
ct->reset();
Tasks* task = new Tasks();
task->setFName( (QString)"test_c_utils.f" );
#ifdef WIN32
task->setObjects( egsLibDir + tr("egs_c_utils.obj") );
#else
task->setObjects( egsLibDir + tr("egs_c_utils.o") );
#endif
task->setTaskName( "Could egs_c_utils be linked to a Fortran file ? " );
task->setLanguage( "Fortran" );
task->setDeleteFlag( true );
ct->setTasks( task );
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
environment.insert("PWD",QDir::currentPath());
ct->copyEnvironment( environment );
ct->launch();
}
void QInstallPage::get_test_c_utils_result(){
if ( ct->successful_test((ushort)0) ) {
egs_c_utils_ok = true;
printProgress( tr("\n Yes, egs_c_utils can be successfully")+
tr(" linked to a Fortran file. \n") );
}
else{
egs_c_utils_ok = false;
printProgress((QString)NO_EGS_UTILS_C);
}
updateProgress();
emit egsCUtilsTested();
}
/****************************
* Guessing link flag for DSO
****************************/
#define LOAD_BEAMLIB_VERSION "#include <dlfcn.h>\n"\
"int main() {\n"\
" void *h, *sym;\n"\
" h = dlopen(\"test.so\",RTLD_LAZY);\n"\
" sym = dlsym(h,\"junk\");\n"\
" return 0;\n"\
"}\n"
void QInstallPage::test_load_beamlib(){
if (!load_beamlib_ok){
dlopen_flags = QString();
printProgress("\n\nTesting load_beamlib skipped due to previous errors...\n");
updateProgress();
emit LoadBeamLibTested();
return;
}
QString test_util( LOAD_BEAMLIB_VERSION );
if ( ! writeQString2File( test_util, (QString)"test_load_beamlib.c" ) ) {
printProgress( (QString)"\n Critical error: could not create file " +
(QString)"test_load_beamlib.c" );
load_beamlib_ok = false;
dlopen_flags = QString();
printProgress(tr("\nCouldn't guess link flag for an DSO object!!!")+
tr("\n ldopen_flag variable will be empty!\n"));
updateProgress();
emit LoadBeamLibTested();
return;
}
#ifdef WIN32
load_beamlib_ok = true;
dlopen_flags = QString();
printProgress(tr("\nAssuming there is no need to pass a flag")+
tr("\nto the compiler for opening a DSO on Windows\n") +
tr("\nusing Win API function LoadLibrary().\n"));
updateProgress();
emit LoadBeamLibTested();
#else
Tasks* task = new Tasks[3];
task[0].setFName( (QString)"test_load_beamlib.c" );
task[0].setTaskName( "Testing flag -ldl ..." );
task[0].setLanguage( "C" );
task[0].setDeleteFlag( false );
task[0].setLibraries("-ldl");
task[1].setFName( (QString)"test_load_beamlib.c" );
task[1].setTaskName( "Testing flag -lc ..." );
task[1].setLanguage( "C" );
task[1].setDeleteFlag( false );
task[1].setLibraries("-lc");
task[2].setFName( (QString)"test_load_beamlib.c" );
task[2].setTaskName( "Testing no flag ..." );
task[2].setLanguage( "C" );
task[2].setDeleteFlag( true );
if ( ct ) ct = 0;
ct = new MTest( screen, 3, config_file );
connect( ct, SIGNAL( taskFinished() ), this, SLOT( updateProgress() ) );
connect( ct, SIGNAL( testsFinished() ), this, SLOT( get_test_load_beamlib()));
connect( ct, SIGNAL( criticalError() ), this, SLOT( get_test_load_beamlib()));
/**********************************************************************/
ct->setTitle( (QString)"\n\nGuessing library needed for dlopen ... " );
ct->setEndStr( QString::null );
ct->setCompilers( fc, cc );
ct->reset();
ct->setTasks( task );
ct->launch();
#endif
}
void QInstallPage::get_test_load_beamlib(){
if ( ct->successful_test((ushort)0) ) {
load_beamlib_ok = true;
dlopen_flags = "-ldl";
}
else if ( ct->successful_test((ushort)1) ) {
load_beamlib_ok = true;
dlopen_flags = "-lc";
}
else if ( ct->successful_test((ushort)2) ) {
load_beamlib_ok = true;
dlopen_flags = QString();
}
else{
load_beamlib_ok = false;
dlopen_flags = QString();
printProgress(tr("\nFailed guessing flag for using dlopen,\n")+
tr("make sure you find the proper flag!!!"));
emit LoadBeamLibTested();
return;
}
printProgress( tr("\n ===> Library for dlopen is ")+ dlopen_flags +
tr(" !!!\n") );
emit LoadBeamLibTested();
}
//**************************************************************
//
// SPECfile <=== configuration file name
// CONFIGname <=== configuration name (taken form guessConfig)
//
//**************************************************************
void QInstallPage::createSystemFiles(){
QString the_name = QFileInfo( QCoreApplication::applicationFilePath() ).fileName();
MTestAnswer &a = ft->getAnswers(); // map relating test name to test result
MTestID id = ft->getIDs(); // map relating test name to task number
printProgress( "\n===> Creating configuration file ...\n\n");
specFile = henHouse() + tr("specs") + QDir::separator() + confFile();
QDate date = QDate::currentDate();
QString today = date.toString ( Qt::TextDate );
QDateTime dateTime = QDateTime::currentDateTimeUtc();
QString config_time = dateTime.toString ( Qt::TextDate ) + " UTC";
QString OS; QString stdfile;
#ifdef WIN32
OS = "Windows";
stdfile = "windows.spec";
#else
OS = "Unix";
stdfile = "unix.spec";
#endif
/*************************************************/
// checking result from egs_c_utils.c compilation
/*************************************************/
QString hasCComp, egs_c_obj = QString();
QString wouldbe_c_util = "$(HEN_HOUSE)lib$(DSEP)$(my_machine)$(DSEP)" +
(QString)"egs_c_utils.o";
QString machine_c_compiler = QString(MACHINE_HAS_C_COMPILER);
if ( egs_c_utils_ok ) {
hasCComp = QString(HAS_C_COMPILER); wouldbe_c_util = QString();
if ( fileExists( egsLibDir + QString("egs_c_utils.o") ) )
egs_c_obj = QString("$(HEN_HOUSE)lib$(DSEP)$(my_machine)$(DSEP)") +
QString("egs_c_utils.o");
else if ( fileExists( egsLibDir + (QString)"egs_c_utils.obj" ) )
egs_c_obj = QString("$(HEN_HOUSE)lib$(DSEP)$(my_machine)$(DSEP)") +
QString("egs_c_utils.obj");
else egs_c_obj = QString();
}
else{
hasCComp = QString(HAS_NO_C_COMPILER); egs_c_obj = QString();
machine_c_compiler = QString(MACHINE_HAS_NO_C_COMPILER);
}
/*************************************************/
// checking result from load_beamlib.c compilation
/*************************************************/
QString beamlib_header(BEAMLIB_OBJECTS_HEADER1),
beamlib_extra_header(BEAMLIB_EXTRA_LIBS_HEADER1),
load_beamlib_obj("$(HEN_HOUSE)lib$(DSEP)$(my_machine)"
"$(DSEP)load_beamlib.o");
QString load_beamlib_macro(HAVE_LOAD_DSO);
if(!load_beamlib_ok){
beamlib_header = QString(BEAMLIB_OBJECTS_HEADER2);
beamlib_extra_header = QString(BEAMLIB_EXTRA_LIBS_HEADER2);
load_beamlib_obj = QString();
load_beamlib_macro = QString(HAVE_NOT_LOAD_DSO);
}
#ifdef WIN32
else if (!fileExists(egsLibDir+(QString)"/load_beamlib.o")&&
fileExists(egsLibDir+(QString)"/load_beamlib.obj")){
load_beamlib_obj = QString("$(HEN_HOUSE)lib$(DSEP)$(my_machine)") +
QString("$(DSEP)load_beamlib.obj");
}
else{
load_beamlib_obj = QString();
}
#endif
/***********************************************************/
// check whether exit and stop failed and add egs_exit to the
// EGS_EXTRA_OBJECTS variable
/***********************************************************/
QString egs_exit;
if (! ft->successful_test( id["exitFun"] ) &&
! ft->successful_test( id["stopFun"] ) &&
ft->successful_test( id["egsExitFun"] ) ){
#ifndef WIN32
egs_exit = QString(" $(HEN_HOUSE)lib$(DSEP)$(my_machine)$(DSEP)") +
QString("egs_exit.o ");
if ( fileExists( "egs_exit.o" ) ){
move_file("egs_exit.o", egsLibDir + QString("egs_exit.o"));
}
else{
egs_exit = QString();
}
#else
egs_exit = (QString)" $(HEN_HOUSE)lib$(DSEP)$(my_machine)$(DSEP)" +
(QString)"egs_exit.obj ";
#endif
}
QString specfile(spec_file);
specfile.replace(QString("$my_name"), the_name );
specfile.replace(QString("$my_version"), QString(MY_VERSION) );
QString the_extra_flag = QString();
QString the_hen = henHouse();
#ifdef WIN32
if ( the_hen.endsWith( QDir::separator() ) )
the_hen.chop(1);
the_hen.append("$(DSEP)");
the_hen.replace( 0, 1, QString(the_hen[0]).toUpper());
//QString the_sep = (QString)" := $(shell echo \\)";
QString the_sep = QString(" := $(subst /,\\,/)");
#else
QString the_sep = QString(" = /");
if ( fc->name().toLower() == "pgf77" || fc->version().contains("PGI") )
the_extra_flag = "-Mnomain";
#endif
specfile.replace(QString("$DSEP"), the_sep ) ;
specfile.replace(QString("$HEN_HOUSE"), the_hen );
specfile.replace(QString("$conf_name"), my_machine() );
specfile.replace(QString("$canonical_system"), canonical() );
specfile.replace(QString("$current_date"), today );
specfile.replace(QString("$make_prog"), make->name() );
specfile.replace(QString("$OS"), OS );
specfile.replace(QString("$std.spec"), stdfile );
specfile.replace(QString("$F77"), fc->name() );
/* ************** IK: changes needed for new config version
required to accommodate Darwin
once I'm at making changes, let's also
try to find libg2c.a and put it in
SHLIB_LIBS
*/
bool is_generic = true;
if( fc->name() == "g77" && cc->name() == "gcc" ) {
if( canonical().contains("darwin") ) {
is_generic = false;
specfile.replace((QString)"$EGS_F77_LINK",(QString)"gcc");
specfile.replace((QString)"$EGS_SHLIB_FLAGS",(QString)"-bundle");
specfile.replace((QString)"$EGS_SHLIB_LIBS",(QString)"-lg2c");
}
else if( canonical().contains("linux") ||
canonical().contains("unix")) {
is_generic = false;
QStringList plist;
plist += "/lib64/";
plist += "/usr/lib64/";
plist += "/usr/local/lib64/";
plist += "/lib/";
plist += "/usr/lib/";
plist += "/usr/local/lib/";
QString shlib_libs = " ";
for ( QStringList::Iterator it=plist.begin(); it!=plist.end();++it) {
QString file = *it + "libg2c.a";
QFileInfo fi(file);
if( fi.exists() ) { shlib_libs = file; break; }
}
specfile.replace((QString)"$EGS_F77_LINK","$(F77)");
specfile.replace((QString)"$EGS_SHLIB_FLAGS",
(QString)"-shared -Wl,-Bsymbolic");
specfile.replace((QString)"$EGS_SHLIB_LIBS",shlib_libs);
}
}
if( is_generic ) {
specfile.replace(QString("$EGS_F77_LINK"),QString("$(F77)"));
specfile.replace(QString("$EGS_SHLIB_FLAGS"),
QString("-shared -Wl,-Bsymbolic"));
specfile.replace(QString("$EGS_SHLIB_LIBS"),QString(" "));
}
#ifdef WIN32
specfile.replace(QString("$EGS_FOBJE"),QString("obj"));
#else
specfile.replace(QString("$EGS_FOBJE"),QString("o"));
#endif
//
// ********************** End of changes needed for Darwin
//
specfile.replace(QString("$FFLAGS"), fc->options() );
specfile.replace(QString("$FOPT"), fc->optimization() );
specfile.replace(QString("$FDEBUG"), fc->debug() );
specfile.replace(QString("$FLIBS"), egs_exit + fc->libraries() );
specfile.replace(QString("$FOUT"), fc->outflag() );
specfile.replace(QString("$FEXTRA"), the_extra_flag );
specfile.replace(QString("$CC"), cc->name() );
specfile.replace((QString)"$C_FLAGS", cc->optimization() + QString(" ") + cc->options() );
specfile.replace((QString)"$COUT", cc->outflag() );
specfile.replace((QString)"$C_COMPILER_AVAILABILITY", hasCComp );
specfile.replace((QString)"$EGS_C_UTILS_OBJ", egs_c_obj );
specfile.replace((QString)"$WOULD_BE_EGS_C_UTIL", wouldbe_c_util );
specfile.replace((QString)"$BEAMLIB_OBJECTS_HEADER",beamlib_header);
specfile.replace((QString)"$BEAMLIB_EXTRA_LIBS_HEADER",beamlib_extra_header);
specfile.replace((QString)"$LOAD_BEAMLIB", load_beamlib_obj );
specfile.replace((QString)"$dlopen_flags", dlopen_flags );
if ( ! writeQString2File( specfile, specFile ) ) {
printProgress( tr("\n Critical error: could not create ")+
tr("configuration file ") + specFile );
QString direrror = QString("\n Could not create configuration file ") +
specFile;
direrror+= QString("\n Check your permissions on this area or");
direrror+= QString("\n consult your system/EGSnrc administrator!");
QMessageBox::critical(this,"ERROR", direrror,"&OK",0,0,0,-1);
return;
}
printProgress( "\n===> Creating machine.macros ...\n\n");
QString comp_def = fc->name();
QString sep;
QString copy;
QString move;
QString remove_dir;
#ifdef WIN32
comp_def.remove(".exe");
sep = "char(92)";
copy = "copy ";
move = "move /Y ";
remove_dir = "rmdir /S /Q ";
the_hen.replace("$(DSEP)","/");
#else
sep = "'/'";
copy = "cp ";
move = "mv -f ";
remove_dir = "rm -rf ";
#endif
QString no_rec_len = "\" Record Length for unformatted I/O \"\n";
QString flush_func = (QString)HAS_FLUSH_FUN;
QString the_exit = QString(HAS_EXIT);
QString the_longest_int ="\"$MAX_INT SET TO 2^63-1 in egsnrc.macros\"";
if ( ! ft->successful_test( id["LongInteger"] ) ){
a["LongInteger"] = "integer*4";
the_longest_int = "REPLACE {$MAX_INT} WITH {2147483647};\"2^31-1\"";
}
if ( ! ft->successful_test( id["ShortInteger"] ) )
a["ShortInteger"] = "integer*4";
if ( ! ft->successful_test( id["flushFun"] ) ){
flush_func = (QString)HAS_NO_FLUSH_FUN;
a["flushFun"] = ";";
}
if ( ! ft->successful_test( id["recLen"] ) ){
a["recLen"] = "fixme!";
no_rec_len = (QString)UNKNOWN_REC_LEN;
}
if ( ! ft->successful_test( id["exitFun"] ) ){
if ( ft->successful_test( id["stopFun"] ) )
the_exit =(QString)HAS_STOP;
else
the_exit =(QString)USE_EGS_EXIT;
}
if (a["Endianess"] == "little endian"){
a["Endianess"] = "1234";
}
else if (a["Endianess"] == "big endian"){
a["Endianess"] = "4321";
}
else if (a["Endianess"] == "pdp endian"){
a["Endianess"] = "3412";
}
else{// Unknown endianess
a["Endianess"] = "xxxx";
}
QString configfile = specFile;
QString Machine_Macros = egsLibDir + QString("machine.macros");
QString machinemacros(machine_macros);
machinemacros.replace(QString("$my_name"), the_name );
machinemacros.replace(QString("$my_version"), QString(MY_VERSION) );
machinemacros.replace(QString("$current_date"),today );
machinemacros.replace(QString("$the_config"),my_machine() );
machinemacros.replace(QString("$$HEN_HOUSE"),the_hen.replace("\\","/") );
machinemacros.replace(QString("$spec_file"), configfile.replace("\\","/") );
machinemacros.replace(QString("$canonical_system"), canonical() );
machinemacros.replace(QString("$conf_name"), my_machine() );
machinemacros.replace(QString("$config_time"), config_time );
machinemacros.replace(QString("$sep"), sep );
machinemacros.replace(QString("$copyf"), copy );
machinemacros.replace(QString("$movef"), move );
machinemacros.replace(QString("$rmdir"), remove_dir );
machinemacros.replace(QString("LongInteger"), a["LongInteger"] );
machinemacros.replace(QString("ShortInteger"), a["ShortInteger"] );
machinemacros.replace(QString("THE_LONGEST_INT"), the_longest_int);
machinemacros.replace(QString("Endianess"), a["Endianess"] );
machinemacros.replace(QString("$NO_REC_LEN"), no_rec_len );
machinemacros.replace(QString("recLen"), a["recLen"] );
machinemacros.replace(QString("$FLUSH_FUN"), flush_func );
machinemacros.replace(QString("flushFun"), a["flushFun"] );
machinemacros.replace(QString("$EXIT_FUN"),the_exit );
machinemacros.replace(QString("exitFun"), a["exitFun"] ); // Only one of the three keys below
machinemacros.replace(QString("stopFun"), a["stopFun"] ); // will get replaced depending on
machinemacros.replace(QString("egsExitFun"), a["egsExitFun"] );
machinemacros.replace(QString("$MACHINE_C_COMPILER"), machine_c_compiler );
machinemacros.replace(QString("$MACHINE_HAVE_LOAD_DSO"), load_beamlib_macro );
if ( ! writeQString2File( machinemacros, Machine_Macros ) ) {
printProgress( tr("\n Critical error: could not create system file ")
+ Machine_Macros );
return;
}
printProgress( (QString)"\n *** System file " + Machine_Macros +
(QString)" successfully created ***\n\n");
printProgress( "\n===> Creating machine.f ...\n\n");
QString Machine_F = egsLibDir + QString("machine.f");
QString machinef(machine_f);
machinef.replace(QString("$my_name"), the_name );
machinef.replace(QString("$my_version"), QString(MY_VERSION) );
QString fun_chunk;
if ( ft->successful_test( id["SystemFun"] ) ){
fun_chunk = readFile2QString( henHouse() +
QString("pieces/egs_system_v1.f"),
QString("Error copying egs_system_v1.f)") );
}
else if( ft->successful_test( id["SystemSub"] ) ){
fun_chunk = readFile2QString( henHouse() +
QString("pieces/egs_system_v2.f"),
QString("Error copying egs_system_v2.f") );
}
else{
fun_chunk = readFile2QString( henHouse() +
QString("pieces/egs_system_v3.f"),
QString("Error copying egs_system_v3.f") );
}
machinef.append( fun_chunk );
if ( ft->successful_test( id["lstatFun"] ) ){
fun_chunk = readFile2QString( henHouse() + QString("pieces/egs_isdir_v1.f"),
QString("Error copying egs_isdir_v1.f") );
QString s = a[ "lstatFun" ], direle=s, arraysize=s;
direle.chop(direle.length() - direle.indexOf(":"));
arraysize.remove(0,arraysize.indexOf(":")+1);
fun_chunk.replace( "___dir_element___", direle );
fun_chunk.replace( "___array_size___", arraysize );
}
else if ( ft->successful_test( id["InquireFun"] ) ){
fun_chunk = readFile2QString( henHouse() + QString("pieces/egs_isdir_v2.f"),
QString("Error copying egs_isdir_v2.f") );
}
else{
fun_chunk = readFile2QString( henHouse() + QString("pieces/egs_isdir_v3.f"),
QString("Error copying egs_isdir_v3.f") );
}
machinef.append( fun_chunk );
if ( ft->successful_test( id["fdateFun"] ) ){
fun_chunk = readFile2QString( henHouse() + QString("pieces/egs_fdate_v1.f"),
QString("Error copying egs_fdate_v1.f") );
fun_chunk.replace( "__fdate__", a[ "fdateFun" ] );
}
else if( ft->successful_test( id["DateAndTime"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_fdate_v2.f",
(QString)"Error copying egs_fdate_v2.f" );
}
else{
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_fdate_v3.f",
(QString)"Error copying egs_fdate_v3.f" );
}
machinef.append( fun_chunk );
if ( ft->successful_test( id["DateAndTime"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_date_and_time_v1.f",
(QString)"Error copying egs_date_and_time_v1.f" );
}
else if( ft->successful_test( id[ "fdateFun" ] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_date_and_time_v2.f",
(QString)"Error copying egs_date_and_time_v1.f" );
fun_chunk.replace( "__fdate__", a[ "fdateFun" ] );
}
else{
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_date_and_time_stub.f",
(QString)"Error copying egs_date_and_time_stub.f" );
}
machinef.append( fun_chunk );
if ( ft->successful_test( id["fdateFun"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_date_v1.f",
(QString)"Error copying egs_date_v1.f" );
fun_chunk.replace( "__fdate__", a[ "fdateFun" ] );
}
else if( ft->successful_test( id["DateAndTime"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_date_v2.f",
(QString)"Error copying egs_date_v2.f" );
}
else if( ft->successful_test( id["dateFun"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_date_v3.f",
(QString)"Error copying egs_date_v3.f" );
fun_chunk.replace( "__date__", a[ "dateFun" ] );
}
else{
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_date_stub.f",
(QString)"Error copying egs_date_stub.f" );
}
machinef.append( fun_chunk );
if ( ft->successful_test( id["fdateFun"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_time_v1.f",
(QString)"Error copying egs_time_v1.f" );
fun_chunk.replace( "__fdate__", a[ "fdateFun" ] );
}
else if( ft->successful_test( id["DateAndTime"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_time_v2.f",
(QString)"Error copying egs_time_v2.f" );
}
else if( ft->successful_test( id["timeFun"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_time_v3.f",
(QString)"Error copying egs_time_v3.f" );
fun_chunk.replace( "__time__", a[ "timeFun" ] );
}
else{
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_date_stub.f",
(QString)"Error copying egs_date_stub.f" );
}
machinef.append( fun_chunk );
if ( ft->successful_test( id["DateAndTime"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_secnds_v1.f",
(QString)"Error copying egs_secnds_v1.f" );
}
else if( ft->successful_test( id[ "fdateFun" ] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_secnds_v2.f",
(QString)"Error copying egs_secnds_v2.f" );
fun_chunk.replace( "__fdate__", a[ "fdateFun" ] );
}
else if( ft->successful_test( id[ "secsFun" ] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_secnds_v3.f",
(QString)"Error copying egs_secnds_v3.f" );
fun_chunk.replace( "__secnds__", a[ "secsFun" ] );
}
else if( ft->successful_test( id[ "timeFun" ] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_secnds_v4.f",
(QString)"Error copying egs_secnds_v4.f" );
fun_chunk.replace( "__time__", a[ "timeFun" ] );
}
else{
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_secnds_stub.f",
(QString)"Error copying egs_secnds_stub.f" );
}
machinef.append( fun_chunk );
if ( ft->successful_test( id["DateAndTime"] ) ||
ft->successful_test( id[ "fdateFun" ] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/time_stuff.f",
(QString)"Error copying time_stuff.f" );
}
machinef.append( fun_chunk );
if ( ft->successful_test( id["etimeFun"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_etime.f",
(QString)"Error copying egs_etime.f" );
fun_chunk.replace( "__etime__", a[ "etimeFun" ] );
}
else{
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_etime_stub.f",
(QString)"Error copying egs_etime_stub.f" );
}
machinef.append( fun_chunk );
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_canonical_system.f",
(QString)"Error copying egs_canonical_system.f" );
fun_chunk.replace( "__canonical_system__", canonical() );
machinef.append( fun_chunk );
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_configuration_name.f",
(QString)"Error copying egs_configuration_name.f" );
fun_chunk.replace( "__configuration_name__", my_machine() );
machinef.append( fun_chunk );
if ( ft->successful_test( id["hostFun"] ) ){
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_hostnm_v1.f",
(QString)"Error copying egs_hostnm_v1.f" );
fun_chunk.replace( "__hostnm__", a[ "hostFun" ] );
}
else{
fun_chunk = readFile2QString( henHouse() +
(QString)"pieces/egs_hostnm_v2.f",
(QString)"Error copying egs_hostnm_v1.f" );
}
machinef.append( fun_chunk );
if ( ! ft->successful_test( id["LnblnkFun"] ) ){
machinef.append( (QString)LNBLNK );
}
if ( ! writeQString2File( machinef, Machine_F ) ) {
printProgress( tr("\n Critical error: could not create system file ") +
Machine_F );
return;
}
/*----------------------------------------------------------------------------
MACHINE.MORTRAN
machine.mortran is what will get used in mortran compilations
We generate it just as a wrapper around machine.f
-----------------------------------------------------------------------------*/
printProgress( "\n===> Creating machine.mortran ...\n\n");
QString Machine_M = egsLibDir + QString("machine.mortran");
QString machinem("%F\n");
fun_chunk = readFile2QString( Machine_F, QString("Error reading ") +
Machine_F );
machinem.append( fun_chunk );
machinem.append( "%M\n" );
if ( ! writeQString2File( machinem, Machine_M ) ) {
printProgress( tr("\n Critical error: could not create system file ")+
Machine_M +