Disable regression if poly is not available (#7981)
[cvc5.git] / contrib / get-script-header.sh
1 #!/usr/bin/env bash
2 #
3 set -e -o pipefail
4
5 [ ! -d contrib ] && echo "$0 not called from base directory" && exit 1
6
7 DEPS_DIR="$(pwd)/deps"
8 INSTALL_DIR="$DEPS_DIR/install"
9 INSTALL_LIB_DIR="$INSTALL_DIR/lib"
10 INSTALL_INCLUDE_DIR="$INSTALL_DIR/include"
11 INSTALL_BIN_DIR="$INSTALL_DIR/bin"
12
13 mkdir -p "$DEPS_DIR"
14
15 if ! [ -e src/parser/smt2/Smt2.g ]; then
16 echo "$(basename $0): I expect to be in the contrib/ of a cvc5 source tree," >&2
17 echo "but apparently:" >&2
18 echo >&2
19 echo " $(pwd)" >&2
20 echo >&2
21 echo "is not a cvc5 source tree ?!" >&2
22 exit 1
23 fi
24
25 function webget {
26 if [ -x "$(command -v wget)" ]; then
27 wget -c -O "$2" "$1"
28 elif [ -x "$(command -v curl)" ]; then
29 curl -L "$1" >"$2"
30 else
31 echo "Can't figure out how to download from web. Please install wget or curl." >&2
32 exit 1
33 fi
34 }
35
36 for cmd in python python2 python3; do
37 if [ -x "$(command -v $cmd)" ]; then
38 PYTHON="$cmd"
39 break
40 fi
41 done
42
43 if [ -z "$PYTHON" ]; then
44 echo "Error: Couldn't find python, python2, or python3." >&2
45 exit 1
46 fi
47
48 function setup_dep
49 {
50 url="$1"
51 directory="$2"
52 echo "Setting up $directory ..."
53 rm -rf "$directory"
54 mkdir -p "$directory"
55 cd "$directory"
56 webget "$url" archive
57 tar xf archive --strip 1 # Strip top-most directory
58 rm archive
59 }
60
61 # Some of our dependencies do not provide a make install rule. Use the
62 # following helper functions to copy libraries/headers/binaries into the
63 # corresponding directories in deps/install.
64
65 function install_lib
66 {
67 echo "Copying $1 to $INSTALL_LIB_DIR"
68 [ ! -d "$INSTALL_LIB_DIR" ] && mkdir -p "$INSTALL_LIB_DIR"
69 cp "$1" "$INSTALL_LIB_DIR"
70 }
71
72 function install_includes
73 {
74 include="$1"
75 subdir="$2"
76 echo "Copying $1 to $INSTALL_INCLUDE_DIR/$subdir"
77 [ ! -d "$INSTALL_INCLUDE_DIR" ] && mkdir -p "$INSTALL_INCLUDE_DIR"
78 [ -n "$subdir" ] && [ ! -d "$INSTALL_INCLUDE_DIR/$subdir" ] && mkdir -p "$INSTALL_INCLUDE_DIR/$subdir"
79 cp -r "$include" "$INSTALL_INCLUDE_DIR/$subdir"
80 }
81
82 function install_bin
83 {
84 echo "Copying $1 to $INSTALL_BIN_DIR"
85 [ ! -d "$INSTALL_BIN_DIR" ] && mkdir -p "$INSTALL_BIN_DIR"
86 cp "$1" "$INSTALL_BIN_DIR"
87 }
88
89 function guess_lib_dir
90 {
91 #
92 # On some systems the library may be installed to lib64/
93 # instead of lib/
94 #
95 # This function guesses the install lib directory
96 #
97 lib_name="$1"
98 lib_dir="$(dirname "$(find "$INSTALL_DIR" -name "${lib_name}")")"
99 echo ${lib_dir}
100 }
101
102 function rename_installed_lib
103 {
104 #
105 # This function uses the calculated library directory and
106 # then relocates the first argument to the second.
107 #
108 src="$1"
109 dest="$2"
110 lib_dir="$(guess_lib_dir "$src")"
111 mv "$lib_dir/$src" "$lib_dir/$dest"
112 }
113