-
Notifications
You must be signed in to change notification settings - Fork 51
/
xc.c
1968 lines (1719 loc) · 46.5 KB
/
xc.c
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
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
*/
#include <stdio.h>
#include <ctype.h>
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
#include "xpp.h"
#include "../bootProto.h"
#define NOKNET
#define import_kernel
#define import_knames
#include <iraf.h>
#if defined(LINUX) || defined(BSD)
# ifdef SOLARIS
# undef SOLARIS
# endif
#endif
/*
* XC -- Main entry point of the XC compiler front-end used by the IRAF
* system.
*/
#define VERSION "IRAFNET XC V2.4 Jan 21 2010"
#define ERR (-1)
#define EOS '\0'
#define YES 1
#define NO 0
#define MAXFLAG 64 /* maximum option flags */
#define MAXFILE 1024 /* maximum files on cmdline */
#define SZ_CMDBUF 4096 /* maximum command buffer */
#define SZ_BUFFER 4096 /* library names, flags */
#define SZ_LIBBUF 4096 /* full library names */
#define SZ_FNAME 255
#define SZ_PATHNAME 511
#define SZ_PKGENV 256
#define DEF_PKGENV "iraf"
#ifdef MACOSX
#define CCOMP "cc" /* C compiler (also .s etc.) */
#define LINKER "cc" /* Linking utility */
#else
#define CCOMP "gcc" /* C compiler (also .s etc.) */
#define LINKER "gcc" /* Linking utility */
#endif
#define F77COMP "f77" /* Fortran compiler */
#define DEBUGFLAG 'g' /* host flag for -x */
#define USEF2C 1 /* use Fortran to C trans. */
#define LIBCINCLUDES "hlib$libc/" /* IRAF LIBC include dir */
#define LOCALBINDIR "/usr/local/bin/" /* standard local BIN */
#define SYSBINDIR "/usr/bin/" /* special system BIN */
#define XPP "xpp.e"
#define RPP "rpp.e"
#define EDSYM "edsym.e"
#define SHIMAGE "S.e"
#define LIBMAIN "libmain.o"
#define SHARELIB "libshare.a"
#define IRAFLIB1 "libex.a"
#define IRAFLIB2 "libsys.a"
#define IRAFLIB3 "libvops.a"
#define IRAFLIB4 "libos.a"
#define IRAFLIB5 "libVO.a"
#define IRAFLIB6 "libcfitsio.a"
#ifdef LINUX
char *fortlib[] = { "-lf2c", /* 0 (host progs) */
"-lf2c", /* 1 */
"-lm", /* 2 */
#ifndef LINUXPPC
#ifndef LINUX64
"", /* 3 -lcompat */
#endif
#else
"-lg2c", /* 3 */
#endif
"-lpthread", /* 4 */
"-lm", /* 5 */
"-lrt", /* 6 */
"-lcurl", /* 7 */
"-lexpat", /* 8 */
"", /* 9 */
0}; /* EOF */
char *opt_flags[] = { "-O", /* 0 */
0}; /* EOF */
int nopt_flags = 1; /* No. optimizer flags */
#else
#ifdef BSD
char *fortlib[] = { "-lf2c", /* 0 (host progs) */
"-lf2c", /* 1 */
"-lm", /* 2 */
"-lcompat", /* 3 */
"-lcurl", /* 4 */
"-lexpat", /* 5 */
"", /* 6 */
"", /* 7 */
"", /* 8 */
"", /* 9 */
0}; /* EOF */
char *opt_flags[] = { "-O", /* 0 */
0}; /* EOF */
int nopt_flags = 1; /* No. optimizer flags */
#else
#ifdef MACOSX
char *fortlib[] = { "-lf2c", /* 0 (host progs) */
"-lf2c", /* 1 */
"-lm", /* 2 */
"-lcurl", /* 3 */
"-lexpat", /* 4 */
"", /* 5 */
"", /* 6 */
"", /* 7 */
"", /* 8 */
"", /* 9 */
0}; /* EOF */
char *opt_flags[] = { "-O3", /* 0 */
0}; /* EOF */
/* As of Dec2007 there remains an unexplained optimizer bug in
** the system which has the effect of disabling FPE handling on
** Mac Intel/PPC systems. For the moment, we'll disable the optimization
** until this is better understood or fixed in future GCC versions.
*/
int nopt_flags = 0; /* No. optimizer flags */
#else
#ifdef SOLARIS
char *fortlib[] = { "-lf2c", /* 0 (host progs) */
"-lf2c", /* 1 */
"-lm", /* 2 */
"-lsocket", /* 3 */
"-lnsl", /* 4 */
"-lintl", /* 5 */
"-ldl", /* 6 */
"-lelf", /* 7 */
"-lcurl", /* 8 */
"-lexpat", /* 9 */
0}; /* EOF */
char *opt_flags[] = { "-O", /* 0 */
0}; /* EOF */
int nopt_flags = 1; /* No. optimizer flags */
#else
#ifdef CYGWIN
char *fortlib[] = { "-lf2c", /* 0 (host progs) */
"-lf2c", /* 1 */
"-lm", /* 2 */
"-lcompat", /* 3 */
"-lcurl", /* 4 */
"-lexpat", /* 5 */
"", /* 6 */
"", /* 7 */
"", /* 8 */
"", /* 9 */
0}; /* EOF */
char *opt_flags[] = { "-O", /* 0 */
0}; /* EOF */
int nopt_flags = 1; /* No. optimizer flags */
#else
char *fortlib[] = { "-lU77", /* 0 (host progs) */
"-lm", /* 1 */
"-lF77", /* 2 */
"-lI77", /* 3 */
"-lm", /* 4 */
"-lcurl", /* 5 */
"-lexpat", /* 6 */
"", /* 7 */
"", /* 8 */
"", /* 9 */
0}; /* EOF */
char *opt_flags[] = { "-O", /* 0 */
0}; /* EOF */
int nopt_flags = 1; /* No. optimizer flags */
#endif
#endif
#endif
#endif
#endif
#ifdef BSD
#define F_STATIC "-static"
#define F_SHARED "-shared"
#else
#ifdef MACOSX
#define F_STATIC "-static"
#define F_SHARED "-shared"
#else
#ifdef LINUX
#define F_STATIC "-Wl,-Bstatic"
#define F_SHARED "-Wl,-Bdynamic"
#else
#ifdef SOLARIS
#define F_STATIC "-Wl,-Bstatic"
#define F_SHARED "-Wl,-Bdynamic"
#endif
#endif
#endif
#endif
#define isxfile(str) (getextn(str) == 'x')
#define isffile(str) (getextn(str) == 'f')
#define iscfile(str) (getextn(str) == 'c')
#define issfile(str) (getextn(str) == 's')
#define isefile(str) (getextn(str) == 'e')
#define isafile(str) (getextn(str) == 'a')
#define isofile(str) (getextn(str) == 'o')
#define ispfile(str) (getextn(str) == 'P') /* func prototypes */
#ifdef SOLARIS
#ifdef X86
int usesharelib = NO;
int noedsym = YES;
#else
int usesharelib = YES;
int noedsym = NO;
#endif
#else
#ifdef SHLIB
int usesharelib = YES;
int noedsym = NO;
#else
int usesharelib = NO;
int noedsym = YES;
#endif
#endif
int stripexe = NO;
int notvsym = NO;
int noshsym = NO;
int errflag = NO;
int objflags = NO;
int keepfort = NO;
int mkobject = YES;
int mktask = YES;
int optimize = YES;
int cflagseen = NO;
int nfileargs = 0;
int link_static = NO;
int link_nfs = NO;
int debug = NO;
int dbgout = NO;
int hostprog = NO;
int voslibs = YES;
int nolibc = NO;
int usef2c = YES;
int useg95 = NO;
int userincs = NO;
#ifdef LINUXPPC
int useg2c = YES;
#else
int useg2c = NO;
#endif
int host_c_main = NO;
char ccomp[SZ_FNAME] = CCOMP;
char f77comp[SZ_FNAME] = F77COMP;
char linker[SZ_FNAME] = LINKER;
char f2cpath[SZ_FNAME] = "/usr/bin/f2c";
char g77path[SZ_FNAME] = "/usr/bin/g77";
char outfile[SZ_FNAME] = "";
char tempfile[SZ_FNAME] = "";
char *lflags[MAXFLAG+1];
char *lfiles[MAXFILE+1]; /* all files */
char *hlibs[MAXFILE+1]; /* host libraries */
char *lxfiles[MAXFILE+1]; /* .x files */
char *lffiles[MAXFILE+1]; /* .f files */
char buffer[SZ_BUFFER+1];
char libbuf[SZ_LIBBUF+1];
char *bp = buffer;
char *libp = libbuf;
char *pkgenv = NULL;
char *pkglibs = NULL;
char v_pkgenv[SZ_PKGENV+1];
int nflags, nfiles, nhlibs, nxfiles, nffiles;
long sig_int, sig_quit, sig_hup, sig_term;
char *shellname = "/bin/sh";
int foreigndefs = NO;
char *foreign_defsfile = "";
char *irafarch = ""; /* IRAFARCH string */
char floatoption[32] = ""; /* f77 arch flag, if any */
int pid;
/**
* External procedure declarations.
*/
extern void ZZSTRT (void);
extern void ZZSTOP (void);
/**
* Local procedure declarations.
*/
static char *mkfname (char *i_fname);
static int addflags (char *flag, char *arglist[], int *p_nargs);
static char *iraflib (char *libref);
static void printargs (char *cmd, char *arglist[], int nargs);
static void xtof (char *file);
static int getextn (char *fname);
static void chdot (char *fname, char dotchar);
static int run (char *task, char *argv[]);
static int sys (char *cmd);
static void done (int k);
static void enbint (SIGFUNC handler);
static void interrupt (void);
static int await (int waitpid);
static void rmfiles (void);
static void fatalstr (char *s1, char *s2);
static void fatal (char *s);
static int isv13 (void);
static char *findexe (char *prog, char *dir);
/**
* MAIN -- Execution begins here. Interpret command line arguments and
* pass commands to UNIX to execute the various passes, i.e.:
*
* xpp SPP to modified-ratfor
* rpp modified-ratfor to Fortran
* f77 UNIX fortran compiler
* cc compile other sources, link if desired
*
* The Fortran source is left behind if the -F flag is given. The IRAF root
* directory must either be given on the command line as "-r pathname" or in
* the environment as the variable "irafdir".
*/
int
main (int argc, char *argv[])
{
int i, j, nargs, ncomp;
char *arglist[MAXFILE+MAXFLAG+10];
char *arg, *ip, *s;
int status, noperands;
/* Initialization. */
ZZSTRT();
isv13();
#if defined(LINUX) || defined(BSD) || defined(X86) || defined(MACOSX)
if (os_sysfile ("f77.sh", f77comp, SZ_FNAME) < 0) {
strcpy (f77comp, "f77");
usef2c = 0;
} else
usef2c = 1;
if (os_sysfile ("f2c.e", tempfile, SZ_FNAME) > 0)
strcpy (f2cpath, tempfile);
#else
strcpy (f77comp, "f77");
#endif
nflags = nfiles = nhlibs = nxfiles = nffiles = 0;
sig_int = (long) signal (SIGINT, SIG_IGN) & 01;
sig_quit = (long) signal (SIGQUIT, SIG_IGN) & 01;
sig_hup = (long) signal (SIGHUP, SIG_IGN) & 01;
sig_term = (long) signal (SIGTERM, SIG_IGN) & 01;
enbint ((SIGFUNC)interrupt);
pid = getpid();
/* Load any XC related environment definitions.
*/
if ((s = os_getenv ("XC-CC")) || (s = os_getenv ("XC_CC")))
strcpy (ccomp, s);
if ((s = os_getenv ("XC-F77")) || (s = os_getenv ("XC_F77"))) {
strcpy (f77comp, s);
usef2c = (strncmp (f77comp, "f77", 3) == 0 ? 1 : 0);
useg95 = (strncmp (f77comp, "g95", 3) == 0 ? 1 : 0);
}
if ((s = os_getenv ("XC-LINKER")) || (s = os_getenv ("XC_LINKER")))
strcpy (linker, s);
/* Always load the default IRAF package environment. */
loadpkgenv (DEF_PKGENV);
/* Count the number of file arguments. Load the environment for
* any packages named on the command line.
*/
pkgenv = NULL;
v_pkgenv[0] = EOS;
for (i=1, nfileargs=0; argv[i] != NULL; i++)
if (argv[i][0] != '-')
nfileargs++;
else if (strcmp (argv[i], "-p") == 0 && argv[i+1]) {
loadpkgenv (argv[++i]);
strcat (v_pkgenv, v_pkgenv[0] ? " -p " : "-p ");
strcat (v_pkgenv, argv[i]);
pkgenv = v_pkgenv;
}
/* If no package environment was specified see if the user has
* specified a default package in their user environment.
*/
if (!pkgenv) {
char *s, u_pkgenv[SZ_PKGENV+1];
char *pkgname, *ip;
if ((s = os_getenv ("PKGENV"))) {
strcpy (ip = u_pkgenv, s);
while (*ip) {
while (isspace(*ip))
ip++;
pkgname = ip;
while (*ip && !isspace(*ip))
ip++;
if (*ip)
*ip++ = EOS;
if (pkgname[0]) {
loadpkgenv (pkgname);
strcat (v_pkgenv, v_pkgenv[0] ? " -p " : "-p ");
strcat (v_pkgenv, pkgname);
pkgenv = v_pkgenv;
}
}
}
}
/* Process command line options, make file lists.
* Convert ".x" files to ".f".
*/
for (i=1; (arg = argv[i]) != NULL; i++) {
if (arg[0] == '-') {
switch (arg[1]) {
case '/':
/* Pass flag on without further interpretation.
* "-/foo" -> "-foo"
* "-//foo" -> "foo"
*/
lflags[nflags] = bp;
ip = &arg[2];
if (*ip == '/')
ip++;
else
*bp++ = '-';
while ((*bp++ = *ip++))
;
if (nflags++ >= MAXFLAG)
fatal ("Too many compiler options");
break;
case 'D':
/* Pass a -D<define> flag on to the host compiler.
*/
lflags[nflags] = bp;
for (ip = &arg[0]; (*bp++ = *ip++); )
;
if (bp - buffer >= SZ_BUFFER)
fatal ("Out of buffer space for options");
if (nflags++ >= MAXFLAG)
fatal ("Too many compiler options");
break;
case 'I':
/* Pass a -I<include-dir> flag on to the host compiler.
* A special case is "-Inolibc" which disables automatic
* inclusion of the IRAF LIBC includes (hlib$libc).
*/
if (strcmp (&arg[2], "nolibc") == 0)
nolibc++;
else {
lflags[nflags] = bp;
*bp++ = arg[0];
*bp++ = arg[1];
strcpy (bp, vfn2osfn (&arg[2], 0));
bp += strlen (bp) + 1;
if (bp - buffer >= SZ_BUFFER)
fatal ("Out of buffer space for options");
if (nflags++ >= MAXFLAG)
fatal ("Too many compiler options");
}
break;
case 'l':
case 'L':
/* Library file (-llib) or library directory (-Ldir)
* reference.
*/
if ((lfiles[nfiles] = iraflib (arg)) == NULL) {
hlibs[nhlibs] = arg;
nhlibs++;
} else
nfiles++;
if (nfiles > MAXFILE || nhlibs > MAXFILE)
fatal ("Too many files");
objflags = YES;
mkobject = YES;
mktask = YES;
break;
case 'o':
/* Set output file name.
*/
if ((arg = argv[++i]) == NULL)
i--;
else
strcpy (outfile, arg);
mkobject = YES;
mktask = YES;
objflags = YES;
break;
case 'p':
/* Ignore since the -p args were already processed above.
*/
i++;
break;
case 'r':
/* Not used anymore */
if ((arg = argv[++i]) == EOS)
i--;
break;
case 'h':
/* Host program: do not link in IRAF main or search
* standard IRAF libraries unless explicitly referenced
* on command line.
*/
voslibs = 0;
/* fall through */
case 'H':
/* Link a host program, but include the VOS libraries.
*/
hostprog++;
noedsym++;
nolibc++;
break;
case 'G':
/* Force a program to link w/ libg2c.a instead of libf2c.a
*/
useg2c++;
break;
case 'A':
/* Force arch-specific include files.
*/
userincs++;
break;
case 'C':
/* Link a host program which has a C main. We may need
* to tweak the command line as a special case here since
* we normally assume Fortran sources. This is currently
* only needed for host C programs under LinuxPPC.
*/
host_c_main++;
break;
case 'V':
/* Print XC version identification.
*/
fprintf (stderr, "%s\n", VERSION);
fflush (stderr);
break;
default:
if (strcmp (&arg[1], "Nh") == 0) {
if ((arg = argv[++i]) == EOS)
i--;
else {
foreigndefs++;
foreign_defsfile = arg;
continue;
}
}
lflags[nflags] = bp;
*bp++ = '-';
/* Process list of flags without arguments, e.g. "-xyz"
* which is the same as "-x -y -z".
*/
for (ip = &arg[1]; *ip != EOS; ip++)
if (*ip == 'c') {
mkobject = YES;
mktask = NO;
objflags = YES;
cflagseen = YES;
} else if (*ip == 'd') {
debug++;
} else if (*ip == 'q') {
optimize = NO;
} else if (*ip == 'O') {
optimize = YES;
} else if (*ip == 'F' || *ip == 'f') {
keepfort = YES;
if (objflags == NO) {
mkobject = NO;
mktask = NO;
}
} else if (*ip == 'x') {
dbgout++;
optimize = NO;
*bp++ = DEBUGFLAG;
if (bp - buffer >= SZ_BUFFER)
fatal ("Out of buffer space for options");
} else if (*ip == 'z') {
usesharelib = NO;
} else if (*ip == 'e') {
noedsym = YES;
} else if (*ip == 't') {
notvsym = YES;
} else if (*ip == 'T') {
noshsym = YES;
} else if (*ip == 's') {
stripexe = YES;
goto passflag;
} else if (*ip == 'N') {
/* "NFS" link option. Generate the output temp
* file in /tmp during the link, then move it to
* the output directory in one operation when done.
* For cases such as linking in an NFS-mounted
* directory, where all the NFS i/o may slow the
* link down excessively.
*/
link_nfs = YES;
} else {
passflag: mkobject = YES;
if (!cflagseen)
mktask = YES;
*bp++ = *ip;
if (bp - buffer >= SZ_BUFFER)
fatal ("Out of buffer space for options");
}
if (bp - lflags[nflags] <= 1) {
lflags[nflags] = NULL;
bp--;
} else {
*bp++ = EOS;
if (nflags++ >= MAXFLAG)
fatal ("Too many compiler options");
}
}
} else {
char *ip, *op, *last_dot;
/* Get default name for output executable file, if not given
* as arg. The default extension is ".e".
*/
if (outfile[0] == EOS) {
last_dot = NULL;
for (ip=arg, op=outfile; (*op = *ip++) != EOS; op++)
if (*op == '.')
last_dot = op;
if (last_dot != NULL)
*last_dot = EOS;
strcat (outfile, ".e");
}
/* Munge filename if file is a library. */
if (isafile(arg) && (s = iraflib(arg)))
arg = s;
if (access (arg,0) == -1) {
fprintf (stderr, "Warning: file `%s' not found\n", arg);
fflush (stderr);
} else {
lfiles[nfiles++] = arg;
if (nfiles > MAXFILE)
fatal ("Too many files");
if (isxfile (arg)) {
xtof (arg);
if (errflag & (XPP_BADXFILE | XPP_COMPERR)) {
nfiles--;
errflag &= ~(XPP_BADXFILE | XPP_COMPERR);
}
} else if (isffile (arg)) {
lffiles[nffiles++] = arg;
if (nffiles > MAXFILE)
fatal ("too many files");
} else if (isefile (arg))
fatal ("no .e files permitted in file list");
}
}
}
if (!mkobject) {
if (debug) {
fprintf (stderr, "quit, fortran only\n");
fflush (stderr);
}
ZZSTOP();
exit (errflag);
}
/* Add -I<include-dir> to lflags for each directory in the pkglibs
* package library list. pkglibs is a comma delimited list of VFN
* directory names formed by loading the core system and layered
* package environments.
*/
if ((pkglibs = os_getenv ("pkglibs"))) {
char *ip, *op, *vp, fname[SZ_FNAME];
for (ip=pkglibs; *ip; ) {
while (*ip && (isspace(*ip) || *ip == ','))
ip++;
for (op=fname; *ip && !(isspace (*ip) || *ip == ','); )
*op++ = *ip++;
*op++ = EOS;
if (*fname == EOS)
break;
/* Omit the LIBC includes if -Inolibc was specified. */
if (! (nolibc && strcmp (fname, LIBCINCLUDES) == 0)) {
lflags[nflags] = bp;
*bp++ = '-';
*bp++ = 'I';
for (vp=vfn2osfn(fname,0); (*bp++ = *vp++); )
;
if (*(bp-2) == '/') {
--bp;
*(bp-1) = EOS;
}
if (bp - buffer >= SZ_BUFFER)
fatal ("Out of buffer space for options");
if (nflags++ >= MAXFLAG)
fatal ("Too many compiler options");
}
while (*ip && (isspace(*ip) || *ip == ','))
ip++;
}
}
/* Now check for any alternative compiler definitions or commandline
* flags which will affect out link line. Some systems like LinuxPPC
* will require use of -lg2c even though we can continue to use the
* hlib$f77.sh the fortran compiler script on that system.
*/
if (useg2c || strncmp (f77comp, "g77", 3) == 0) {
fortlib[0] = fortlib[1] = "-lg2c";
}
#ifdef sun
/* Determine if any special architecture dependent compilation flags
* are needed. For the Sun V1.3 compiler, since FLOAT_OPTION is no
* longer supported, we look for IRAFARCH and generate the -f68881
* or -ffpa compiler switches automatically if we are compiling on a
* Sun-3 and no -/f* has already been specified on the command line.
*/
if (!floatoption[0] && (irafarch = os_getenv("IRAFARCH")))
if (irafarch[0] == 'f')
sprintf (floatoption, "-%s", irafarch);
#endif
/* Compile all F77 source files with F77 to produce object code.
* This compilation is separate from that used for the '.x' files,
* because we do not want to use the UNIX "-u" flag (requires that
* everything be declared) for raw Fortran files.
*/
nargs = 0;
arglist[nargs++] = f77comp;
arglist[nargs++] = "-c";
if (usef2c == YES) {
arglist[nargs++] = "-f2c";
arglist[nargs++] = f2cpath;
}
#ifdef MACOSX
if (useg95 == 0) {
if ((irafarch = os_getenv("IRAFARCH"))) {
if (strcmp (irafarch, "macosx") == 0) {
/*
arglist[nargs++] = "-arch";
arglist[nargs++] = "ppc";
*/
arglist[nargs++] = "-arch";
arglist[nargs++] = "i386";
arglist[nargs++] = "-m32";
arglist[nargs++] = "-mmacosx-version-min=10.4";
} else if (strcmp (irafarch, "macintel") == 0) {
arglist[nargs++] = "-arch";
arglist[nargs++] = "x86_64";
arglist[nargs++] = "-m64";
}
}
}
#endif
#if (defined(LINUX) && !defined(MACH64))
arglist[nargs++] = "-m32";
#endif
#if (defined(BSD))
arglist[nargs++] = "-m32";
#endif
#ifdef LINUXAOUT
arglist[nargs++] = "-b";
arglist[nargs++] = "i486-linuxaout";
#endif
#ifdef sun
if (floatoption[0])
arglist[nargs++] = floatoption;
#endif
if (optimize) {
for (i=0; i < nopt_flags; i++)
arglist[nargs++] = opt_flags[i];
}
/* Add the user-defined flags last so they can override the
* hardwired options.
*/
if ((s = os_getenv("XC-FFLAGS")) || (s = os_getenv("XC_FFLAGS")))
addflags (s, arglist, &nargs);
for (i=0; i < nflags; i++)
arglist[nargs++] = lflags[i];
for (i=0; i < nffiles; i++)
arglist[nargs++] = lffiles[i];
arglist[nargs] = NULL;
if (i > 0) {
if (debug)
printargs (f77comp, arglist, nargs);
status = run (f77comp, arglist);
#ifdef LINUX
/* This kludge is to work around a bug in the F2C based F77 script
* on Linux, which returns an exit status of 4 when successfully
* compiling a Fortran file.
*/
if (status == 4)
status = 0;
#endif
errflag += status;
}
/* Compile the remaining Fortran source files with F77 to produce
* object code.
*/
nargs = 0;
arglist[nargs++] = f77comp;
arglist[nargs++] = "-c";
arglist[nargs++] = "-u";
arglist[nargs++] = "-x";
if (usef2c == YES) {
arglist[nargs++] = "-f2c";
arglist[nargs++] = f2cpath;
}
#ifdef MACOSX
if (useg95 == 0) {
if ((irafarch = os_getenv("IRAFARCH"))) {
if (strcmp (irafarch, "macosx") == 0) {
/*
arglist[nargs++] = "-arch";
arglist[nargs++] = "ppc";
*/
arglist[nargs++] = "-arch";
arglist[nargs++] = "i386";
arglist[nargs++] = "-m32";
arglist[nargs++] = "-mmacosx-version-min=10.4";
} else if (strcmp (irafarch, "macintel") == 0) {
arglist[nargs++] = "-arch";
arglist[nargs++] = "x86_64";
arglist[nargs++] = "-m64";
}
}
}
#endif
#if (defined(LINUX) && !defined(MACH64))
arglist[nargs++] = "-m32";
#endif
#if (defined(BSD))
arglist[nargs++] = "-m32";
#endif
#ifdef LINUXAOUT
arglist[nargs++] = "-b";
arglist[nargs++] = "i486-linuxaout";
#endif
#ifdef sun
if (floatoption[0])
arglist[nargs++] = floatoption;
#endif
if (optimize) {
for (i=0; i < nopt_flags; i++)
arglist[nargs++] = opt_flags[i];
}
/* Add the user-defined flags last so they can override the
* hardwired options.
*/
if ((s = os_getenv("XC-FFLAGS")) || (s = os_getenv("XC_FFLAGS")))
addflags (s, arglist, &nargs);
for (i=0; i < nflags; i++)
arglist[nargs++] = lflags[i];
/* Make list of files to be compiled. Do not include F77 files,
* as they were already compiled above.
*/
for (i=0, noperands=0; i < nfiles; i++) {
for (j=0; j < nffiles && lffiles[j] != lfiles[i]; j++)
;
if (j >= nffiles && isffile (lfiles[i])) {
arglist[nargs++] = lfiles[i];
noperands++;
}
}
arglist[nargs] = NULL;
if (noperands > 0) {
if (debug)
printargs (f77comp, arglist, nargs);
status = run (f77comp, arglist);
#ifdef LINUX
/* This kludge is to work around a bug in the F2C based F77 script
* on Linux, which returns an exit status of 4 when successfully
* compiling a Fortran file.
*/
if (status == 4)
status = 0;
#endif
errflag += status;
}
/* Compile the remaining non-Fortran source files with CC to produce
* object code.
*/
nargs = 0;
arglist[nargs++] = ccomp;
arglist[nargs++] = "-c";
#ifdef MACH64
arglist[nargs++] = "-DMACH64"; /* needed for zmain.c */
#endif
#ifdef LINUX64
arglist[nargs++] = "-DLINUX64"; /* needed for zmain.c */
#endif
#if (defined(LINUX) && !defined(MACH64))
arglist[nargs++] = "-m32";
#endif
#ifdef LINUX
arglist[nargs++] = "-DLINUX";
#ifdef REDHAT
arglist[nargs++] = "-DREDHAT";
#endif
#ifdef LINUXPPC
arglist[nargs++] = "-DLINUXPPC";
#endif
arglist[nargs++] = "-DPOSIX";
arglist[nargs++] = "-DSYSV";
#endif
#ifdef BSD
arglist[nargs++] = "-m32";
arglist[nargs++] = "-DBSD";
#endif
#ifdef MACOSX
arglist[nargs++] = "-DMACOSX";
if (useg95 == 0) {
if ((irafarch = os_getenv("IRAFARCH"))) {