-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_paths_for_libraries.sh
79 lines (66 loc) · 1.94 KB
/
create_paths_for_libraries.sh
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
#!/bin/bash
(set -o igncr) 2>/dev/null && set -o igncr; # this comment is needed for Windows system
path_separator()
{
if [[ "$1" == *[/]* ]]
then
local sep="/"
else
local sep="\\"
fi
echo "$sep"
}
create_library_paths_for_gcc()
{
local root_path=$1
local lib_name=$2
local only_L_path=$3
if [[ "$root_path" == *[/]* ]]
then
local sep="/"
else
local sep="\\"
fi
local lib_path="$root_path""$sep""$lib_name"
local mod="-I""$lib_path""$sep""mod"
local lib="-L""$lib_path"" -l""$lib_name"
if [ "$only_L_path" == "only_L_path" ]; then
local result_path="$lib"
else
local result_path="$mod"" $lib"
fi
echo "$result_path"
}
### Example of usage:
## source create_library_paths_for_gcc.sh # if it used in another script
#root_path="C:/lib/something"
#lib_name="cool"
#result=$( create_library_paths_for_gcc "$root_path" "$lib_name" "only_L_path")
#echo $result
create_paths_for_libraries()
{
local -a argv=("${@}")
local -i totlen=${#argv[@]}
local root_path="${argv[0]}"
local -a lib_names=("${argv[@]:1:$totlen}")
local all_paths=""
for lib_name in "${lib_names[@]}"
do
if [[ "$lib_name" =~ " only_L_path" ]]; then # if there is substring "only_L_path"
lib_name=${lib_name//" only_L_path"/} # remove "only_L_path" substring
lib_paths=$( create_library_paths_for_gcc "$root_path" "$lib_name" "only_L_path")
all_paths="$all_paths"" $lib_paths"
else
lib_paths=$( create_library_paths_for_gcc "$root_path" "$lib_name")
all_paths="$all_paths"" $lib_paths"
fi
done
all_paths="${all_paths## }" # removing of the first space
echo "$all_paths"
}
### Example of usage:
## source create_paths_for_libraries.sh # if it used in another script
#root_path="C:\work\library"
#declare -a libs=("$root_path" "mfufm" "slatec only_L_path" "physlib" "pulsarlib")
#lib_paths=$( create_paths_for_libraries "${libs[@]}" )
#echo $lib_paths