File: ymake

package info (click to toggle)
ncl 6.3.0-13
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 196,648 kB
  • ctags: 70,631
  • sloc: ansic: 603,601; fortran: 441,469; sed: 11,222; csh: 8,350; yacc: 4,253; xml: 1,928; sh: 1,526; lex: 1,266; python: 1,067; f90: 652; perl: 479; java: 447; objc: 291; makefile: 109
file content (702 lines) | stat: -rwxr-xr-x 17,516 bytes parent folder | download | duplicates (3)
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
#!/bin/csh -f
#
#	$Id: ymake,v 1.49 2008-12-28 13:27:18 haley Exp $
#
######################################################################
#
# Program:	ymake
#
# Purpose:	"ymake" processes a "yMakefile" or "ymakefile"
#		that may have imbedded "cpp" commands. In producing
#		the output file, "Makefile" or "makefile", "ymake"
#		first reads in a "configuration file", based on
#		what the host system is, and then runs the
#		yMakefile/ymakefile through "cpp", thus producing
#		"Makefile" or "makefile". The result is a standard,
#		portable Makefile.
#
#		This mechanism is used for generating a machine-dependent 
#		hierarchy of Makefiles at installation time.
#
#		Warning: this script WILL overwrite the existing
#		Makefile IF a yMakefile exists!
#
# Author:	Don Middleton-Link
#
# Revision History:
#		Created June 1988
#		Revised October 1988 - extensions added for IBM/AIX
#		Moved to Bourne shell version for UNICOS 5.0 beta
#		Revised November 1989
#		Significant re-write/additions to allow an installed
#			version May 93 (boote)
#		Added option for FreeBSD operating system 2003 (grubin)
#
# Warning:	This script WILL overwrite the existing
#		Makefile IF a yMakefile exists!
#
######################################################################

set     defines
set     ymakeargs
@ useinstalled = 1

while ($#argv)

        switch ("$argv[1]")

        case    -config:
                shift
                if ($#argv) then
                        set config_dir = "$argv[1]"
                        if (! -d $config_dir) then
                                echo "$0 : Unable to open NCARG_CONFIG dir : $config_dir"
                                exit 1
                        endif
                                
                        set defines = (-I$argv[1] $defines)
                        @ useinstalled = 0
                else
                        exit 1
                endif
                breaksw

        case    -noproject:

                @ NoProject = 1
                set defines = ($defines -D_NO_PROJECT_FILE)
                set ymakeargs = ($ymakeargs -noproject)

                breaksw

        case    -Curdir:
                shift
                if ($#argv) then
                        set cur_dir = "$argv[1]"

                        set defines=($defines -DCURDIR=$cur_dir)
                else
                        exit 1
                endif
                breaksw

        case    -Topdir:
                shift
                if ($#argv) then
                        set top_dir = "$argv[1]"
                        if (! -d $top_dir) then
                                echo "$0 : Unable to open Topdir : $top_dir" 
                                exit 1
                        endif

                        set defines=($defines -DTOPDIR=$top_dir)
                                
                else
                        exit 1
                endif
                breaksw

        default:
                set defines = ($defines $argv[1])
                set ymakeargs = ($ymakeargs $argv[1])
                breaksw
        endsw

        shift
end

@ num_args = 0
foreach arg ($ymakeargs)
        @ num_args++
        switch ("$num_args")

        case 1:
                set defines = ($defines -D_YmakeArg1=$arg)
                breaksw
        case 2:
                set defines = ($defines -D_YmakeArg2=$arg)
                breaksw
        case 3:
                set defines = ($defines -D_YmakeArg3=$arg)
                breaksw
        case 4:
                set defines = ($defines -D_YmakeArg4=$arg)
                breaksw
        case 5:
                set defines = ($defines -D_YmakeArg5=$arg)
                breaksw
        default:
                echo "$0 :Too Many args - ignoring $arg" 
                breaksw
        endsw
end

if ( ! $?top_dir) then
        set top_dir = .
endif

if ( -r $top_dir/ymake.conf) then
        set defines=($defines -D_LOCAL_CONF=\"$top_dir/ymake.conf\")
endif

if (! $?NoProject) then
        if ( -r $top_dir/ymake.project) then
                set defines=($defines -D_PROJECT_FILE=\"$top_dir/ymake.project\")
        endif
endif

if ($useinstalled != 0) then
        set config_dir = `ncargpath config`
        if ($status != 0) then
                echo "$0 : Unable to find NCARG_CONFIG dir" 
                exit 1
        endif
        if (! -d $config_dir) then
                echo "$0 : Unable to open NCARG_CONFIG dir : $config_dir" 
                exit 1
        endif
        set defines = (-I$config_dir -DUseInstalled $defines)

        set root_dir = `ncargpath root`
        if ($status != 0) then
                echo "$0 : Unable to find NCARG_ROOT dir" 
                exit 1
        endif
        set defines=($defines -D_InstRoot\=$root_dir -D_InstConfig\=$config_dir)

        set tmp_dir = `ncargpath tmp`
        if ($status != 0) then
                echo "$0 : Unable to find TMP dir" 
                exit 1
        endif
        set defines = ($defines -D_InstTmp\=$tmp_dir)

        set lib_dir = `ncargpath lib`
        if ($status != 0) then
                echo "$0 : Unable to find NCARG_LIB dir"
                exit 1
        endif
        set defines = ($defines -D_InstLib\=$lib_dir)

        set bin_dir = `ncargpath bin`
        if ($status != 0) then
                echo "$0 : Unable to find NCARG_BIN dir"
                exit 1
        endif
        set defines = ($defines -D_InstBin\=$bin_dir)

        set inc_dir = `ncargpath include`
        if ($status != 0) then
                echo "$0 : Unable to find NCARG_INCLUDE dir" 
                exit 1
        endif
        set defines = ($defines -D_InstInc\=$inc_dir)

        set man_dir = `ncargpath man`
        if ($status != 0) then
                echo "$0 : Unable to find NCARG_MAN dir" 
                exit 1
        endif
        set defines = ($defines -D_InstMan\=$man_dir)
endif

if ($?YMAKE_DEV_FILE) then
        if (-r $YMAKE_DEV_FILE) then
                set defines=($defines -DYMAKEDEVFILE=\"$YMAKE_DEV_FILE\")
        else
                echo "unable to open YMAKE_DEV_FILE $YMAKE_DEV_FILE" 
        endif
endif

if (-e $config_dir/Site.local) then
        set defines=($defines -DSiteFile=\"Site.local\" -DSiteFileName=Site.local)
else
        set defines=($defines -DSiteFile=\"Site\" -DSiteFileName=Site)
endif

set ymakefile
set outfile

set tmp1="ymake.tmp$$"
/bin/rm -f $tmp1

if (-e "ymakefile") then
        set ymakefile="ymakefile"
        set outfile = "makefile"
else if (-e "yMakefile") then
        set ymakefile="yMakefile"
        set outfile = "Makefile"
else
        echo "$0 : no y(mM)akefile found" 
        exit 1
endif

set defines=($defines -DYMAKESRCFILE=$ymakefile)

if (-e $outfile) then
        if (-e $outfile.bak) then
                /bin/rm -f $outfile.bak
        endif
        mv $outfile $outfile.bak
endif

onintr error_cleanup

set foo = `uname -s`

#
#       Figure out what kind of system we are on. We need to know the OS
#       and the machine architecture. 
#
if ($status != 0) then
        echo "$0 : Unknown operating system"
        exit 1
endif
set mach = `uname -m`
if ($status != 0) then
        echo "$0 : Unknown machine type" 
        exit 1
endif

switch ("$foo")
case SunOS:
case AIX:
case IRIX:
case IRIX64:
case ULTRIX:
case HP-UX:
case OSF1:
case Linux:
case FreeBSD:
case Darwin:
        set opsys = $foo
        breaksw
case GNU/kFreeBSD:
	# GNU/kFreeBSD on DEBIAN
	set opsys = DEBIAN
	breaksw
case GNU:
	# GNU/Hurd on Debian
	set opsys = DEBIAN
	breaksw
case CYGWIN*:
        set opsys = CYGWIN
        breaksw
default:
        set foo = `uname -m`
        if ($status != 0) exit 1
        switch ("$foo")
        case    CRAY*
        case    cray*
                set opsys = UNICOS
                breaksw
        default:
                echo "$0 : system unknown"
                exit 1
        endsw
        breaksw
endsw

switch ("$opsys")
case    SunOS:
        set foo = `uname -r`
        if ($status != 0) exit 1

        switch ("$foo")
        case    5*:
                set os = $opsys
                set extraos = Solaris
                breaksw
        default:
                set os = $opsys
                breaksw
        endsw

        switch ("$mach")
        case    sun4*:
                set arch = sun4

                if ($?extraos == 0) then
                        set sysincs = Sun4
                        breaksw
                endif

                if ("$extraos" == Solaris) then
                        set sysincs = Sun4Solaris
                        breaksw
                endif
                breaksw
        case    i86pc*:
                set arch = PC
                if ("$extraos" == Solaris) then
                  set sysincs = SolarisPC
                  breaksw
                endif
                breaksw
        case    sun3*:
                set arch = sun3
                set sysincs = Sun3
                breaksw
        default:
                echo "$0 : Unknown machine type"
                exit 1
        endsw

        set vendor = SUN

        breaksw

case    AIX:
        set os = $opsys

        switch ("$mach")
        case    00*00:
                set model = `echo $mach | cut -c9-10`
                set arch = RS6k$model
                breaksw
        default:
                echo "$0 : Unknown machine type" 
                exit 1
        endsw

        set sysincs = AIX_RS6000
        set vendor = IBM

        breaksw

case 	DEBIAN:
	set os = $opsys
	set model = $mach
	set arch = $mach
	set sysincs = DEBIAN
	set vendor = DEBIAN
	breaksw

case    Linux:
        set os = $opsys

        switch ("$mach")
        case    i*86:
        case    x*86:
	case    amd64:
        case    i*64:
        case    x*64:
        case    s390*:
        case    mip*:
        case    sparc*:
        case    arm*:
        case    ppc*:
        case    aarch64*:
        case    alpha:
            set model   = $mach
            set arch    = $mach
            set sysincs = LINUX
            set vendor  = IBM
            breaksw
        default:
            echo "$0 : Unknown machine type" 
            exit 1
        endsw

        breaksw

case    FreeBSD:
        set os = $opsys

        switch ("$mach")
        case    i*86:
        case    i*64:
        case    alpha:
            set model   = $mach
            set arch    = $mach
            set sysincs = FreeBSD
            set vendor  = IBM
            breaksw
        default:
            echo "$0 : Unknown machine type"
            exit 1
        endsw

        breaksw

case    Darwin:
        set os = $opsys

        switch ("$mach[1]")
        case    Power:
            set model   = $mach
            set arch    = $mach
            set sysincs = Darwin
            set vendor  = Apple
            breaksw
        case    i386:
        case    x86_64:
            set model   = $mach
            set arch    = $mach
            set sysincs = Darwin_Intel
            set vendor  = Apple
            breaksw
        default:
            echo "$0 : Unknown machine type" 
            exit 1
        endsw

        breaksw

case	CYGWIN:
        set os = $opsys
        set model = $mach
        set arch = $mach
        set sysincs = CYGWIN
        set vendor = Cygnus
        breaksw

case    IRIX:
case    IRIX64:
        set os = $opsys

        switch ("$mach")
        case    IP*:
                set arch = $mach
                breaksw
        default:
                echo "$0 : Unknown machine type" 
                exit 1
        endsw

        set sysincs = SGI_IRIX
        set vendor = SGI

        breaksw

case    ULTRIX:
case    OSF1:
        set os = $opsys
        set arch = $mach

        if ("$os" == ULTRIX) then
                set sysincs = DECRISC
        else
                set sysincs = AlphaOSF1
        endif

        set vendor = DEC

        breaksw

case    HP-UX:
        set os = HPUX

        switch ("$mach")
        case    9000/7*:
                set model = `echo $mach | cut -c7-8`
                set arch = HP9k7$model
                breaksw
        case    9000/8*:
                set model = `echo $mach | cut -c7-8`
                set arch = HP9k8$model
                breaksw
        default:
                echo "$0 : Unknown machine type" 
                exit 1
        endsw

        set sysincs = HPUX_snake
        set vendor = HP

        breaksw

case    UNICOS:
        set os = $opsys

        switch ("$mach[1]")
        case   CRAY:
                switch ("$mach[2]")
                case    Y*:
                        set arch = YMP
                breaksw
        case    C90:
        case    J90:
        case    TS:
                        set arch = $mach[1]
                breaksw
                default:
                        echo "$0 : Unknown machine type" 
                        exit 1
                endsw
        breaksw

        case   "CRAY-2":
                set arch = cray2
        breaksw

        case   "cray-3":
                set arch = cray3
        breaksw

        default:
                echo "$0 : Unknown machine type" 
                exit 1
        endsw

        set sysincs = Cray
        set vendor = CRAY

        breaksw

default:
        echo "$0 : Unknown System Type - No Config file" 
        exit 1
        breaksw
endsw

if ($?sysincs == 0) then
        echo "$0 : Unknown System Type - No Config file" 
        exit 1
endif

#
#       add sysincs defs to list
#
if (-e $config_dir/$sysincs) then
        set defines=($defines -DSystemIncludes=\"$sysincs\")
        set defines=($defines -DSystemIncludesName=\"$sysincs\")
else
        echo "$0 : Unable to open Config file: $sysincs" 
        exit 1
endif

switch ("$opsys")
case    AIX:
        set major = `uname -v`
        set minor = `uname -r`
        set subminor = ""
        breaksw
case    OSF1:
        set major = `uname -r | cut -d. -f1 | cut -c2- `
        set minor = `uname -r | cut -d. -f2`
        set subminor = `uname -r | cut -d. -f3`
        breaksw
case    SunOS:
case    IRIX64:
case    IRIX:
case    ULTRIX:
case    HP-UX:
case    UNICOS:
default:
        set major = `uname -r | cut -d. -f1`
        set minor = `uname -r | cut -d. -f2`
        set subminor = `uname -r | cut -d. -f3`
        if ($minor == "5SE") set minor = 5
        breaksw
endsw

if ("$subminor" == "") then
        unset subminor
endif

#
#       add os and arch to our defines list
#       also add major minor and sub-minor
#


if ($?extraos) then
        set defines=($defines -D"$extraos" -D_OpSys2Def=-D"$extraos")
else
        set defines=($defines -D_OpSys2Def="")
endif
set defines=($defines -D"$os" -D_OpSysDef=-D"$os")
set defines=($defines -D"$arch" -D"$vendor")
set defines=($defines -D_ArchDef=-D"$arch" -D_VendorDef=-D"$vendor")
set defines=($defines -D_Major=$major -D_Minor=$minor)
if ($?subminor) then
        set defines=($defines -D_SubMinor=$subminor)
endif


# Leave the cpp commands unmolested but insert a C null comment
# in front of Makefile comment lines.  cpp will later remove these
# restoring the original form (plus a few blank lines).
# Also check for a tab followed by a # - that should be a saber target
# so insert a C null comment for them as well.

sed <$ymakefile >! $tmp1 \
        -e '/^#[        ]*if/b' \
        -e '/^#[        ]*ifdef/b' \
        -e '/^#[        ]*ifndef/b' \
        -e '/^#[        ]*else/b' \
        -e '/^#[        ]*elif/b' \
        -e '/^#[        ]*endif/b' \
        -e '/^#[        ]*define/b' \
        -e '/^#[        ]*undef/b' \
        -e '/^#[        ]*line/b' \
        -e '/^#[        ]*include/b' \
        -e '/^#/s$$/**/_COMMENT_&$' \
        -e '/^  #/s$$/**/_COMMENT_&$'

cat <<'EOF' >! $outfile
#########################################################################
#                                                                       #
#       This Makefile was created by the "ymake" utility.               #
#       If you wish to make changes in the "Makefile" or "makefile",    #
#       do so by making changes to "yMakefile" or "ymakefile"           #
#       and executing "make local-Makefile".                            #
#                                                                       #
#########################################################################

'EOF'

if (-e /usr/ccs/lib/cpp) then
    set cpp = /usr/ccs/lib/cpp
else if (-e /opt/ctl/bin/cpp) then
    set cpp = /opt/ctl/bin/cpp
else if (-e /usr/bin/cpp) then
    set cpp = /usr/bin/cpp
else
  set cpp = /lib/cpp
endif

# set cpp options

switch ("$opsys")
case    UNICOS:
        set cppopt = -N
        breaksw
case    Linux:
case	FreeBSD:
case    CYGWIN:
        set cppopt = -traditional-cpp
        breaksw
default:
        set cppopt
        breaksw
endsw

switch ("$opsys")
case    CYGWIN:
echo '#include "Template"' | \
$cpp $cppopt -I. -D_COMMENT_\#="" -DNGCOMM=\# $defines -DYMAKEFILE=\"$tmp1\" | \
"$config_dir"/ymake-filter >>$outfile
breaksw
default:
echo '#include "Template"' | \
$cpp $cppopt -I. -D_COMMENT_="" -DNGCOMM=\# $defines -DYMAKEFILE=\"$tmp1\" | \
"$config_dir"/ymake-filter >>$outfile
breaksw
endsw

if ($status) goto error_cleanup

/bin/rm -f $outfile.bak $tmp1
onintr
exit 0

error_cleanup:
echo "" 
echo "Error in <ymake>: Interrupted in" `pwd` "- restoring $outfile" 
/bin/rm -f $outfile $tmp1
cp $outfile.bak $outfile
/bin/rm -f $outfile.bak
exit 1
onintr