-
Notifications
You must be signed in to change notification settings - Fork 2
/
hpxconfig_functions.sh
2889 lines (2641 loc) · 92 KB
/
hpxconfig_functions.sh
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
#-------------------------------------------------------------
# Bourne/Korn shell functions required to configure Healpix packages
# ------------------------------------------------------------
# 2008-03-26, IAP, EH
# 2008-07-24 ---> version 2.10
# 2008-09-22, EH: remove need for IDL_DIR
# no long term effects (on IDL_PATH and IDL_STARTUP) of hidl or hidlde
# do not expand HEALPIX variable in F90 config file
# 2008-09-26: more stringent tests on F90 compiler (checkF90Compilation) and
# linkage to fitsio (checkF90FitsioLink)
# clean-up macros creating 'to_be_removed' files
# 2008-11-13 ---> version 2.11
# 2008-11-17: corrected typo in C 'c-shared' target
# detects correctly gfortran for version >= 4.3
# 2008-11-21: solved potential problem with multiple cfitio*.tar.gz for C++
# introduced ${HEAD}
# replaced ~ with ${HOME}
# 2009-02-25: added Fortran compilation flag for 64 bit INTEGER
# still unknown for Fujitsu, Lahey, Portland, Absoft
# 2009-06-18: added WLRPATH so that F90 codes can be linked to shared cfitsio library
# 2009-06-26: replace echoLn with printf
# 2009-07-10: debugging on MacOS, libgif -> libhpxgif
# 2009-10-12: replace gfortran -dumpversion -> gfortran --version
# 2009-10-21: removed bashisms:
# replaced ' == ' tests with ' = ' or ' -eq '
# got rid of arrays in pickCppCompilation
# 2010-06-22: supports zsh (M. Tomasi)
# 2010-12-09: added IdentifyCParallCompiler to compile C libpsht with OpenMP
# 2011-01-28: C++ configuration ask for preinstalled cfitsio library
# 2011-01-31: keep track of previous choice of FITSDIR and FITSINC (within same session)
# : propose OpenMP by default
# 2011-03-07: allow linking with shared libcfitsio for the C++ port
# 2012-02-27: better parsing of config.* files in C++ configuration
# 2012-05-30: and ignore healpy specific config.* files.
# 2012-11-05: supports python (healpy) configuration
# proposes -fPIC compilation of F90 code
# 2013-04-18: work-around for GCC 4.4 bug
# 2013-07-26: F90: add output location of modules ($MODDIR). Hacked from CMake.
# 2014-11-25: propose cfitsio-free compilation of C package
# 2015-05-12: correct bashism (==) introduced above (problematic for dash and zsh)
# 2015-07-31: improved g95 support; updated support address
# 2016-04-28: tentatively added MINGW for Windows
# 2016-06-02: debugged gcc detection in IdentifyCCompiler
# 2016-08-10: 1st attempt to better detect python version
# 2017-06-21: deal with FL (Fawlty Language) IDL clone (generateConfFlFile)
# 2019-01-21: call autotool configure for C++;
# read system variables
# CC, (used in C/sharp/C++/F90/healpy)
# C_FITS, C_SHARED (C)
# CXX, (C++/ healpy)
# CXXFLAGS, CXX_PARAL (C++)
# SHARP_COPT, SHARP_PARAL (sharp)
# FC, F_AR, F_DIRSUFF, F_OPT, F_PARAL, F_SHARED (F90)
# FITSDIR, (C/ C++/F90)
# FITSINC, (C/ C++)
# PYTHON (healpy)
# PROFILE_EDIT (profile)
# papersize, ps_com, pdf_com, gif_com (IDL)
# to define proposed default values.
# 2019-10-01: addition and documentation of --auto=list mode
# 2020-01-06: added missing space in whereisCmd
# 2020-01-14: removed spurious \r in a some comments
# 2020-01-23: removed bashism, improved FITSDIR behavior
# 2021-01-26: better handling of libcfitsio without libcurl
# 2021-04-06: added SHARP_PARAL and CXX_PARAL
#=====================================
#=========== General usage ===========
#=====================================
# checkDir: search for installation directories and create them
# is necessary
# echoLn:
# findFITSLib: search for FITSIO library
# fullPath: convert relative to absolute directory names
#
#
#-------------
checkDir () {
l=""
for d in $*; do
[ ! -d $d ] && l="$l $d"
done
if [ "x$l" != "x" ]; then
echo "Warning: The following directories could not be found:"
for d in $l; do
echo "$d"
done
if [ $INTERACTIVE -eq 1 ] ; then
echoLn "Should I attempt to create these directories (y|n) [y]? "
read answer
if [ "x$answer" != "xn" -a "x$answer" != "xN" ]; then
for d in $l; do
${MKDIR} $d 1>${DEVNULL} 2>&1
if [ $? -gt 0 ]; then
echo "Error: Could not create directory $d"
crashAndBurn
fi
done
else
echo "Create installation directories first."
crashAndBurn
fi
else
# remove extra question in automated mode, to make script more predictable
echoLn "They now will be created ... "
for d in $l; do
${MKDIR} $d 1>${DEVNULL} 2>&1
if [ $? -gt 0 ]; then
echo "Error: Could not create directory $d"
crashAndBurn
fi
done
echo "done."
fi
fi
}
#-------------
echoLn () {
# if [ "${OS}" = "Linux" -o "${OS}" = "Darwin" ]; then
# echo -n "$*"
# else
# echo "$*\c"
# fi
${PRINTF} "$*"
}
#-------------
findFITSLib () {
for dir in $* /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 \
/usr/local/lib/cfitsio /usr/local/lib64/cftisio /usr/local/src/cfitsio \
${HOME}/lib ${HOME}/lib64 \
`${LS} -dr /softs/cfitsio*/lib 2> ${DEVNULL}` \
`${LS} -dr /softs/cfitsio/*/lib 2> ${DEVNULL}` \
`${LS} -dr /usr/common/usg/cfitsio/*/lib 2> ${DEVNULL}` \
`${LS} -dr ${HOME}/?oft*/cfitsio*/ 2> ${DEVNULL}` \
`${LS} -dr ${HOME}/?oft*/cfitsio*/lib 2> ${DEVNULL}` \
`${LS} -dr ${HEADAS}/../heacore/*-*-*/lib 2> ${DEVNULL}` ; do
if [ -r "${dir}/lib${LIBFITS}.a" -o -r "${dir}/lib${LIBFITS}.so" -o -r "${dir}/lib${LIBFITS}.dylib" ] ; then
FITSDIR=$dir
break
fi
done
}
#-------------
findFITSInclude () {
for dir in $* /usr/include /usr/local/include \
/usr/local/src/cfitsio \
${HOME}/include ${HOME}/include64 \
`${LS} -dr /softs/cfitsio*/include 2> ${DEVNULL}` \
`${LS} -dr /softs/cfitsio/*/include 2> ${DEVNULL}` \
`${LS} -dr /usr/common/usg/cfitsio/*/include 2> ${DEVNULL}` \
`${LS} -dr ${HOME}/?oft*/cfitsio*/ 2> ${DEVNULL}` \
`${LS} -dr ${HOME}/?oft*/cfitsio*/include 2> ${DEVNULL}` \
`${LS} -dr ${HEADAS}/../heacore/*-*-*/include 2> ${DEVNULL}` ; do
if [ -r "${dir}/fitsio.h" ] ; then
FITSINC=$dir
break
fi
done
}
#-------------
findFITSPrefix () {
for dir in $* /usr /usr/local /usr/local/lib/cfitsio /usr/local/cfitsio /usr/local/lib64/cftisio /usr/local/src/cfitsio ${HOME}/softs/cfitsio/3.24 /usr/common/usg/cfitsio/3.26 ; do
testlib="${dir}/lib/lib${LIBFITS}"
if ( ([ -r "${testlib}.a" ] || [ -r "${testlib}.so" ] || [ -r "${testlib}.dylib" ]) && [ -r "${dir}/include/fitsio.h" ] ) ; then
FITSPREFIX=$dir
break
fi
done
}
#-------------
fullPath () {
t='TEMP=`cd $TEMP; pwd`'
for d in $*; do
eval `echo $t | sed 's/TEMP/'$d'/g'`
done
}
#-------------
askMake () {
if [ "${MAKESET}" = 0 ] ; then
echoLn "Enter make command ($MAKE): "
read answer
[ "x$answer" != "x" ] && MAKE=$answer
MAKESET=1
fi
}
#-------------
goodBye () {
echo
if [ -s Makefile -a ${edited_makefile} -eq 1 ] ; then
echo
echo "You can run \"(GNU)make\" to build all the packages configured so far,"
echo " and \"(GNU)make test\" to test them."
echo " If supported, \"make -j\" will parallelize the tasks"
echo "and speed up the compilation and installation"
echo
fi
echo "Good Bye !"
echo
exit 0
}
#-------------
crashAndBurn () {
echo
echo "Something went wrong ..."
echo "Quitting configuration script !"
echo
exit -1
}
#-------------
whereisCmd () {
for d in $*; do
CMD=`${WHEREIS} $d`
if [ "x${CMD}" != "x" -a "x${CMD}" != "x${d}:" ] ; then
break
fi
done
}
#-------------
isTrue () {
[ "$1" = "1" -o "$1" = "y" -o "$1" = "Y" -o "$1" = "t" -o "$1" = "T" ] && echo 1 || echo 0
}
#-------------
isFalse () {
[ "$1" = "0" -o "$1" = "n" -o "$1" = "N" -o "$1" = "f" -o "$1" = "F" ] && echo 1 || echo 0
}
#=================
# automatic mode
#=================
# fillFile () { #$1=leading line, $2=number of blank lines, $3=output file
# lead=$1
# rep=$2
# multicr='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
# string=$(echo $multicr | ${AWK} -v var=$rep '{ string=substr($0, 1, var); print string; }' )
# printf `echo ${lead}X${string} | sed 's|X|\\\n|g'` >> $3
# }
fillFile () { #$1=leading line, $2=number of blank lines, $3=output file
echo $1 $2 | ${AWK} '{print $1} {while ($2--) print ""}' >> $3
}
processAutoList(){
autofile=$1
autolist=$2
do_profile=0
do_c=0
do_cxx=0
do_f90=0
do_idl=0
do_healpy=0
do_sharp=0
sharp_configured=0
test_Sharp
# ---- parse list ----
#autolist=${autolist/,/ } # not in dash
#autolist=`${SED} 's|,| |g' <<< $autolist` # not in dash
autolist=`echo $autolist | ${SED} 's/,/ /g'`
for item in $autolist; do
case $item in
all)
do_profile=1
do_c=1
do_sharp=1
do_cxx=1
do_f90=1
do_idl=1
do_healpy=1
;;
profile)
do_profile=1
;;
c)
do_profile=1
do_c=1
;;
cxx|cpp)
do_profile=1
[ "$sharp_configured" = "0" ] && do_sharp=1 # only if not already configured
do_cxx=1
;;
f90)
do_profile=1
[ "$sharp_configured" = "0" ] && do_sharp=1 # only if not already configured
do_f90=1
;;
idl)
do_profile=1
do_idl=1
;;
healpy)
do_healpy=1
;;
sharp)
do_sharp=1
;;
*)
echo "Unknown item listed in automatic mode: $item"
echo "must be among: ${usage4}"
crashAndBurn
esac
done
# ---- fill file ----
${RM} -f ${autofile}
touch ${autofile}
#
[ $do_profile -eq 1 ] && fillFile 9 1 ${autofile}
[ $do_sharp -eq 1 ] && fillFile 7 3 ${autofile}
if [ $do_c -eq 1 ]; then
if [ `isTrue $C_FITS` -eq 1 ]; then
fillFile 2 8 ${autofile}
else
fillFile 2 5 ${autofile}
fi
fi
[ $do_cxx -eq 1 ] && fillFile 4 7 ${autofile}
[ $do_f90 -eq 1 ] && fillFile 3 13 ${autofile}
[ $do_idl -eq 1 ] && fillFile 1 4 ${autofile}
[ $do_healpy -eq 1 ] && fillFile 5 3 ${autofile}
fillFile 0 0 ${autofile} # to exit gracefully
do_profile=0
do_c=0
do_cxx=0
do_f90=0
do_idl=0
do_healpy=0
do_sharp=0
}
#=====================================
#=========== C package ===========
#=====================================
# setCDefaults
# add64bitCFlags
# askCUserMisc
# editCMakefile
# writeCpkgconfigFile
# C_config
setCDefaults () {
OPT="-O2 -Wall"
C_AR="ar -rsv"
PIC="-fPIC" # works with gcc, icc and clang
C_WLRPATH=""
case $OS in
AIX)
CC="xlc"
OPT="-O -DRS6000"
PIC="-G"
CF64="-q64"
AR64="-X64"
;;
Linux)
C_WLRPATH="-Wl,-R"
;;
esac
LIBDIR=$HEALPIX/lib
INCDIR=$HEALPIX/include
CDIR="src/C"
FITSINC="/usr/local/include"
#DO_C_SHARED=0
}
# -------------
add64bitCFlags () {
if [ "x$CF64$AR64" != "x" ]; then
echo "Do you want to make a 64 bit compilation ? (y|n) [n]: "
read answer
if [ "x$answer" = "xy" -o "x$answer" = "xY" ]; then
OPT="$OPT $CF64"
C_AR="$C_AR $AR64"
fi
fi
}
#-------------
askCUserMisc () {
checkDir $INCDIR $LIBDIR
fullPath INCDIR LIBDIR
echoLn "enter C compiler you want to use [$CC]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CC=$answer
add64bitCFlags
echoLn "enter options for C compiler [$OPT]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && OPT=$answer
echoLn "enter archive creation (and indexing) command [$C_AR]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && C_AR=$answer
echoLn "do you want the HEALPix/C library to include CFITSIO-related functions ? (y|n)"
if [ `isTrue ${C_FITS}` -eq 1 ] ; then
echoLn " [y]: "
read answer
[ `isFalse ${answer}` -eq 1 ] && C_WITHOUT_CFITSIO=1 || C_WITHOUT_CFITSIO=0
else
echoLn " [n]: "
read answer
[ `isTrue ${answer}` -eq 1 ] && C_WITHOUT_CFITSIO=0 || C_WITHOUT_CFITSIO=1
fi
[ $INTERACTIVE -eq 0 ] && echo $answer
if [ ${C_WITHOUT_CFITSIO} -eq 0 ]; then
echoLn "enter full name of cfitsio library [lib${LIBFITS}.a]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && LIBFITS=`${BASENAME} $answer ".a" | ${SED} "s/^lib//"`
findFITSLib $LIBDIR $FITSDIR
echoLn "enter location of cfitsio library [$FITSDIR]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && FITSDIR=$answer
fullPath FITSDIR
[ "x$C_WLRPATH" != "x" ] && C_WLRPATH="${C_WLRPATH}${FITSDIR}"
lib="${FITSDIR}/lib${LIBFITS}.a"
if [ ! -r $lib ]; then
echo "error: fits library $lib not found"
crashAndBurn
fi
checkFitsioCurl $lib
guess1=${FITSDIR}
guess2=`${DIRNAME} ${guess1}`
guess3="${guess2}/include"
findFITSInclude $INCDIR ${guess1} ${guess2} ${guess3} $FITSINC
echoLn "enter location of cfitsio header fitsio.h [$FITSINC]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && FITSINC=$answer
fullPath FITSINC
inc="${FITSINC}/fitsio.h"
if [ ! -r $inc ]; then
echo "error: cfitsio include file $inc not found"
crashAndBurn
fi
else
C_WITHOUT_CFITSIO=1
fi
echoLn "A static library is produced by default. Do you also want a shared library ? "
if [ `isTrue $C_SHARED` -eq 1 ]; then
echoLn "(y|n) [y]: "
read answer
[ `isFalse $answer` -eq 1 ] && DO_C_SHARED=0 || DO_C_SHARED=1
else
echoLn "(y|n) [n]: "
read answer
[ `isTrue $answer` -eq 1 ] && DO_C_SHARED=1 || DO_C_SHARED=0
fi
[ $INTERACTIVE -eq 0 ] && echo $answer
}
#-------------
editCMakefile () {
echoLn "Editing top Makefile for C ..."
clibtypes='c-static'
if [ ${DO_C_SHARED} -eq 1 ]; then
if [ "${OS}" = "Darwin" ]; then
clibtypes="${clibtypes} c-dynamic"
else
###clibtypes="${clibtypes} shared" # corrected 2008-11-17
clibtypes="${clibtypes} c-shared"
fi
fi
# [ -r Makefile ] && ${CP} Makefile Makefile.bkup
mv -f Makefile Makefile_tmp
${CAT} Makefile_tmp |\
${SED} "s|^C_CC.*$|C_CC = $CC|" |\
${SED} "s|^C_PIC.*$|C_PIC = $PIC|" |\
${SED} "s|^C_OPT.*$|C_OPT = $OPT|" |\
${SED} "s|^C_INCDIR.*$|C_INCDIR = $INCDIR|" |\
${SED} "s|^C_LIBDIR.*$|C_LIBDIR = $LIBDIR|" |\
${SED} "s|^C_AR.*$|C_AR = $C_AR|" |\
${SED} "s|^C_WITHOUT_CFITSIO.*$|C_WITHOUT_CFITSIO = $C_WITHOUT_CFITSIO|" |\
${SED} "s|^C_CFITSIO_INCDIR.*$|C_CFITSIO_INCDIR = $FITSINC|" |\
${SED} "s|^C_CFITSIO_LIBDIR.*$|C_CFITSIO_LIBDIR = $FITSDIR|" |\
${SED} "s|^C_EXTRA_LIB.*$|C_EXTRA_LIB = $CFITSIOCURL|" |\
${SED} "s|^C_WLRPATH.*$|C_WLRPATH = $C_WLRPATH|" |\
${SED} "s|^C_ALL.*|C_ALL = ${clibtypes}|" |\
${SED} "s|^HEALPIX=.*$|HEALPIX = $HEALPIX|" |\
${SED} "s|^ALL\(.*\) c-void \(.*\)|ALL\1 c-all \2|" |\
${SED} "s|^TESTS\(.*\) c-void \(.*\)|TESTS\1 c-test \2|" |\
${SED} "s|^CLEAN\(.*\) c-void \(.*\)|CLEAN\1 c-clean \2|" |\
${SED} "s|^DISTCLEAN\(.*\) c-void \(.*\)|DISTCLEAN\1 c-distclean \2|" |\
${SED} "s|^TIDY\(.*\) c-void \(.*\)|TIDY\1 c-tidy \2|" > Makefile
echo " done."
edited_makefile=1
}
# -----------------------------------------------------------------
writeCpkgconfigFile (){
#pkgconfigFile=${HEALPIX}/lib/chealpix.pc
pkgconfigFile=${HEALPIX}/lib/pkgconfig/chealpix.pc
${MKDIR} -p `${DIRNAME} ${pkgconfigFile}`
echo
echo "Writing pkgconfig file: ${pkgconfigFile}"
echo "# HEALPix/C pkg-config file" > ${pkgconfigFile}
echo " " >> ${pkgconfigFile}
echo "prefix=${HEALPIX}" >> ${pkgconfigFile}
echo "libdir=\${prefix}/lib" >> ${pkgconfigFile}
echo "includedir=\${prefix}/include" >> ${pkgconfigFile}
echo " " >> ${pkgconfigFile}
echo "Name: chealpix" >> ${pkgconfigFile}
echo "Description: C library for HEALPix (Hierarchical Equal-Area iso-Latitude) pixelisation of the sphere" >> ${pkgconfigFile}
echo "Version: ${HPXVERSION}" >> ${pkgconfigFile}
echo "URL: https://healpix.sourceforge.io" >> ${pkgconfigFile}
if [ ${C_WITHOUT_CFITSIO} -eq 0 ] ; then
echo "Requires: cfitsio" >> ${pkgconfigFile}
fi
echo "Libs: -L\${libdir} -lchealpix" >> ${pkgconfigFile}
echo "Cflags: -I\${includedir} ${PIC}" >> ${pkgconfigFile}
${CAT} ${pkgconfigFile}
echo " -------------- "
echo
}
#-------------
C_config () {
setCDefaults
askCUserMisc
# makeCInstall
editCMakefile
[ $NOPROFILEYET = 1 ] && installProfile
writeCpkgconfigFile
}
#=====================================
#========= libsharp package ==========
#=====================================
# setSharpDefaults: default variables for libsharp
#-------------
setSharpDefaults () {
SHARPDIR=${HEALPIX}/src/common_libraries/libsharp
SHARPBLD=${SHARPDIR}/build
npgc=`$CC -V 2>&1 | ${GREP} PGI | ${WC} -l` # PGI C
if [ $npgc != 0 ] ; then
#SHARP_COPT="${SHARP_COPT--O3 -fast -mp}" # -O3 -fast -mp unless already defined
SHARP_COPT="${SHARP_COPT--O3 -fast}" # -O3 -fast unless already defined (-mp added by configure unless called with --disable-openmp)
else
#SHARP_COPT="-DMULTIARCH -O3 -ffast-math -fopenmp" # reserve for multiplatform compilation
#SHARP_COPT="${SHARP_COPT--O3 -ffast-math -march=native -fopenmp}" # -O3 -ffast-math -march=native -fopenmp unless already defined
SHARP_COPT="${SHARP_COPT--O3 -ffast-math -march=native}" # -O3 -ffast-math -march=native unless already defined (-fopenmp added by configure unless called with --disable-openmp)
fi
SHARP_LDFLAGS=""
if [ "${OS}" = "Darwin" -a `isTrue ${USE_ATRPATH}` -eq 1 ]; then
#SHARP_LDFLAGS="-Wl,-install_name,@rpath/libsharp.0.dylib"
SHARP_LDFLAGS="-Wl,-install_name,@rpath/libsharp.1.dylib"
#SHARP_LDFLAGS="-Wl,-install_name,@rpath/libsharp.1.dylib,-compatibility_version,1,-current_version,1"
# requires to add -Wl,-rpath,${HEALPIX}/lib to C++ flags ($CXXFLAGS)
fi
}
#-------------
askSharpUserMisc () {
echoLn "enter C compiler you want to use [$CC]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CC=$answer
nclang=`$CC --version 2>&1 | ${GREP} 'clang' | ${WC} -l`
echo "enter options for C compiler: "
echo "For optimal performance, this should include '-ffast-math'"
echo "and '-march=native' (in gcc or clang, or your compiler's equivalent options)."
echo "(If you are using gcc or clang and you want to produce a portable,"
echo "high-performance library, you can also replace '-march=native'"
echo "by '-DMULTIARCH'.)"
if [ $nclang != 0 ] ; then
echo "If your clang compiler supports OpenMP, include flags like -fopenmp=libiomp5"
else
echo "No need to include OpenMP flags, which will be dealt with later on."
fi
#echoLn "[$CFLAGS]: "
echoLn "[$SHARP_COPT]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && SHARP_COPT=$answer
echo "Do you want a parallel implementation of libsharp ?"
echo " 0) No (serial) "
echo " 1) Yes (parallel with OpenMP)"
echoLn "Enter choice [$SHARP_PARAL]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ ${SHARP_PARAL} -eq 0 -a `isTrue ${answer}` -eq 1 ] && SHARP_PARAL=1
[ ${SHARP_PARAL} -eq 1 -a `isFalse ${answer}` -eq 1 ] && SHARP_PARAL=0
if [ $SHARP_PARAL -eq 1 ] ; then
SHARPOPENMP="--enable-openmp"
echo "A parallel implementation of libsharp will be used"
else
SHARPOPENMP="--disable-openmp"
echo "A serial implementation of libsharp will be used"
fi
}
#-------------
editSharpMakefile () {
SHARPCDIR=${HEALPIX}/src/common_libraries/libsharp
SHARPBLD=${SHARPCDIR}/build
SHARPLIB=${SHARPLDIR}/libsharp.a
SHARPMKF=${SHARPBLD}/Makefile
echo
echo "Running configure in ${SHARPBLD} ... "
(\rm -rf ${SHARPBLD}; \
mkdir ${SHARPBLD}; \
cd ${SHARPBLD}; \
CC="${CC}" CFLAGS="${SHARP_COPT}" LDFLAGS="${SHARP_LDFLAGS}" ${SHARPCDIR}/configure --prefix=${SHARPPREFIX} ${SHARPOPENMP} || crashAndBurn) || crashAndBurn
echo "done."
echo
echo "edit top Makefile for libsharp ..."
mv -f Makefile Makefile_tmp
${CAT} Makefile_tmp |\
${SED} "s|^ALL\(.*\) sharp-void \(.*\)|ALL\1 sharp-all \2|" |\
${SED} "s|^TESTS\(.*\) sharp-void \(.*\)|TESTS\1 sharp-test \2|" |\
${SED} "s|^CLEAN\(.*\) sharp-void \(.*\)|CLEAN\1 sharp-clean \2|" |\
${SED} "s|^DISTCLEAN\(.*\) sharp-void \(.*\)|DISTCLEAN\1 sharp-distclean \2|" |\
${SED} "s|^TIDY\(.*\) sharp-void \(.*\)|TIDY\1 sharp-tidy \2|" |\
${SED} "s|^HEALPIX=.*$|HEALPIX = $HEALPIX|" |\
${SED} "s|^SHARPLDIR.*|SHARPLDIR=${SHARPLDIR}|" |\
${SED} "s|^SHARPBLD.*|SHARPBLD =${SHARPBLD}|" |\
${SED} "s|^SHARPLIB.*|SHARPLIB =${SHARPLIB}|" |\
${SED} "s|^SHARPMKF.*|SHARPMKF =${SHARPMKF}|" |\
${SED} "s|^# sharp configuration.*|# sharp configuration: (rm -rf ${SHARPBLD}; mkdir ${SHARPBLD}; cd ${SHARPBLD}; CC=\"${CC}\" CFLAGS=\"${SHARP_COPT}\" LDFLAGS=\"${SHARP_LDFLAGS}\" ${SHARPCDIR}/configure --prefix=${SHARPPREFIX} ${SHARPOPENMP})|" > Makefile
# mv -f Makefile Makefile_tmp
# ${CAT} Makefile_tmp |\
# ${SED} 's|^$(SHARPMKF).*$|$(SHARPMKF):\\
# mkdir -p $(SHARPBLD); \\\ \\
# \$(RM) -r $(SHARPBLD)/*; \\\ \\
# cd $(SHARPBLD); \\\\ \\
# CC=${CC} CFLAGS=${SHARP_COPT} LDFLAGS=${SHARP_LDFLAGS} ${SHARPCDIR}/configure --prefix=${SHARPPREFIX}; \\\ \\
# cd \$(HEALPIX)|' > Makefile
echo " done."
edited_makefile=1
}
#-------------
Sharp_config () {
setSharpDefaults
askSharpUserMisc
editSharpMakefile
}
#-------------
Sharp_install () {
echo
echo "Compiling and installing libsharp ..."
makejobs=''
ngnumake=`${MAKE} -v 2>&1 | ${GREP} GNU | ${WC} -l`
[ $ngnumake != 0 ] && makejobs='-j' # parallel make for GNUmake
( cd ${SHARPBLD} && ${MAKE} ${makejobs} install || crashAndBurn )
echo "done."
}
#-------------
test_Sharp () {
sharp_configured=0
if [ -s Makefile ] ; then
sharp_configured=`${CAT} Makefile | ${GREP} -c "^ALL\(.*\) sharp-all"`
fi
}
#=====================================
#=========== C++ package ===========
#=====================================
# setCppDefaults: defaults variables for C++
#-------------
setCppDefaults () {
#CFLAGS="-O3 -fopenmp"
CFLAGS="-O3"
CXXBLD=${CXXDIR}/build
CXX_LDFLAGS=""
# CXXFLAGS="${CXXFLAGS--O3 -fopenmp}" # -O3 -fopenmp unless already defined
CXXFLAGS="${CXXFLAGS--O3}" # -O3 unless already defined
if [ "${OS}" = "Darwin" -a `isTrue ${USE_ATRPATH}` -eq 1 ]; then
CXX_LDFLAGS="-Wl,-install_name,@rpath/libhealpix_cxx.2.dylib"
# requires to add -Wl,-rpath,${HEALPIX}/lib to C++ flags ($CXXFLAGS)
CXXFLAGS="${CXXFLAGS} -Wl,-rpath,${HEALPIX}/lib"
fi
}
#-------------
askCppUserMisc () {
echoLn "enter C compiler you want to use [$CC]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CC=$answer
echoLn "enter options for C compiler [$CFLAGS]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CFLAGS=$answer
echoLn "enter C++ compiler you want to use [$CXX]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CXX=$answer
ncxxlang=`$CXX --version 2>&1 | ${GREP} 'clang' | ${WC} -l`
if [ $ncxxlang != 0 ] ; then
echo "enter options for C++ compiler (if your clang compiler supports OpenMP, include flags like -fopenmp=libiomp5)."
else
echo "enter options for C++ compiler (no need to include OpenMP flags, which will be dealt with later on)."
fi
echoLn "[$CXXFLAGS]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CXXFLAGS=$answer
echo "Do you want a parallel implementation of HEALPix/C++ library and codes ?"
echo " 0) No (serial) "
echo " 1) Yes (parallel with OpenMP)"
echoLn "Enter choice [$CXX_PARAL]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ ${CXX_PARAL} -eq 0 -a `isTrue ${answer}` -eq 1 ] && CXX_PARAL=1
[ ${CXX_PARAL} -eq 1 -a `isFalse ${answer}` -eq 1 ] && CXX_PARAL=0
if [ $CXX_PARAL -eq 1 ] ; then
CXXOPENMP="--enable-openmp"
echo "A parallel implementation of HEALPix/C++ will be used"
else
CXXOPENMP="--disable-openmp"
echo "A serial implementation of HEALPix/C++ will be used"
fi
#echo "${FITSINC} ${FITSDIR}"
CFITSIO_CFLAGS=""
echoLn "enter path to fitsio.h"
if [ "$FITSINC" = "/usr/local/include" ]; then
echoLn ", in case of blank answer, autotools will look in standard locations []: "
read answer
else
echoLn " [$FITSINC]: "
read answer
[ "x$answer" = "x" ] && CFITSIO_CFLAGS="-I${FITSINC}"
fi
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CFITSIO_CFLAGS="-I$answer"
CFITSIO_LIBS=""
echoLn "enter path to cfitsio library"
if [ "$FITSDIR" = "/usr/local/lib" ]; then
echoLn ", in case of blank answer, autotools will look in standard locations []: "
read answer
else
echoLn "[$FITSDIR]: "
read answer
[ "x$answer" = "x" ] && CFITSIO_LIBS="-L${FITSDIR} -lcfitsio"
fi
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CFITSIO_LIBS="-L$answer -lcfitsio"
echo $CFITSIO_CFLAGS $CFITSIO_LIBS
}
#-------------
editCppMakefile () {
echo
echo "Running configure in ${CXXBLD} ... "
(\rm -rf ${CXXBLD}; \
mkdir ${CXXBLD}; \
cd ${CXXBLD}; \
CC="${CC}" CFLAGS="${CFLAGS}" CXX="${CXX}" CXXFLAGS="${CXXFLAGS}" LDFLAGS="${CXX_LDFLAGS}" SHARP_CFLAGS="-I${HEALPIX}/include" SHARP_LIBS="-L${HEALPIX}/lib -lsharp" CFITSIO_CFLAGS="${CFITSIO_CFLAGS}" CFITSIO_LIBS="${CFITSIO_LIBS}" ${CXXDIR}/configure --prefix=${CXXPREFIX} ${CXXOPENMP} || crashAndBurn)
echo "done"
echo
echo "edit top Makefile for C++ ..."
mv -f Makefile Makefile_tmp
${CAT} Makefile_tmp |\
${SED} "s|^ALL\(.*\) cpp-void \(.*\)|ALL\1 cpp-all \2|" |\
${SED} "s|^TESTS\(.*\) cpp-void \(.*\)|TESTS\1 cpp-test \2|" |\
${SED} "s|^CLEAN\(.*\) cpp-void \(.*\)|CLEAN\1 cpp-clean \2|" |\
${SED} "s|^DISTCLEAN\(.*\) cpp-void \(.*\)|DISTCLEAN\1 cpp-distclean \2|" |\
${SED} "s|^TIDY\(.*\) cpp-void \(.*\)|TIDY\1 cpp-tidy \2|" |\
${SED} "s|^HEALPIX=.*$|HEALPIX = $HEALPIX|" |\
${SED} "s|^CXXBLD.*|CXXBLD=${CXXBLD}|" > Makefile
mv -f Makefile Makefile_tmp
${CAT} Makefile_tmp |\
${SED} "s|^# C++ configuration.*$|# C++ configuration: (rm -rf ${CXXBLD} ; mkdir ${CXXBLD} ; cd ${CXXBLD}; CC=\"${CC}\" CFLAGS=\"${CFLAGS}\" CXX=\"${CXX}\" CXXFLAGS=\"${CXXFLAGS}\" LDFLAGS=\"${CXX_LDFLAGS}\" SHARP_CFLAGS=\"-I${HEALPIX}/include\" SHARP_LIBS=\"-L${HEALPIX}/lib -lsharp\" CFITSIO_CFLAGS=\"${CFITSIO_CFLAGS}\" CFITSIO_LIBS=\"${CFITSIO_LIBS}\" ${CXXDIR}/configure --prefix=${CXXPREFIX} ${CXXOPENMP})|"> Makefile
# mv -f Makefile Makefile_tmp
# ${CAT} Makefile_tmp |\
# ${SED} "s|^cpp-config.*$|cpp-config: sharp-all\\
# mkdir -p \$(CXXBLD); \\\ \\
# \$(RM) -r \$(CXXBLD)/*; \\\ \\
# cd \$(CXXBLD); \\\\ \\
# CC=\"${CC}\" CFLAGS=\"${CFLAGS}\" CXX=\"${CXX}\" CXXFLAGS=\"${CXXFLAGS}\" SHARP_CFLAGS=\"-I${HEALPIX}/include\" SHARP_LIBS=\"-L${HEALPIX}/lib -lsharp\" CFITSIO_CFLAGS=\"${CFITSIO_CFLAGS}\" CFITSIO_LIBS=\"${CFITSIO_LIBS}\" ${CXXDIR}/configure --prefix=${CXXPREFIX}; \\\ \\
# cd \$(HEALPIX)|" > Makefile
echo " done."
edited_makefile=1
}
#-------------
generateConfCppFile () {
echo "Generating $HPX_CONF_CPP"
echo "# C++ configuration for HEALPix `date`" > $HPX_CONF_CPP
case $SHELL in
csh|tcsh)
${CAT} <<EOF >>$HPX_CONF_CPP
setenv PATH \${HEALPIX}/bin:\${PATH}
EOF
;;
sh|ksh|bash|zsh)
${CAT} <<EOF >>$HPX_CONF_CPP
PATH="\${HEALPIX}/bin:\${PATH}"
export PATH
EOF
;;
*)
echo "Shell $SHELL not supported yet."
${RM} $HPX_CONF_CPP
;;
esac
}
#-------------
Cpp_config () {
test_Sharp
if [ $sharp_configured = "0" ] ; then
echo "Configuring the libsharp library first, since this is a dependency:"
Sharp_config
Sharp_install
echo
echo "Now configuring Healpix C++ itself:"
fi
HPX_CONF_CPP=$1
setCppDefaults
askCppUserMisc
generateConfCppFile
#installCppPackage
editCppMakefile
[ $NOPROFILEYET = 1 ] && installProfile
}
#=====================================
#=========== healpy Python package ===========
#=====================================
# #-------------
# Healpy_config () {
# # CFITSIO: make a first guess
# LIBFITS=cfitsio
# fullPath FITSDIR
# guess2=`${DIRNAME} ${FITSDIR}`
# guess3=`${DIRNAME} ${FITSINC}`
# findFITSPrefix $FITSDIR $FITSINC ${guess2} ${guess3}
# # ask user
# echo "Enter directory prefix for CFitsio"
# echoLn " ie containing lib/libcfitsio.* and include/fitsio.h ($FITSPREFIX): "
# read answer
# [ "x$answer" != "x" ] && FITSPREFIX=$answer
# # double check
# inc="${FITSPREFIX}/include/fitsio.h"
# if [ ! -r $inc ]; then
# echo "error: cfitsio include file $inc not found"
# crashAndBurn
# fi
# # apply
# editHealpyMakefile
# # update paths for C and C++
# FITSDIR=${FITSPREFIX}/lib
# FITSINC=${FITSPREFIX}/include
# }
# #-------------
# editHealpyMakefile () {
# echoLn "edit top Makefile for Python (healpy) ..."
# mv -f Makefile Makefile_tmp
# ${CAT} Makefile_tmp |\
# ${SED} "s|^ALL\(.*\) healpy-void\(.*\)|ALL\1 healpy-all \2|" |\
# ${SED} "s|^TESTS\(.*\) healpy-void\(.*\)|TESTS\1 healpy-test \2|" |\
# ${SED} "s|^CLEAN\(.*\) healpy-void\(.*\)|CLEAN\1 healpy-clean \2|" |\
# ${SED} "s|^DISTCLEAN\(.*\) healpy-void\(.*\)|DISTCLEAN\1 healpy-distclean \2|" |\
# ${SED} "s|^TIDY\(.*\) healpy-void\(.*\)|TIDY\1 healpy-tidy \2|" > Makefile
# echo " done."
# edited_makefile=1
# }
#-------------
Healpy_config () { # for healpy >= 1.7.0
HPY_PYTHON="$PYTHON"
tmpfile=to_be_removed
HPY_SETUP='setup.py' # default setup
HPY_SETUP2='setup2.py' # backup setup
HPY_DIR='src/healpy/'
# ask for python command
echoLn "Enter python command [$HPY_PYTHON] "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && HPY_PYTHON="$answer"
# test python version number
${HPY_PYTHON} --version 1> ${tmpfile} 2>&1
#python_version=`${CAT} ${tmpfile} | ${AWK} '{print \$NF}'` # current version (last field)
python_version=`${CAT} ${tmpfile} | ${AWK} '{print \$2}'` # current version (2nd field)
#python_reqrd="2.4" # minimal version supported
#python_reqrd="2.6" # minimal version supported
#python_reqrd="2.7" # minimal version supported (1.12.8)
#python_reqrd="3.6" # minimal version supported (1.15.0)
python_reqrd="3.9" # minimal version supported (1.17.3)
#p_v1=`echo ${python_version} | ${AWK} '{print $1*10}'` # does not work properly for eg 3.10
#p_v2=`echo ${python_reqrd} | ${AWK} '{print $1*10}'`
p_v1=`echo ${python_version} | ${AWK} -F. '{print $1*10000+$2*100+$3}'`
p_v2=`echo ${python_reqrd} | ${AWK} -F. '{print $1*10000+$2*100+$3}'`
${RM} ${tmpfile}
if [ ${p_v1} -lt ${p_v2} ]; then
echo
echo "Python version (${python_version}) must be >= ${python_reqrd}"
echo
crashAndBurn
fi
# # special treatement for MacOSX
# if [ "${OS}" = "Darwin" ]; then
# # find out compiler and options used by python (and therefore healpy in setup.py)
# HPY_CC=`${HPY_PYTHON} -c "from distutils.sysconfig import get_config_var ; print get_config_var('CC')"`
# HPY_OPTS=`${HPY_PYTHON} -c "from distutils.sysconfig import get_config_var ; print get_config_var('CFLAGS')"`
# # test these options on a C code
# ${CAT} > ${tmpfile}.c <<EOF
# int main(){
# }
# EOF
# ${HPY_CC} -E ${HPY_OPTS} ${tmpfile}.c -o ${tmpfile}.p 1>${DEVNULL} 2>&1
# # if test fails, create back up setup2.py and make sure it will be used
# if [ ! -e ${tmpfile}.p ] ; then
# cat ${HPY_DIR}${HPY_SETUP} | \
# sed "s|'--disable-shared',|'--disable-shared', '--disable-dependency-tracking',|g" > \
# ${HPY_DIR}${HPY_SETUP2}
# HPY_SETUP=${HPY_SETUP2}
# fi
# # clean up
# ${RM} ${tmpfile}.*
# fi
echoLn "enter C compiler you want to use [$CC]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CC=$answer
HPY_CC="${CC}"
echoLn "enter C++ compiler you want to use [$CXX]: "
read answer
[ $INTERACTIVE -eq 0 ] && echo $answer
[ "x$answer" != "x" ] && CXX=$answer
HPY_CXX="${CXX}"
# apply
editHealpyMakefile
}
#-------------
editHealpyMakefile () {
echo
echo "edit top Makefile for Python (healpy) ..."