about summary refs log tree commit diff
path: root/var_lib_genenet_bnw/build.sh
blob: 4dc345f4f7b0ec14aa599fc568344afb65afc66c (plain)
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
#!/bin/bash
# Build the four C/C++ programs the structure-learning pipeline needs.
#
# The sources predate C99 and C++11: network_score and structure rely on
# implicit int and fall off the end of main(), and get_kbest_nets used SGI's
# <ext/hash_set>.  -std=gnu89 keeps the C compiling on a modern gcc, and
# get_kbest_nets.cc was ported to std::unordered_set (see the comment at its
# hash-set block) so no compatibility flag is needed there.
#
# network_score needs R's standalone math library:
#   guix shell rmath-standalone gcc-toolchain -- ./build.sh
set -e
CFLAGS=${CFLAGS:--O2 -std=gnu89 -w}

RMATH_PREFIX=${RMATH_PREFIX:-}
if [ -z "$RMATH_PREFIX" ]; then
    # ask pkgconf if it is around, else fall back to $R_HOME / the usual names
    if command -v pkgconf >/dev/null 2>&1; then
        RMATH_LIBS=$(pkgconf --libs libRmath)
    fi
    RMATH_PREFIX=$(dirname "$(dirname "$(command -v R 2>/dev/null || echo /usr/lib/R/bin/R)")")
fi

gcc $CFLAGS ${RMATH_PREFIX:+-I$RMATH_PREFIX/include} \
    ./localscore/network_score.c ${RMATH_LIBS:-${RMATH_PREFIX:+-L$RMATH_PREFIX/lib -lRmath}} -lm \
    -o network_score
gcc $CFLAGS ./print_structure/structure.c -lm -o structure

cd ./k-best/src/
D=${CXX:-g++}
$D -w -O2 -o get_kbest_parents get_kbest_parents.cc
$D -w -O2 -o get_kbest_nets get_kbest_nets.cc