forked from jlazar17/nuSQuIDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·775 lines (652 loc) · 24.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
#!/bin/bash
check_pkgconfig(){
if [ "$CHECKED_PKGCONFIG" ]; then return; fi
echo "Looking for pkg-config..."
which pkg-config 2>&1 > /dev/null
if [ "$?" -ne 0 ]; then
echo "Error: pkg-config not found; you will need to specify library locations manually" 1>&2
exit 1
fi
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
}
try_find_boost(){
GUESS_DIR=$1
PYV=$2
PKG=boost
VAR_PREFIX=`echo $PKG | tr [:lower:] [:upper:]`
TMP_FOUND=`eval echo "$"${VAR_PREFIX}_FOUND`
if [ "$TMP_FOUND" ]; then return; fi
echo "Looking for $PKG in $GUESS_DIR..."
POSSIBLE_BOOST_LIBDIRS="${GUESS_DIR}/lib ${GUESS_DIR}/lib64 ${GUESS_DIR}/lib/x86_64-linux-gnu"
POSSIBLE_BOOST_INCDIRS="${GUESS_DIR}/include"
for BOOST_LIBDIR in $POSSIBLE_BOOST_LIBDIRS; do
if [ -d $BOOST_LIBDIR -a \( -e $BOOST_LIBDIR/libboost_python${PYV}.a -o -e $BOOST_LIBDIR/libboost_python${PYV}.so -o -e $BOOST_LIBDIR/libboost_python${PYV}.dylib \) ]; then
break
fi
done
if [ ! -d $BOOST_LIBDIR -o ! \( -e $BOOST_LIBDIR/libboost_python${PYV}.a -o -e $BOOST_LIBDIR/libboost_python${PYV}.so -o -e $BOOST_LIBDIR/libboost_python${PYV}.dylib \) ]; then
echo " Unable to locate the boost_python${PYV} libray in $GUESS_DIR"
return
fi
for BOOST_INCDIR in $POSSIBLE_BOOST_INCDIRS; do
if [ -d $BOOST_INCDIR -a -e $BOOST_INCDIR/boost/python.hpp ]; then
break
fi
done
if [ ! -d $BOOST_INCDIR -o ! $BOOST_INCDIR/boost/python.hpp ]; then
echo " Unable to locate boost/python.hpp in $GUESS_DIR"
return
fi
BOOST_CFLAGS="-I${BOOST_INCDIR}"
BOOST_LDFLAGS="-Wl,-rpath -Wl,${BOOST_LIBDIR} -L${BOOST_LIBDIR} -lboost_python${PYV}"
BOOST_FOUND=1
echo " Found boost in $GUESS_DIR"
}
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=101001
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))'
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)'
fi
CC=${CC-$GUESS_CC}
CXX=${CXX-$GUESS_CXX}
AR=${AR-$GUESS_AR}
LD=${LD-$GUESS_LD}
PYTHON_EXE="python"
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')
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
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
ensure_found gsl
ensure_found hdf5
ensure_found squids
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}/inc
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
echo "Generating makefile..."
echo "# Compiler
CC=$CC
CXX=$CXX
AR=$AR
LD=$LD
DYN_SUFFIX=$DYN_SUFFIX
DYN_OPT=$DYN_OPT
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
echo '
INCnuSQUIDS=$(PATH_nuSQUIDS)/include
LIBnuSQUIDS=$(PATH_nuSQUIDS)/lib
# FLAGS
CFLAGS= -O3 -fPIC -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)
# Compilation rules
all: $(STAT_PRODUCT) $(DYN_PRODUCT)
examples : $(EXAMPLES)
$(DYN_PRODUCT) : $(OBJECTS)
@echo Linking $(DYN_PRODUCT)
@$(CXX) $(DYN_OPT) $(LDFLAGS) -o $(DYN_PRODUCT) $(OBJECTS)
$(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)
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)"
@cp $(DYN_PRODUCT) $(STAT_PRODUCT) "$(PREFIX)/$(INSTALL_LIBDIR)"
@echo Installing config information in $(PREFIX)/$(INSTALL_LIBDIR)/pkgconfig
@mkdir -p "$(PREFIX)/$(INSTALL_LIBDIR)/pkgconfig"
@cp lib/nusquids.pc "$(PREFIX)/$(INSTALL_LIBDIR)/pkgconfig"' >> ./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
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
if [ "$DYLD_LIBRARY_PATH" ]; then
printf "${DYLD_LIBRARY_PATH}:" >> test/env_vars.sh
fi
printf "/lib:/usr/lib:\${HOME}/lib:/usr/local/lib:" >> test/env_vars.sh
else
printf "export LD_LIBRARY_PATH=\"" >> test/env_vars.sh
fi
echo "../lib:${SQUIDS_LIBDIR}:${GSL_LIBDIR}:${HDF5_LIBDIR}\"" >> test/env_vars.sh
if [ $PYTHON_BINDINGS ]; then
echo "Generating Python bindings makefile..."
PYTHONVERSION=`${PYTHON_EXE} -c 'import sys; print(str(sys.version_info.major)+"."+str(sys.version_info.minor))'`
PYTHONVERSIONSIMPLE=`${PYTHON_EXE} -c 'import sys; print(str(sys.version_info.major)+"."+str(sys.version_info.minor))'`
PYTHONVERSIONSIMPLE=${PYTHONVERSIONSIMPLE//.}
PYTHONLIBPATH=`${PYTHON_EXE} -c 'from distutils import sysconfig; print(sysconfig.get_config_var("LIBDIR"))'`
PYTHONBLDLIB=`${PYTHON_EXE} -c 'from distutils import sysconfig; print(sysconfig.get_config_var("BLDLIBRARY")[3:])'`
if [ -z "$PYTHONBLDLIB" ]; then
PYTHONBLDLIB=-lpython${PYTHONVERSION}
fi
PYTHONINCPATH=`${PYTHON_EXE} -c 'from distutils import sysconfig; print(sysconfig.get_config_var("INCLUDEPY"))'`
PYTHON_CFLAGS+=" -I${PYTHONINCPATH}"
# this fpermissive flag is due to a bug on numpy import_array() function on pythonv3
PYTHON_CFLAGS+=" -fpermissive"
PYTHONNUMPYCHECK=`${PYTHON_EXE} ./resources/check_numpy.py`
if [ -z "$PYTHONNUMPYCHECK" ]; then
echo "Error: numpy not found. Specify numpy installation location with --with-numpy-incdir."
exit 1
fi
PYTHONNUMPYINC=$PYTHONNUMPYCHECK
# check if python library was compiled with
PYTHONINCPATH=`${PYTHON_EXE} -c 'from distutils import sysconfig; print(sysconfig.get_config_var("INCLUDEPY"))'`
if [ "$BOOST_INCDIR" -a "$BOOST_LIBDIR" ]; then
echo "Checking manually specified boost..."
if [ -d "$BOOST_INCDIR" \
-a -d "$BOOST_LIBDIR" \
-a -e "$BOOST_INCDIR/boost/python.hpp" \
-a -e "$BOOST_LIBDIR/libboost_python$PYTHONVERSIONSIMPLE.a" ]; then
BOOST_FOUND=1
BOOST_CFLAGS="-I$BOOST_INCDIR"
BOOST_LDFLAGS="-Wl,-rpath -Wl,${BOOST_LIBDIR} -L$BOOST_LIBDIR -lboost_python$PYTHONVERSIONSIMPLE"
else
echo "Warning: manually specifed boost not found; will attempt auto detection"
fi
fi
try_find_boost /usr ${PYTHONVERSIONSIMPLE}
try_find_boost /usr/local ${PYTHONVERSIONSIMPLE}
try_find_boost /usr "-py27"
try_find_boost /usr ""
try_find_boost /usr/local ""
if [ -z $BOOST_LIBDIR ] && [ -z $BOOST_INCDIR ]; then
echo "Error: Specify BOOST library path using --with-boost-libdir and BOOST include path using --with-boost-incdir."
exit 1
fi
if [ -z $BOOST_LIBDIR ]; then
echo "Error: Specify BOOST library path using --with-boost-libdir."
exit 1
fi
if [ -z $BOOST_INCDIR ]; then
echo "Error: Specify BOOST include path using --with-boost-incdir."
exit 1
fi
echo "
# Compiler
CC=$CC
CXX=$CXX
AR=$AR
LD=$LD
DYN_SUFFIX=.so
DYN_OPT=$DYN_OPT
PYTHON_VERSION = ${PYTHONVERSION}
LDFLAGS+= -L${PYTHONLIBPATH} -L${PYTHONLIBPATH}/..
LDFLAGS+= ${PYTHONBLDLIB}
LDFLAGS+= ${BOOST_LDFLAGS}
LDFLAGS+= ${SQUIDS_LDFLAGS} -lnuSQuIDS ${GSL_LDFLAGS} ${HDF5_LDFLAGS}
INCCFLAGS+= ${PYTHON_CFLAGS} ${SQUIDS_CFLAGS} ${GSL_CFLAGS} ${HDF5_CFLAGS} -I../include/
INCCFLAGS+= ${BOOST_CFLAGS}
INCCFLAGS+= -I${PYTHONNUMPYINC}
" > resources/python/src/Makefile
echo '
PATH_nuSQUIDS= $(shell pwd)/../../../
PATH_nuSQUIDSpy= $(shell pwd)/../
SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
# Directories
LIBnuSQUIDS=$(PATH_nuSQUIDS)/lib
INCnuSQUIDS=$(PATH_nuSQUIDS)/include
LDFLAGS+= -L$(LIBnuSQUIDS) -lnuSQuIDS
INCCFLAGS+= -I$(INCnuSQUIDS) -I$(PATH_nuSQUIDSpy)/inc
CXXFLAGS= -O3 -fPIC -std=c++11 $(INCCFLAGS)
' >> resources/python/src/Makefile
echo '
# Project files
NAME=nuSQUIDSpy
STAT_PRODUCT=$(PATH_nuSQUIDSpy)/bindings/$(NAME).a
DYN_PRODUCT=$(PATH_nuSQUIDSpy)/bindings/$(NAME)$(DYN_SUFFIX)
OS_NAME=$(shell uname -s)
ifeq ($(OS_NAME),Linux)
DYN_SUFFIX=.so
DYN_OPT=-shared -Wl,-soname,$(DYN_PRODUCT)
endif
ifeq ($(OS_NAME),Darwin)
DYN_SUFFIX=.so
DYN_OPT=-dynamiclib -install_name $(PATH_nuSQUIDSpy)/bindings/$(DYN_PRODUCT)
endif
# Compilation rules
all: $(STAT_PRODUCT) $(DYN_PRODUCT)
$(DYN_PRODUCT) : $(OBJECTS)
@echo Linking $(DYN_PRODUCT)
@$(CXX) $(DYN_OPT) $(LDFLAGS) -o $(DYN_PRODUCT) $(OBJECTS) $(LDFLAGS)
$(STAT_PRODUCT) : $(OBJECTS)
@echo Linking $(STAT_PRODUCT)
@$(AR) -rcs $(STAT_PRODUCT) $(OBJECTS)
%.o : %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
.PHONY: clean
clean:
rm -f *.o ../bindings/*.so ../bindings/*.a
' >> resources/python/src/Makefile
fi
nusqpath=`pwd`
echo '
#ifndef NUSQUIDS_GLOBAL_H
#define NUSQUIDS_GLOBAL_H
' > include/nuSQuIDS/global.h
echo "
#define XSECTION_LOCATION \"$nusqpath/data/xsections/\"
#define SUN_MODEL_LOCATION \"$nusqpath/data/astro/struct_b16_agss09.dat\"
#define SUN_MODEL_NELECTRON_LOCATION \"$nusqpath/data/astro/nele_bs05op.dat\"
#define EARTH_MODEL_LOCATION \"$nusqpath/data/astro/EARTH_MODEL_PREM.dat\"
" >> include/nuSQuIDS/global.h
echo '
#endif
' >> include/nuSQuIDS/global.h
echo "Done."
echo "To build library, run the following: make
After, to build examples: make examples"