-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·127 lines (108 loc) · 3.06 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
#!/usr/bin/env bash
declare GITHUB_BASE="https://github.com/cjungmann/lib"
declare -a LIBS_NEEDED=( argeater pager contools )
declare -a DEVS_REQUIRED=(
curses.h libncurses-dev
bash/builtins.h bash-builtins
)
declare -a LIB_DIRS_ARRAY=()
declare -a LIB_FLAGS_ARRAY=()
declare -a LIB_MODULES_ARRAY=()
declare -a INCFLAGS_ARRAY=()
confirm_devs()
{
local -i missing_count=0
local header package
for el in "${DEVS_REQUIRED[@]}"; do
if [ -z "$header" ]; then
header="$el"
else
package="$el"
if ! [ -f "/usr/include/$header" ]; then
printf $'Cannot find header \e[31;1m%s\e[m. Please install \e[31;1m%s\e[m.\n' \
"$header" "$package"
(( ++missing_count ))
fi
header=
package=
fi
done
[ "$missing_count" -eq 0 ]
}
install_and_build_library()
{
local libname="$1"
if ! [ -d "libs" ]; then
mkdir libs
fi
cd libs
git clone "${GITHUB_BASE}${libname}.git"
cd "lib$libname"
declare dir="libs/lib$libname"
make
if [ "$?" -eq 0 ]; then
LIB_MODULES_ARRAY+=( "$dir/lib$libname.a" )
INCFLAGS_ARRAY+=( "-I$dir" )
fi
LIB_DIRS_ARRAY+=( $( pwd ) )
cd ../..
}
shared_library_installed()
{
local libname="lib${1}.so"
/usr/sbin/ldconfig -p | grep [[:space:]]"$libname"[[:space:]]
}
add_if_static_library_available()
{
local libname="$1"
local libdir="libs/lib${libname}"
local libfile="$libdir/lib${libname}.a"
echo "Checking for lib path '$libdir'"
if [ -d "$libdir" ]; then
if [ -f "$libfile" ]; then
echo "Found the $libname static library!, Adding."
LIB_MODULES_ARRAY+=( "$libfile" )
INCFLAGS_ARRAY+=( "-I${libdir}" )
return 0
fi
fi
echo "Failed to find $libname"
return 1
}
confirm_library()
{
local libname="$1"
if shared_library_installed "$libname"; then
echo "Found shared library '$1'"
LIB_FLAGS_ARRAY+=( "-l$libname" )
elif ! add_if_static_library_available "$libname"; then
echo "failed to find static library, so we're gonna add it"
install_and_build_library "$libname"
fi
}
setup_libraries()
{
for lib in "${LIBS_NEEDED[@]}"; do
confirm_library "$lib"
done
}
if ! confirm_devs; then
exit
fi
setup_libraries
declare flags_str="s|LIB_FLAGS =.*|LIB_FLAGS = ${LIB_FLAGS_ARRAY[*]}|"
declare mods_str="s|LIB_MODULES =.*|LIB_MODULES = ${LIB_MODULES_ARRAY[*]}|"
declare incflags_str="s|INCFLAGS =.*|INCFLAGS = ${INCFLAGS_ARRAY[*]}|"
flags_str="${flags_str// /\\ }"
mods_str="${mods_str// /\\ }"
incflags_str="${incflags_str// /\\ }"
printf $'flags_str with be \e[32;1m%s\e[m\n' "$flags_str"
printf $'mods_str with be \e[32;1m%s\e[m\n' "$mods_str"
printf $'incflags_str with be \e[32;1m%s\e[m\n' "$incflags_str"
read -n1 -p "Press any key to update the Makefile"
declare -a SED_LIB_ARGS=(
-e "${flags_str}"
-e "${mods_str}"
-e "${incflags_str}"
)
sed -i "${SED_LIB_ARGS[@]}" Makefile