Skip to content

Commit 88ccaf3

Browse files
committed
Updated to provide manifest support
1 parent 1d17772 commit 88ccaf3

File tree

2 files changed

+120
-37
lines changed

2 files changed

+120
-37
lines changed

dylib.manifest

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Igis 1.1.0

make.sh

Lines changed: 119 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,131 @@
11
#!/bin/bash
2-
CONFIG=${1:-debug}
3-
FILENAME=$(basename -- "$0")
4-
case $FILENAME in
2+
# MerlinMake version 1.0.0 23-Feb-2019 15:12
3+
4+
# This script generates the command line required to use the proper version of merlin libraries both for
5+
# compiling a project and for executing the project. The command is then executed.
6+
7+
# The sole argument is either 'debug' or 'release' depending on configuration.
8+
# If no argument is specified defaults to 'debug'.
9+
10+
# The file must either be named make.sh or use a symlink named run.sh
11+
# The filename is then detected; make.sh will build while run.sh will run.
12+
13+
# Dynamic library dependencies are specified in the file 'dylib.manifest' located in the same directory
14+
# as make.sh.
15+
# There are two line formats:
16+
# project version -OR-
17+
# project LOCAL path
18+
#
19+
# The second format facilitates simple development of libraries by easily allowing a local directory
20+
# as a source.
21+
22+
config=${1:-debug}
23+
filename=$(basename -- "$0")
24+
case $filename in
525
"run.sh")
6-
MODE="run";;
26+
mode="run";;
727
"make.sh")
8-
MODE="build";;
28+
mode="build";;
929
*)
1030
# Terminate on error after message
1131
echo "Expected filename to be either 'make.sh' or 'run.sh'"
1232
exit 1;;
1333
esac
1434

35+
if [[ ! "$config" =~ ^(debug|release)$ ]]; then
36+
echo "Unexpected configuration; must be either debug or release, not $config"
37+
exit 1
38+
fi
39+
40+
# Requires: MERLIN_LIBRARY_ROOT_DIR (e.g. /usr/local/lib/merlin)
41+
[ -z "$MERLIN_LIBRARY_ROOT_DIR" ] && { echo "MERLIN_LIBRARY_ROOT_DIR must be defined"; exit 1; }
42+
43+
# Reference: https://www.ostricher.com/2014/10/the-right-way-to-get-the-directory-of-a-bash-script/
44+
get_script_dir () {
45+
source="${BASH_SOURCE[0]}"
46+
# While $source is a symlink, resolve it
47+
while [ -h "$source" ]; do
48+
dir="$( cd -P "$( dirname "$source" )" && pwd )"
49+
source="$( readlink "$source" )"
50+
# If $source was a relative symlink (so no "/" as prefix, need to resolve it relative to the symlink base directory
51+
[[ $source != /* ]] && source="$dir/$source"
52+
done
53+
dir="$( cd -P "$( dirname "$source" )" && pwd )"
54+
echo "$dir"
55+
}
56+
57+
# Start with a basic command line and empty library path
58+
commandLine="swift $mode -c $config"
59+
LD_LIBRARY_PATH=""
60+
61+
# Read the manifest file
62+
# If it exists, it must be in the format projectName tag
63+
manifestPath="$(get_script_dir)/dylib.manifest"
64+
if [ -f $manifestPath ]; then
65+
echo "Reading manifest at $manifestPath"
66+
67+
while read line; do
68+
if [ ! -z "$line" ]; then
69+
# If the line is not empty, it must be in the format specified
70+
# The first case is specification of a library found in the MERLIN_LIBRARY_ROOT_DIR
71+
# This format specifies only a library name and version
72+
# e.g. "Igis 1.0.7"
73+
libraryRegex='^([[:alpha:]]+)[[:space:]]+([[:alnum:]\.]+)$'
74+
75+
# An alterntive is specifying a local path which will be used directly
76+
# iff the tag is 'LOCAL'
77+
localRegex='^([[:alpha:]]+)[[:space:]]+LOCAL[[:space:]]+([[:alnum:]/-]+)$'
78+
79+
if [[ "$line" =~ $localRegex ]]; then
80+
project=${BASH_REMATCH[1]}
81+
directory=${BASH_REMATCH[2]}
82+
echo "Requires LOCAL $project @ LOCAL from $directory"
83+
84+
# The library path is determined by the exact name used for the directory
85+
libraryPath="$directory/.build/$config"
86+
elif [[ "$line" =~ $libraryRegex ]]; then
87+
project=${BASH_REMATCH[1]}
88+
tag=${BASH_REMATCH[2]}
89+
echo "Requires LIBRARY $project @ $tag"
90+
91+
# Determine the library path based on the name of the project and tag
92+
libraryPath="$MERLIN_LIBRARY_ROOT_DIR/$project-$tag/$project/.build/$config"
93+
else
94+
echo "Unexpected line format: $line"
95+
exit 1
96+
fi
97+
98+
# Verify that the libraryPath exists
99+
if [[ ! -d "$libraryPath" ]]; then
100+
echo "The specified library path was not found '$libraryPath'"
101+
exit 1
102+
fi
103+
104+
# Build the command line by appending the library for inclusion and linking
105+
commandLine="$commandLine -Xswiftc -I -Xswiftc $libraryPath"
106+
commandLine="$commandLine -Xswiftc -L -Xswiftc $libraryPath"
107+
commandLine="$commandLine -Xswiftc -l$project"
108+
109+
# Build the LD_LIBRARY_PATH
110+
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$libraryPath"
111+
112+
# Define a new variable of the form DYLIB_$project_PATH to contain the library path for the
113+
# specified library. The library may refer to this environment variable to find files
114+
# relative to itself.
115+
dylibVariableName=DYLIB_${project}_PATH
116+
printf -v $dylibVariableName "%s" "$libraryPath"
117+
export $dylibVariableName
118+
fi
119+
done < "$manifestPath"
15120

16-
if [[ "$CONFIG" =~ ^(debug|release)$ ]]; then
17-
if [[ -z "$LD_LIBRARY_PATH" ]]; then
18-
echo "Must provide LD_LIBRARY_PATH in environment" 1>&2
19-
exit 1
20-
fi
21-
22-
if [ "$CONFIG" == "debug" ]; then
23-
if [[ -z "$IGIS_LIBRARY_DEBUG_PATH" ]]; then
24-
echo "Must provide IGIS_LIBRARY_DEBUG_PATH in environment" 1>&2
25-
exit 1
26-
fi
27-
28-
echo "LD_LIBRARY_PATH at $LD_LIBRARY_PATH"
29-
echo "IGIS_LIBRARY_DEBUG_PATH at $IGIS_LIBRARY_DEBUG_PATH"
30-
echo "Building debug configuration..."
31-
LD_LIBRARY_PATH="$IGIS_LIBRARY_DEBUG_PATH:$CURSES_LIBRARY_DEBUG_PATH:$NCURSES_LIBRARY_DEBUG_PATH:$LOGICAL_OPERATORS_LIBRARY_DEBUG_PATH"
32-
swift $MODE -c debug -Xswiftc -I -Xswiftc $IGIS_LIBRARY_DEBUG_PATH -Xswiftc -L -Xswiftc $IGIS_LIBRARY_DEBUG_PATH -Xswiftc -lIgis
33-
else
34-
if [[ -z "$IGIS_LIBRARY_RELEASE_PATH" ]]; then
35-
echo "Must provide IGIS_LIBRARY_RELEASE_PATH in environment" 1>&2
36-
exit 1
37-
fi
38-
39-
echo "LD_LIBRARY_PATH at $LD_LIBRARY_PATH"
40-
echo "IGIS_LIBRARY_RELEASE_PATH at $IGIS_LIBRARY_RELEASE_PATH"
41-
echo "Building release configuration..."
42-
LD_LIBRARY_PATH="$IGIS_LIBRARY_RELEASE_PATH:$CURSES_LIBRARY_RELEASE_PATH:$NCURSES_LIBRARY_RELEASE_PATH:$LOGICAL_OPERATORS_LIBRARY_RELEASE_PATH"
43-
swift $MODE -c release -Xswiftc -I -Xswiftc $IGIS_LIBRARY_DEBUG_PATH -Xswiftc -L -Xswiftc $IGIS_LIBRARY_DEBUG_PATH -Xswiftc -lIgis
44-
fi
45121
else
46-
# Terminate on error after message
47-
echo "Argument specified must be either 'debug' or 'release'"
48-
exit 1;
122+
echo "No manifest found at $manifestPath"
49123
fi
124+
125+
# Export required variables
126+
export LD_LIBRARY_PATH
127+
128+
# Whether or not there was a manifest, we evaluate the command line
129+
130+
eval "$commandLine"
131+
echo "Done"

0 commit comments

Comments
 (0)