forked from austinschneider/nuSQuIDS_LV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·881 lines (756 loc) · 29.8 KB
/
configure
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
#!/bin/bash
check_pkgconfig(){
if [ "$CHECKED_PKGCONFIG" ]; then return; fi
echo "Looking for pkg-config..."
PKG_CONFIG_PATH=$(which pkg-config 2>&1)
if [ "$?" -ne 0 ]; then
echo "Error: pkg-config not found; you will need to specify library locations manually" 1>&2
exit 1
fi
echo " Found $PKG_CONFIG_PATH"
CHECKED_PKGCONFIG=1
}
find_package(){
PKG=$1
VAR_PREFIX=`echo $PKG | tr [:lower:] [:upper:]`
TMP_FOUND=`eval echo "$"${VAR_PREFIX}_FOUND`
if [ "$TMP_FOUND" ]; then return; fi
check_pkgconfig
echo "Looking for $PKG..."
pkg-config --exists $PKG
if [ "$?" -ne 0 ]; then
echo " $PKG not found with pkg-config"
return
fi
if [ $# -ge 2 ]; then
MIN_VERSION=$2
pkg-config --atleast-version $MIN_VERSION $PKG
if [ "$?" -ne 0 ]; then
echo "Error: installed $PKG version ("`pkg-config --modversion $PKG`") is too old; version >=$MIN_VERSION is required" 1>&2
exit 1
fi
fi
echo " Found $PKG version `pkg-config --modversion $PKG`"
eval ${VAR_PREFIX}_FOUND=1
eval ${VAR_PREFIX}_VERSION=\"`pkg-config --modversion $PKG`\"
eval ${VAR_PREFIX}_CFLAGS=\"`pkg-config --cflags $PKG`\"
eval ${VAR_PREFIX}_LDFLAGS=\"`pkg-config --libs $PKG`\"
eval ${VAR_PREFIX}_INCDIR=\"`pkg-config --variable=includedir $PKG`\"
eval ${VAR_PREFIX}_LIBDIR=\"`pkg-config --variable=libdir $PKG`\"
}
find_hdf5(){
PKG=hdf5
echo "Looking for $PKG..."
VAR_PREFIX=`echo $PKG | tr [:lower:] [:upper:]`
TMP_FOUND=`eval echo "$"${VAR_PREFIX}_FOUND`
if [ "$TMP_FOUND" ]; then return; fi
which h5cc 2>&1 > /dev/null
if [ "$?" -ne 0 ]; then return; fi
which h5ls 2>&1 > /dev/null
if [ "$?" -eq 0 ]; then
HDF5_VERSION=`h5ls --version | sed 's/.* \([0-9.]*\)/\1/'`
echo " Found $PKG version $HDF5_VERSION via executables in \$PATH"
if [ $# -ge 1 ]; then
MIN_VERSION=$1
#TODO: actually check version
fi
else
echo " h5ls not found; cannot check $PKG version"
echo " Proceeding with unknown version and hoping for the best"
fi
HDF5_COMPILE_COMMAND=`h5cc -show`
for item in $HDF5_COMPILE_COMMAND; do
item=`echo "$item" | sed 's| |\n|g' | sed -n 's/.*-L\([^ ]*\).*/\1/p'`
if [ -n "$item" ]; then
POSSIBLE_HDF5_LIBDIRS="$POSSIBLE_HDF5_LIBDIRS
$item"
fi
done
for HDF5_LIBDIR in $POSSIBLE_HDF5_LIBDIRS; do
if [ -d $HDF5_LIBDIR -a \( -e $HDF5_LIBDIR/libhdf5.a -o -e $HDF5_LIBDIR/libhdf5.so \) ]; then
break
fi
done
if [ ! -d $HDF5_LIBDIR -o ! \( -e $HDF5_LIBDIR/libhdf5.a -o -e $HDF5_LIBDIR/libhdf5.so \) ]; then
echo " Unable to guess $PKG library directory"
return
fi
POSSIBLE_HDF5_INCDIRS=`echo "$HDF5_COMPILE_COMMAND" | sed 's| |\n|g' | sed -n 's/.*-I\([^ ]*\).*/\1/p'`
POSSIBLE_HDF5_INCDIRS="$POSSIBLE_HDF5_INCDIRS ${HDF5_LIBDIR}/../include"
for HDF5_INCDIR in $POSSIBLE_HDF5_INCDIRS; do
if [ -d $HDF5_INCDIR -a -e $HDF5_INCDIR/H5version.h ]; then
break
fi
done
if [ ! -d $HDF5_INCDIR -o ! $HDF5_INCDIR/H5version.h ]; then
echo " Unable to guess $PKG include directory"
return
fi
HDF5_CFLAGS="-I${HDF5_INCDIR}"
HDF5_LDFLAGS=`echo "$HDF5_COMPILE_COMMAND" | \
sed 's/ /\\
/g' | \
sed -n -E \
-e '/^[[:space:]]*-l/p' \
-e '/^[[:space:]]*-L/p' \
-e '/^[[:space:]]*-Wl,/p' \
-e 's/^[[:space:]]*.*lib([^.]*)\.a/-l\1/p' \
-e 's/^[[:space:]]*.*lib([^.]*)\.so/-l\1/p' \
-e 's/^[[:space:]]*.*lib([^.]*)\.dylib/-l\1/p' `
HDF5_LDFLAGS=`echo $HDF5_LDFLAGS` # collapse to single line
HDF5_FOUND=1
}
# less searching for python than verfying that the given executable works and extracting relevant paths
try_find_python(){
echo "Looking for python"
if which ${PYTHON_EXE} > /dev/null 2>&1; then
PYTHON_EXE=$(which ${PYTHON_EXE} 2>/dev/null)
echo " Using python executable ${PYTHON_EXE}"
else
echo " ${PYTHON_EXE} is not a valid python executable"
return
fi
PYTHON_VERSION=`${PYTHON_EXE} -c 'import sys; print(str(sys.version_info.major)+"."+str(sys.version_info.minor))'`
if [ "$?" -ne 0 ]; then
echo "Unable to use python executable ${PYTHON_EXE} (version check failed)"
return
fi
PYTHONVERSIONSIMPLE=`${PYTHON_EXE} -c 'import sys; print(str(sys.version_info.major)+str(sys.version_info.minor))'`
PYTHON_INCDIR=`${PYTHON_EXE} -c 'from distutils import sysconfig; print(sysconfig.get_python_inc())'`
if [ -d "$PYTHON_INCDIR" ]; then
echo " Found python include dir $PYTHON_INCDIR"
else
echo " Unable to locate the python include dir"
return
fi
# This is the directory to which libraries should be installed for python to find them
PYTHON_MODULEDIR=`${PYTHON_EXE} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib(plat_specific=True, standard_lib=False))'`
if [ "$PYTHON_MODULEDIR" ]; then
echo " Python module install dir is $PYTHON_MODULEDIR"
else
echo " Unable to locate the python module dir"
return
fi
# This is the directory that python claims contains its standard library,
# which may or may not include the actual libpython
PYTHON_STDLIBDIR=`${PYTHON_EXE} -c 'from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True,standard_lib=True))'`
# This may contain a suffix which appears after the version like in 'libpython3.6m'
# See https://www.python.org/dev/peps/pep-3149/#proposal
PYTHONLIBSUFFIX=`${PYTHON_EXE} -c 'from distutils import sysconfig; print(sysconfig.build_flags)' 2>/dev/null`
# Here we just try to guess every location anyone has ever seen a libpython in the wild
POSSIBLE_PYTHON_LIBDIRS="/lib /lib64 /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 ${PYTHON_STDLIBDIR} ${PYTHON_STDLIBDIR}/lib"
# sometimes Apple puts a symlink in ${PYTHONSTDLIBDIR}/lib, sometimes it doesn't
TMP=`echo "$PYTHON_STDLIBDIR" | sed -n s'|\(.*/lib\)/python'"${PYTHON_VERSION}"'|\1|p'`
if [ "$TMP" ]; then POSSIBLE_PYTHON_LIBDIRS="${POSSIBLE_PYTHON_LIBDIRS} ${TMP}"; fi
# Ubuntu is special, of course
if uname -a | grep -i 'ubuntu' > /dev/null; then
POSSIBLE_PYTHON_LIBDIRS="${POSSIBLE_PYTHON_LIBDIRS} /usr/lib/$(uname -i)-linux-gnu"
fi
for PYTHON_LIBDIR in $POSSIBLE_PYTHON_LIBDIRS; do
for PV in $PYTHON_VERSION $PYTHONVERSIONSIMPLE; do
#echo " Looking for ${PYTHON_LIBDIR}/libpython${PV}${PYTHONLIBSUFFIX}.(a|so|dylib)"
if [ -d $PYTHON_LIBDIR ]; then
if [ -e ${PYTHON_LIBDIR}/libpython${PV}${PYTHONLIBSUFFIX}.a ]; then
PYTHON_LIBRARY=${PYTHON_LIBDIR}/libpython${PV}${PYTHONLIBSUFFIX}.a
break
elif [ -e ${PYTHON_LIBDIR}/libpython${PV}${PYTHONLIBSUFFIX}.so ];then
PYTHON_LIBRARY=${PYTHON_LIBDIR}/libpython${PV}${PYTHONLIBSUFFIX}.so
break
elif [ -e ${PYTHON_LIBDIR}/libpython${PV}${PYTHONLIBSUFFIX}.dylib ]; then
PYTHON_LIBRARY=${PYTHON_LIBDIR}/libpython${PV}${PYTHONLIBSUFFIX}.dylib
break
fi
fi
done
done
if [ -e "$PYTHON_LIBRARY" ]; then
echo " Found python library $PYTHON_LIBRARY"
else
echo " Unable to locate the python library"
return
fi
PYTHON_CFLAGS="-I${PYTHON_INCDIR}"
PYTHON_LDFLAGS="-L${PYTHON_LIBDIR} -l$(echo "$PYTHON_LIBRARY" | sed 's|.*lib\(python.*\)\.[a-z]*|\1|')"
PYTHON_FOUND=1
}
try_find_boost(){
PKG=boost
VAR_PREFIX=`echo $PKG | tr [:lower:] [:upper:]`
TMP_FOUND=`eval echo "$"${VAR_PREFIX}_FOUND`
if [ "$TMP_FOUND" ]; then return; fi
if [ "$PYTHON_FOUND" ]; then
PYV=`${PYTHON_EXE} -c 'import sys; print(str(sys.version_info.major)+str(sys.version_info.minor))'`
PYVM=`${PYTHON_EXE} -c 'import sys; print(sys.version_info.major)'`
echo "Looking for $PKG built for python ${PYV} in $GUESS_DIR..."
else
echo "Looking for $PKG in $GUESS_DIR..."
fi
if [ "$#" -eq 1 ]; then
GUESS_DIR=$1
POSSIBLE_BOOST_LIBDIRS="${GUESS_DIR}/lib ${GUESS_DIR}/lib64 ${GUESS_DIR}/lib/x86_64-linux-gnu"
POSSIBLE_BOOST_INCDIRS="${GUESS_DIR}/include"
elif [ "$#" -eq 2 ]; then
GUESS_DIR="$1 and $2"
POSSIBLE_BOOST_LIBDIRS="$2"
POSSIBLE_BOOST_INCDIRS="$1"
else
echo "Wrong number of arguments to try_find_boost"
return
fi
if [ "$PYTHON_FOUND" ]; then
for PYV_SUFFIX in $PYV $PYVM ''; do
for BOOST_LIBDIR in $POSSIBLE_BOOST_LIBDIRS; do
if [ -d $BOOST_LIBDIR -a \( -e $BOOST_LIBDIR/libboost_python${PYV_SUFFIX}.a -o -e $BOOST_LIBDIR/libboost_python${PYV_SUFFIX}.so -o -e $BOOST_LIBDIR/libboost_python${PYV_SUFFIX}.dylib \) ]; then
if [ ! "$PYV_SUFFIX" ]; then
echo " Found boost_python with no python version tag; hoping it is compatible"
fi
BOOST_PYTHON_FOUND=1
BOOST_PYTHON_LDFLAGS="-lboost_python${PYV_SUFFIX}"
break
fi
done
if [ "$BOOST_PYTHON_FOUND" ]; then break; fi
done
if [ ! "$BOOST_PYTHON_FOUND" ]; then
echo " Unable to locate the boost_python library in $GUESS_DIR"
fi
fi
for BOOST_INCDIR in $POSSIBLE_BOOST_INCDIRS; do
if [ -d $BOOST_INCDIR -a -e $BOOST_INCDIR/boost/version.hpp ]; then
break
fi
done
if [ ! -d "$BOOST_INCDIR" -o ! -e "$BOOST_INCDIR/boost/version.hpp" ]; then
echo " Unable to locate boost/version.hpp in $GUESS_DIR"
return
fi
BOOST_CFLAGS="-I${BOOST_INCDIR}"
BOOST_LDFLAGS="-Wl,-rpath -Wl,${BOOST_LIBDIR} -L${BOOST_LIBDIR}"
BOOST_FOUND=1
echo " Found boost in $GUESS_DIR"
echo " Boost include directory is ${BOOST_INCDIR}"
if [ "$BOOST_LIBDIR" ]; then
echo " Boost library directory is ${BOOST_LIBDIR}"
fi
}
find_numpy(){
echo "Looking for numpy..."
NUMPY_INCDIR=$(${PYTHON_EXE} -c 'import numpy; print(numpy.get_include())')
if [ "$?" -ne 0 ]; then
echo "Unable to import numpy using ${PYTHON_EXE}"
return
fi
NUMPY_CFLAGS="-I${NUMPY_INCDIR}"
NUMPY_FOUND=1
echo " Found numpy"
echo " Numpy include directory is ${NUMPY_INCDIR}"
}
ensure_found(){
PKG=$1
VAR_PREFIX=`echo $PKG | tr [:lower:] [:upper:]`
TMP_FOUND=`eval echo "$"${VAR_PREFIX}_FOUND`
if [ "$TMP_FOUND" ]; then return; fi
#not found
lowername=`echo $PKG | tr [A-Z] [a-z]`
TMP_INCDIR=`eval echo "$"${VAR_PREFIX}_INCDIR`
TMP_LIBDIR=`eval echo "$"${VAR_PREFIX}_LIBDIR`
if [ "$TMP_INCDIR" -a "$TMP_LIBDIR" ]; then
echo "Error: $PKG not found in $TMP_INCDIR and $TMP_LIBDIR or with pkg-config" 1>&2
echo "Please verify that the path given to --with-${lowername} is correct" 1>&2
else
echo "Error: $PKG not installed or not registered with pkg-config" 1>&2
echo "Please specify location using the --with-${lowername} flag" 1>&2
fi
unset TMP_INCDIR
unset TMP_LIBDIR
exit 1
}
PREFIX=/usr/local
INSTALL_LIBDIR=lib
VERSION_NUM=101100
VERSION=`echo $VERSION_NUM | awk '{
major = int($1/100000);
minor = int($1/100)%1000;
patch = $1%100;
print major"."minor"."patch;
}'`
OS_NAME=`uname -s`
GUESS_CC=gcc
GUESS_CXX=g++
GUESS_AR=ar
GUESS_LD=ld
if [ "$OS_NAME" = Linux ]; then
DYN_SUFFIX=.so
DYN_OPT='-shared -Wl,-soname,$(shell basename $(DYN_PRODUCT))'
DYN_OPT_PY='-shared -Wl,-soname,$(shell basename $(PYTHON_LIB))'
fi
if [ "$OS_NAME" = Darwin ]; then
GUESS_CC=clang
GUESS_CXX=clang++
GUESS_LD=clang++
DYN_SUFFIX=.dylib
DYN_OPT='-dynamiclib -compatibility_version $(VERSION) -current_version $(VERSION)'
DYN_OPT_PY='-dynamiclib -compatibility_version $(VERSION) -current_version $(VERSION)'
fi
CC=${CC-$GUESS_CC}
CXX=${CXX-$GUESS_CXX}
AR=${AR-$GUESS_AR}
LD=${LD-$GUESS_LD}
PYTHON_EXE="python"
if which "$PYTHON_EXE" > /dev/null 2>&1; then
: # good, keep our initial guess
elif which "python3" > /dev/null 2>&1; then
PYTHON_EXE="python3"
fi
HELP="Usage: ./configure [OPTION]...
Installation directories:
--prefix=PREFIX install files in PREFIX
[$PREFIX]
By default, \`make install' will install all the files in
\`$PREFIX/bin', \`$PREFIX/lib' etc. You can specify
an installation prefix other than \`$PREFIX' using \`--prefix',
for instance \`--prefix=\$HOME'.
Fine tuning of the installation directories:
--libdir=DIR object code libraries [lib]
The following options can be used to maunally specify the
locations of dependencies:
--with-gsl=DIR use the copy of GSL in DIR
assuming headers are in DIR/include
and libraries in DIR/lib
--with-gsl-incdir=DIR use the copy of GSL in DIR
--with-gsl-libdir=DIR use the copy of GSL in DIR
--with-hdf5=DIR use the copy of HDF5 in DIR
assuming headers are in DIR/include
and libraries in DIR/lib
--with-hdf5-incdir=DIR use the copy of HDF5 in DIR
--with-hdf5-libdir=DIR use the copy of HDF5 in DIR
--with-squids=DIR use the copy of SQuIDS in DIR
assuming headers are in DIR/include
and libraries in DIR/lib
--with-squids-incdir=DIR use the copy of SQuIDS in DIR
--with-squids-libdir=DIR use the copy of SQuIDS in DIR
For the python bindings the following flags are used:
--with-python-bindings enable python binding compilation
--with-boost-incdir=DIR use the copy of Boost in DIR
--with-boost-libdir=DIR use the copy of Boost in DIR
--with-boost=DIR use the copy of Boost in DIR
assuming headers are in DIR/include
and libraries in DIR/lib
--python-bin=PYTHON_EXECUTABLE use this python executable
(default is 'python')
--python-module-dir=DIR install python module to this directory, rather
than the default system location. The special
value site.USER_SITE will be automatically
expanded using the python interpreter
Some influential environment variables:
CC C compiler command
CXX C++ compiler command
AR Static linker command
LD Dynamic linker command
" #`
for var in "$@"
do
if [ "$var" = "--help" -o "$var" = "-h" ]; then
echo "$HELP"
exit 0
fi
TMP=`echo "$var" | sed -n 's/^--prefix=\(.*\)$/\1/p'`
if [ "$TMP" ]; then PREFIX="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--libdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then INSTALL_LIBDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-gsl=\(.*\)$/\1/p'`
if [ "$TMP" ]; then
GSL_INCDIR="${TMP}/include";
GSL_LIBDIR="${TMP}/lib";
continue; fi
TMP=`echo "$var" | sed -n 's/^--with-gsl-incdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then GSL_INCDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-gsl-libdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then GSL_LIBDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-hdf5=\(.*\)$/\1/p'`
if [ "$TMP" ]; then
HDF5_INCDIR="${TMP}/include";
HDF5_LIBDIR="${TMP}/lib";
continue; fi
TMP=`echo "$var" | sed -n 's/^--with-hdf5-incdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then HDF5_INCDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-hdf5-libdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then HDF5_LIBDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-squids=\(.*\)$/\1/p'`
if [ "$TMP" ]; then
SQUIDS_INCDIR="${TMP}/include";
SQUIDS_LIBDIR="${TMP}/lib";
continue; fi
TMP=`echo "$var" | sed -n 's/^--with-squids-incdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then SQUIDS_INCDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-squids-libdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then SQUIDS_LIBDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-python-bindings/true/p'`
if [ "$TMP" ]; then PYTHON_BINDINGS=true; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-boost=\(.*\)$/\1/p'`
if [ "$TMP" ]; then
BOOST_INCDIR="${TMP}/include";
BOOST_LIBDIR="${TMP}/lib";
continue; fi
TMP=`echo "$var" | sed -n 's/^--with-boost-libdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then BOOST_LIBDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--with-boost-incdir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then BOOST_INCDIR="$TMP"; continue; fi
TMP=`echo "$var" | sed -n 's/^--python-bin=\(.*\)$/\1/p'`
if [ "$TMP" ]; then PYTHON_EXE=$TMP; continue; fi
TMP=`echo "$var" | sed -n 's/^--python-module-dir=\(.*\)$/\1/p'`
if [ "$TMP" ]; then USER_PYTHON_MODULE_DIR="${TMP}"; continue; fi
echo "config.sh: Unknown or malformed option '$var'" 1>&2
exit 1
done
if [ "$GSL_INCDIR" -a "$GSL_LIBDIR" ]; then
echo "Checking manually specified GSL..."
if [ -d "$GSL_INCDIR/gsl" \
-a -e "$GSL_INCDIR/gsl/gsl_version.h" \
-a -d "$GSL_LIBDIR" \
-a -e "$GSL_LIBDIR/libgsl.a" ]; then
GSL_FOUND=1
GSL_CFLAGS="-I$GSL_INCDIR"
GSL_LDFLAGS="-L$GSL_LIBDIR -lgsl -lgslcblas -lm"
else
echo "Warning: manually specifed GSL not found; will attempt auto detection"
fi
fi
find_package gsl 1.15
if [ "$HDF5_INCDIR" -a "$HDF5_LIBDIR" ]; then
echo "Checking manually specified HDF5..."
if [ -d "$HDF5_INCDIR" \
-a -e "$HDF5_INCDIR/H5version.h" \
-a -d "$HDF5_LIBDIR" \
-a -e "$HDF5_LIBDIR/libhdf5.a" \
-a -e "$HDF5_LIBDIR/libhdf5_hl.a" ]; then
HDF5_FOUND=1
HDF5_CFLAGS="-I$HDF5_INCDIR"
HDF5_LDFLAGS="-L$HDF5_LIBDIR -lhdf5 -lhdf5_hl"
else
echo "Warning: manually specifed HDF5 not found; will attempt auto detection"
fi
fi
#Do not use this due to broken Ubuntu package
#find_package hdf5 1.8
find_hdf5
if [ "$SQUIDS_INCDIR" -a "$SQUIDS_LIBDIR" ]; then
echo "Checking manually specified SQUIDS..."
if [ -d "$SQUIDS_INCDIR" \
-a -d "$SQUIDS_LIBDIR" \
-a -e "$SQUIDS_LIBDIR/libSQuIDS.a" ]; then
SQUIDS_FOUND=1
SQUIDS_CFLAGS="-I$SQUIDS_INCDIR"
SQUIDS_LDFLAGS="-L$SQUIDS_LIBDIR -lSQuIDS"
if $CXX --version | grep -q "Free Software Foundation"; then
SQUIDS_CFLAGS="$SQUIDS_CFLAGS -Wno-abi"
fi
else
echo "Warning: manually specifed SQUIDS not found; will attempt auto detection"
fi
fi
find_package squids 1.2
if [ $PYTHON_BINDINGS ]; then
try_find_python
if [ "$PYTHON_FOUND" != 1 ]; then
echo "*** Failed to find python; python bindings will not be built ***"
unset PYTHON_BINDINGS
else
if [ "$USER_PYTHON_MODULE_DIR" ]; then
if [ "$USER_PYTHON_MODULE_DIR" == "site.USER_SITE" ]; then
PYTHON_MODULEDIR=`${PYTHON_EXE} -c 'import site; print(site.USER_SITE)'`
else
PYTHON_MODULEDIR="$USER_PYTHON_MODULE_DIR"
fi
fi
fi
if [ "$BOOST_INCDIR" -a "$BOOST_LIBDIR" ]; then
echo "Checking manually specified boost..."
try_find_boost "$BOOST_INCDIR" "$BOOST_LIBDIR"
if [ ! "$BOOST_FOUND" ]; then
echo "Warning: manually specifed boost not found; will attempt auto detection"
fi
fi
try_find_boost /usr
try_find_boost /usr/local
if [ "$BOOST_PYTHON_FOUND" != 1 ]; then
echo "*** Failed to find boost python; python bindings will not be built ***"
unset PYTHON_BINDINGS
fi
find_numpy
if [ "$NUMPY_FOUND" != 1 ]; then
echo "*** Failed to find numpy; python bindings will not be built ***"
unset PYTHON_BINDINGS
fi
fi
ensure_found gsl
ensure_found hdf5
ensure_found squids
# Resolve PREFIX absolutely
OLDPWD=`pwd`
cd "$PREFIX"
PREFIX=`pwd`
cd "$OLDPWD"
SOURCE_PATH=`pwd`
if [ ! -d ./build/ ]; then
mkdir build;
fi
if [ ! -d ./lib/ ]; then
mkdir lib;
fi
echo "Generating config file..."
# Somewhat evil: HDF5 does not register with pkg-config, which causes the latter
# to error out because it cannot find nuSQuIDS dependencies.
# Solution: Since we found HDF5 (hopefully correctly), register it ourselves.
echo "# WARNING: This configuration file was heutristically generated by nuSQuIDS
# and may not be complete or correct
libdir=${HDF5_LIBDIR}
includedir=${HDF5_INCDIR}" > lib/hdf5.pc
echo '
Name: HDF5
Description: "A data model, library, and file format for storing and managing data."
URL: https://www.hdfgroup.org/HDF5/' >> lib/hdf5.pc
echo "Version: ${HDF5_VERSION}" >> lib/hdf5.pc
echo "Cflags: ${HDF5_CFLAGS}
Libs: ${HDF5_LDFLAGS}
" >> lib/hdf5.pc
echo "prefix=$PREFIX" > lib/nusquids.pc
echo '
libdir=${prefix}/'"$INSTALL_LIBDIR"'
includedir=${prefix}/include
Name: nuSQuIDS
Description: Toolbox for neutrino oscillation experiments
URL: https://github.com/arguelles/nuSQuIDS' >> lib/nusquids.pc
echo "Version: $VERSION" >> lib/nusquids.pc
echo 'Requires: gsl >= 1.15 hdf5 >= 1.8 squids >= 1.2.0
Libs: -L${libdir} -lnuSQuIDS
Cflags: -I${includedir}
' >> lib/nusquids.pc
echo "Generating version header..."
sed -e "s|__NUSQUIDS_VERSION__|$VERSION_NUM|g" \
-e "s|__NUSQUIDS_VERSION_STR__|$VERSION|g" \
< resources/version.h.in > include/nuSQuIDS/version.h
INSTALL_FLAG_PREFIX="NUSQUIDS_DATA_PATH_INSTALL_FLAG_PREFIX_"
INSTALL_FLAG_SUFFIX="_NUSQUIDS_DATA_PATH_INSTALL_FLAG_SUFFIX"
INSTALL_FLAG_OFF="A"
INSTALL_FLAG_ON="B"
REPLACE_INSTALL_FLAG="s|${INSTALL_FLAG_PREFIX}${INSTALL_FLAG_OFF}${INSTALL_FLAG_SUFFIX}|${INSTALL_FLAG_PREFIX}${INSTALL_FLAG_ON}${INSTALL_FLAG_SUFFIX}|g"
echo "Generating data path header..."
echo "#include <cstring>
#define SOURCE_DATA_PATH \"${SOURCE_PATH}/data/\"
#define INSTALL_DATA_PATH \"${PREFIX}/share/nuSQuIDS/\"
namespace{
const char dataPathBitOffValue='$INSTALL_FLAG_OFF';
//This needs to be volatile so that the compiler can't optimize away reads from it,
//which is important since we plan to change the value of the constant between compile-time
//and run-time
const volatile char dataPathBitContainer[] = \"${INSTALL_FLAG_PREFIX}${INSTALL_FLAG_OFF}${INSTALL_FLAG_SUFFIX}\";
bool getInstallBit(){
static const std::size_t prefixLen = strlen(\"${INSTALL_FLAG_PREFIX}\");
return dataPathBitContainer[prefixLen]!='${INSTALL_FLAG_OFF}';
}
}
" > build/resource_paths.h
echo "Generating makefile..."
echo "# Compiler
CC=$CC
CXX=$CXX
AR=$AR
LD=$LD
DYN_SUFFIX=$DYN_SUFFIX
DYN_OPT=$DYN_OPT
DYN_OPT_PY=$DYN_OPT_PY
VERSION=$VERSION
PREFIX=$PREFIX
INSTALL_LIBDIR:=$INSTALL_LIBDIR
" > ./Makefile
echo '
PATH_nuSQUIDS=$(shell pwd)
PATH_SQUIDS=$(SQUIDS_DIR)
SOURCES = $(wildcard src/*.cpp)
OBJECTS = $(patsubst src/%.cpp,build/%.o,$(SOURCES))
EXAMPLES := examples/Single_energy/single_energy \
examples/Multiple_energy/multiple_energy \
examples/Atm_default/atm_default \
examples/Bodies/bodies \
examples/Xsections/xsections \
examples/NSI/nsi \
examples/LV/lv \
examples/Atm_BSM/atm_bsm\
examples/HDF5_Write_Read/write \
examples/HDF5_Write_Read/read \
examples/Constant_density_layers/const_dens_layers \
examples/Astrophysical_neutrino_flavor_ratio/astro_flv_ratio
CXXFLAGS= -std=c++11
# Directories
' >> ./Makefile
echo "GSL_CFLAGS=$GSL_CFLAGS" >> ./Makefile
echo "GSL_LDFLAGS=$GSL_LDFLAGS" >> ./Makefile
echo "HDF5_CFLAGS=$HDF5_CFLAGS" >> ./Makefile
echo "HDF5_LDFLAGS=$HDF5_LDFLAGS" >> ./Makefile
echo "SQUIDS_CFLAGS=$SQUIDS_CFLAGS" >> ./Makefile
echo "SQUIDS_LDFLAGS=$SQUIDS_LDFLAGS" >> ./Makefile
if [ "$PYTHON_BINDINGS" ]; then
echo "PYTHON_CFLAGS=$PYTHON_CFLAGS" >> ./Makefile
echo "PYTHON_LDFLAGS=$PYTHON_LDFLAGS" >> ./Makefile
echo "BOOST_PYTHON_LDFLAGS=$BOOST_PYTHON_LDFLAGS" >> ./Makefile
echo "PYTHON_MODULEDIR=$PYTHON_MODULEDIR" >> ./Makefile
echo "NUMPY_CFLAGS=$NUMPY_CFLAGS" >> ./Makefile
fi
echo '
INCnuSQUIDS=$(PATH_nuSQUIDS)/include
LIBnuSQUIDS=$(PATH_nuSQUIDS)/lib
# FLAGS
CFLAGS= -O3 -fPIC -Ibuild -I$(INCnuSQUIDS) $(SQUIDS_CFLAGS) $(GSL_CFLAGS) $(HDF5_CFLAGS)
LDFLAGS= -Wl,-rpath -Wl,$(LIBnuSQUIDS) -L$(LIBnuSQUIDS)
LDFLAGS+= $(SQUIDS_LDFLAGS) $(GSL_LDFLAGS) $(HDF5_LDFLAGS) -lpthread
EXAMPLES_FLAGS=-I$(INCnuSQUIDS) $(CXXFLAGS) $(CFLAGS)
# Project files
NAME=nuSQuIDS
STAT_PRODUCT=lib/lib$(NAME).a
DYN_PRODUCT=lib/lib$(NAME)$(DYN_SUFFIX)
PYTHON_LIB:=lib/$(NAME).so
# Compilation rules
all: $(STAT_PRODUCT) $(DYN_PRODUCT)
examples : $(EXAMPLES)
$(DYN_PRODUCT) : $(OBJECTS)
@echo Linking $(DYN_PRODUCT)
@$(CXX) $(DYN_OPT) $(OBJECTS) $(LDFLAGS) -o $(DYN_PRODUCT)
$(STAT_PRODUCT) : $(OBJECTS)
@echo Linking $(STAT_PRODUCT)
@$(AR) -rcs $(STAT_PRODUCT) $(OBJECTS)
build/%.o : src/%.cpp
@echo Compiling $< to $@
@$(CXX) $(CXXFLAGS) -c $(CFLAGS) $< -o $@
examples/Single_energy/single_energy : $(DYN_PRODUCT) examples/Single_energy/main.cpp
@echo Compiling single energy example
@$(CXX) $(EXAMPLES_FLAGS) examples/Single_energy/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@
examples/Astrophysical_neutrino_flavor_ratio/astro_flv_ratio : $(DYN_PRODUCT) examples/Astrophysical_neutrino_flavor_ratio/main.cpp
@echo Compiling astrophysical neutrino flavor ratio example
@$(CXX) $(EXAMPLES_FLAGS) examples/Astrophysical_neutrino_flavor_ratio/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@
examples/Multiple_energy/multiple_energy : $(DYN_PRODUCT) examples/Multiple_energy/main.cpp
@echo Compiling multiple energy example
@$(CXX) $(EXAMPLES_FLAGS) examples/Multiple_energy/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@
examples/HDF5_Write_Read/write : $(DYN_PRODUCT) examples/HDF5_Write_Read/write.cpp
@echo Compiling HDF5 write
@$(CXX) $(EXAMPLES_FLAGS) examples/HDF5_Write_Read/write.cpp -lnuSQuIDS $(LDFLAGS) -o $@
examples/HDF5_Write_Read/read : $(DYN_PRODUCT) examples/HDF5_Write_Read/read.cpp
@echo Compiling HDF5 read
@$(CXX) $(EXAMPLES_FLAGS) examples/HDF5_Write_Read/read.cpp -lnuSQuIDS $(LDFLAGS) -o $@
examples/Atm_default/atm_default : $(DYN_PRODUCT) examples/Atm_default/main.cpp
@echo Compiling atmospheric example
@$(CXX) $(EXAMPLES_FLAGS) examples/Atm_default/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@
build/exBody.o : examples/Bodies/exBody.h examples/Bodies/exBody.cpp
@$(CXX) $(EXAMPLES_FLAGS) -c examples/Bodies/exBody.cpp -o $@
build/ex_bodies_main.o : examples/Bodies/exBody.h examples/Bodies/main.cpp
@$(CXX) $(EXAMPLES_FLAGS) -c examples/Bodies/main.cpp -o $@
examples/Bodies/bodies : $(DYN_PRODUCT) build/ex_bodies_main.o build/exBody.o
@echo Compiling bodies example
@$(CXX) $(EXAMPLES_FLAGS) build/ex_bodies_main.o build/exBody.o -lnuSQuIDS $(LDFLAGS) -o $@
build/exCross.o : examples/Xsections/exCross.h examples/Xsections/exCross.cpp
@$(CXX) $(EXAMPLES_FLAGS) -c examples/Xsections/exCross.cpp -o $@
examples/Xsections/xsections : $(DYN_PRODUCT) examples/Xsections/main.cpp build/exCross.o
@echo Compiling cross section example
@$(CXX) $(EXAMPLES_FLAGS) examples/Xsections/main.cpp build/exCross.o -lnuSQuIDS $(LDFLAGS) -o $@
examples/NSI/nsi : $(DYN_PRODUCT) examples/NSI/main.cpp
@echo Compiling non-standard interaction example
@$(CXX) $(EXAMPLES_FLAGS) examples/NSI/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@
examples/LV/lv : $(DYN_PRODUCT) examples/LV/main.cpp
@echo Compiling Lorentz Violation example
@$(CXX) $(EXAMPLES_FLAGS) examples/LV/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@
examples/Atm_BSM/atm_bsm: $(DYN_PRODUCT) examples/Atm_BSM/main.cpp
@echo Compiling atmospheric with beyond standard model physics example
@$(CXX) $(EXAMPLES_FLAGS) examples/Atm_BSM/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@
examples/Constant_density_layers/const_dens_layers : $(DYN_PRODUCT) examples/Constant_density_layers/main.cpp
@echo Compiling constant density layer example
@$(CXX) $(EXAMPLES_FLAGS) examples/Constant_density_layers/main.cpp -lnuSQuIDS $(LDFLAGS) -o $@
.PHONY: install uninstall clean test docs
clean:
@echo Erasing generated files
@rm -f $(PATH_nuSQUIDS)/build/*.o
@rm -f $(PATH_nuSQUIDS)/$(STAT_PRODUCT) $(PATH_nuSQUIDS)/$(DYN_PRODUCT) $(PATH_nuSQUIDS)/$(PYTHON_LIB)
doxygen:
@mkdir -p ./docs
@doxygen src/doxyfile
docs:
@mkdir -p ./docs
@doxygen src/doxyfile
test: $(DYN_PRODUCT) $(STAT_PRODUCT)
@cd ./test ; ./run_tests
install: $(DYN_PRODUCT) $(STAT_PRODUCT)
@echo Installing headers in $(PREFIX)/include/nuSQuIDS
@mkdir -p "$(PREFIX)/include/nuSQuIDS"
@cp "$(INCnuSQUIDS)"/nuSQuIDS/*.h "$(PREFIX)/include/nuSQuIDS"
@echo Installing libraries in $(PREFIX)/$(INSTALL_LIBDIR)
@mkdir -p "$(PREFIX)/$(INSTALL_LIBDIR)"
@LANG=C sed "'${REPLACE_INSTALL_FLAG}'" < $(DYN_PRODUCT) > "$(PREFIX)/$(INSTALL_LIBDIR)/lib$(NAME)$(DYN_SUFFIX)"
@LANG=C sed "'${REPLACE_INSTALL_FLAG}'" < $(STAT_PRODUCT) > "$(PREFIX)/$(INSTALL_LIBDIR)/lib$(NAME).a"
@chmod 755 "$(PREFIX)/$(INSTALL_LIBDIR)/lib$(NAME)$(DYN_SUFFIX)" "$(PREFIX)/$(INSTALL_LIBDIR)/lib$(NAME).a"
@echo Installing config information in $(PREFIX)/$(INSTALL_LIBDIR)/pkgconfig
@mkdir -p "$(PREFIX)/$(INSTALL_LIBDIR)/pkgconfig"
@cp lib/nusquids.pc "$(PREFIX)/$(INSTALL_LIBDIR)/pkgconfig"
@echo Installing physics data in $(PREFIX)/share/nuSQuIDS
@mkdir -p "$(PREFIX)/share/nuSQuIDS"
@cp -r data/* "$(PREFIX)/share/nuSQuIDS/"
' >> ./Makefile
if `pkg-config hdf5`; then
:
else
echo ' @cp lib/hdf5.pc "$(PREFIX)/$(INSTALL_LIBDIR)/pkgconfig"' >> ./Makefile
fi
echo '
uninstall:
@echo Removing headers from $(PREFIX)/include/nuSQuIDS
@rm -rf "$(PREFIX)/include/nuSQuIDS"
@echo Removing libraries from $(PREFIX)/$(INSTALL_LIBDIR)
@rm -f "$(PREFIX)/$(INSTALL_LIBDIR)/$(DYN_PRODUCT)"
@rm -f "$(PREFIX)/$(INSTALL_LIBDIR)/$(STAT_PRODUCT)"
@echo Removing config information from $(PREFIX)/$(INSTALL_LIBDIR)/pkgconfig
@rm -f "$(PREFIX)/$(INSTALL_LIBDIR)/pkgconfig/nusquids.pc"
' >> ./Makefile
if [ "$PYTHON_BINDINGS" ]; then
echo '
python : $(PYTHON_LIB)
$(PYTHON_LIB) : build/nuSQUIDSpy.o $(STAT_PRODUCT)
@echo Linking python bindings
@$(CXX) $(DYN_OPT_PY) build/nuSQUIDSpy.o -Llib -l$(NAME) $(LDFLAGS) $(BOOST_PYTHON_LDFLAGS) $(PYTHON_LDFLAGS) -o $(PYTHON_LIB)
build/nuSQUIDSpy.o : resources/python/src/nuSQUIDSpy.cpp
@echo Compiling python bindings
@$(CXX) $(CXXFLAGS) -c -Iresources/python/inc $(PYTHON_CFLAGS) $(NUMPY_CFLAGS) $(CFLAGS) $< -o $@
python-install : $(PYTHON_LIB)
@echo Installing python module in $(PYTHON_MODULEDIR)
@mkdir -p $(PYTHON_MODULEDIR)
@cp $(PYTHON_LIB) $(PYTHON_MODULEDIR)
python-uninstall : $(PYTHON_LIB)
@echo Removing python module from $(PYTHON_MODULEDIR)
@rm $(PYTHON_MODULEDIR)/$(NAME).so
' >> ./Makefile
fi
echo "
export CXX=\"${CXX}\"
export CFLAGS=\"${CFLAGS} ${SQUIDS_CFLAGS} ${GSL_CFLAGS} ${HDF5_CFLAGS}\"
export CXXFLAGS=\"${CXXFLAGS} -std=c++11\"
export LDFLAGS=\"${LDFLAGS} -lnuSQuIDS -lpthread ${SQUIDS_LDFLAGS} ${GSL_LDFLAGS} ${HDF5_LDFLAGS}\"
" > test/env_vars.sh
if uname | grep -q 'Darwin' ; then
printf "export DYLD_LIBRARY_PATH=\"" >> test/env_vars.sh
printf "${SOURCE_PATH}/lib:${SQUIDS_LIBDIR}:${GSL_LIBDIR}:${HDF5_LIBDIR}" >> test/env_vars.sh
if [ "$DYLD_LIBRARY_PATH" ]; then
printf ":${DYLD_LIBRARY_PATH}" >> test/env_vars.sh
fi
else
printf "export LD_LIBRARY_PATH=\"" >> test/env_vars.sh
printf "${SOURCE_PATH}/lib:${SQUIDS_LIBDIR}:${GSL_LIBDIR}:${HDF5_LIBDIR}" >> test/env_vars.sh
if [ "$LD_LIBRARY_PATH" ]; then
printf ":${LD_LIBRARY_PATH}" >> test/env_vars.sh
fi
fi
echo '"' >> test/env_vars.sh
echo "Done."
echo
echo "To build the library, run the following: make
After, to build examples: make examples"
if [ "$PYTHON_BINDINGS" ]; then
echo "To build the python bindings run: make python"
echo "To install the python bindings run: make python-install"
fi