3 [[ "${BASH_SOURCE[0]}" != "${0}" ]] || set -e -u
7 declare -r gitroot=https://raw.githubusercontent.com/apertium
8 declare -ar pmodules=(trunk staging nursery incubator)
9 declare -ar lmodules=(languages incubator)
11 declare -r svnroot_giella=https://victorio.uit.no/langtech/trunk
15 discover_url_apertium () {
19 if [[ ${dir} = *-*-* ]]; then
20 modules=( "${pmodules[@]}" )
22 modules=( "${lmodules[@]}" )
24 for module in "${modules[@]}"; do
25 submodules=$(curl -Ss --fail "${gitroot}/apertium-${module}/master/.gitmodules")
26 # url="${svnroot}${module}/${dir}"
27 if url=$(grep "[[:space:]]*url = .*/${dir}.git$" <<<"${submodules}"); then
29 # TODO: Option to use ssh urls?
30 url=${url/git@github.com:/https:\/\/github.com\/}
31 echo "Assuming git url of ${dir} is ${url}" >&2
36 echo "WARNING: Couldn't find git url of ${dir}" >&2
37 if ! msg=$(curl -Ss --fail "${gitroot}/apertium-languages/master/.gitmodules"); then
38 printf "\n%s\n\n" "${msg}" >&2
39 echo "You may want to see http://wiki.apertium.org/wiki/Using_SVN#Host_not_found_when_using_proxy" >&2
40 echo "or make sure you have a working internet connection." >&2
44 discover_url_giella () {
46 local -r url="${svnroot_giella}/${dir}"
47 echo "Assuming SVN url of ${dir} is ${url}" >&2
52 if [[ $1 = giella-* ]]; then
53 echo "langs/${1##giella-}"
59 if [[ $1 = giella-* ]]; then
60 echo "langs/${1##giella-}/tools/mt/apertium"
68 local -r dir=$(dir_of_dep "${dep}")
69 # Let cwd be GTHOME from here on in; langs should exist under this dir:
78 if [[ ${dep} = giella-* ]]; then
79 ./configure --enable-apertium --with-hfst --enable-syntax
80 V=1 make # giella so memory hungry, -j1
81 elif [[ ${dep} = gtcore ]]; then
92 local -r dir=$(dir_of_dep "${dep}")
93 if [[ -d ${dir} ]]; then
94 if [[ -d "${dir}/.git" ]]; then
95 if [[ -z "$(cd "${dir}" && git fetch --dry-run)" ]]; then
103 if [[ -z $(svn status -qu "${dir}") ]]; then
114 local -r dir=$(dir_of_dep "${dep}")
116 if [[ -d ${dir} ]]; then
119 printf "Updating existing %s (%s)\n" "${dir}" "$(pwd)"
120 if [[ -d .git ]]; then
127 if [[ ${dep} = giella-* || ${dep} = gtcore ]]; then
128 url=$(discover_url_giella "${dir}") && svn checkout "${url}" "${dir}"
130 url=$(discover_url_apertium "${dir}") && if [[ $depth -gt 0 ]]; then
131 git clone --depth "${depth}" "${url}" "${dir}"
133 git clone "${url}" "${dir}"
141 for e in "${@:2}"; do
142 [[ "$e" == "$1" ]] && return 0
149 local -r keep_going=$2
150 local -r skip_if_up_to_date=$3
151 local -r pair=apertium-${4##apertium-}
152 # shellcheck disable=SC2124
153 local -r skip="${@:5}" # intentionally assigning array to string
155 if [[ ${skip_if_up_to_date} == true && $(is_dep_updated "${pair}") == "yes" ]]; then
156 printf "Existing pair %s is already up to date. Skipping build step.\\n" "${pair}"
160 get_dep "${depth}" "${pair}"
161 # Mac has ancient bash, so no declare -A for us
164 while read -r n dep; do
166 orglang=$(split_org_langs "${dep}")
167 local lang=${orglang##* }
168 # shellcheck disable=SC2068
169 if in_array "${lang}" ${skip[@]}; then # intentionally unquoted skip
171 echo "Skipping data ${dep} as instructed."
177 done < <(awk -F'[][[:space:]]+' '/^ *AP_CHECK_LING\(/ && $2 && $4 {print $2, $4}' "${pair}"/configure.ac)
179 if [[ ${#deps[@]} -ne 0 ]]; then
180 for dep in "${deps[@]}"; do
181 if ! get_data "${depth}" "${skip_if_up_to_date}" "${keep_going}" "${dep}"; then
183 echo "WARNING: Couldn't get dependency ${dep}; pair ${pair} might not get set up correctly."
185 if ${keep_going}; then
186 echo "WARNING: Continuing on as if nothing happened ..."
196 autogen="./autogen.sh "
197 for i in "${!depn[@]}"; do
198 binsdir=$(bins_of_dep "${deps[i]}")
199 autogen="${autogen} --with-lang${depn[i]}=../${binsdir}"
203 make test || echo "make test failed, but that's probably fine."
209 You can now "cd ${pair}" or one of the dependencies, edit some files
210 and type "make -j3 langs" to compile again.
216 local -r org=$( if [[ $1 = giella-* ]]; then echo giella; else echo apertium; fi )
217 local -r langs=${1#${org}-}
218 echo "${org} ${langs}"
221 maybe_symlink_GTHOME () {
224 echo "Found $1 here, using that."
226 elif [[ -z ${GTHOME+x} ]]; then
228 echo "GTHOME is unset; will have to build $1 without it."
230 elif [[ -d $GTHOME/$1 ]]; then
232 echo "Found $1 in your \$GTHOME, symlinking to that to avoid recompilation."
234 test -d langs || mkdir langs
235 ln -sf "$GTHOME/$1" "$1"
238 echo "GTHOME is set but there is no $GTHOME/$1; will have to build $1 from scratch."
245 local -r keep_going=$2
246 local -r skip_if_up_to_date=$3
247 local -r orglangs=$(split_org_langs "$4")
248 local -r org=${orglangs%% *}
249 local -r langs=${orglangs##* }
251 if [[ ${langs} = *-* ]]; then
254 local -r mdep=${org}-${langs}
255 if [[ $org = giella ]]; then
256 maybe_symlink_GTHOME "langs/${langs}"
257 maybe_symlink_GTHOME gtcore
258 get_dep "${depth}" gtcore
262 if [[ ${skip_if_up_to_date} == true && $(is_dep_updated "${mdep}") == "yes" ]]; then
263 printf "Dependency %s is up-to-date, skipping update and build.\\n" "$3"
265 if get_dep "${depth}" "${mdep}"; then
278 ${0##*/} -l [MODULE...]
281 Run with just one argument, it will download and set up the
282 Apertium development data for the specified language pair.
284 With the -l option, it will list available language pairs. Give
285 one or more MODULE arguments to list only pairs in that SVN
286 module (one of "trunk", "staging", "nursery", "incubator").
287 The same behavior can be invoked for language modules using -m.
290 -h display this help and exit
291 -l list available packages instead of setting up data
292 -m list available language modules instead of setting up
294 -k keep going even if a dependency fails
295 -s skip the build step for up-to-date dependencies/pairs
296 -x DEP skip data dependency DEP (useful if DEP is installed
297 through a package manager); may be specified multiple
299 -d DEPTH specify a --depth to 'git clone'
304 Download and set up apertium-nno-nob, along with its nno and
307 sudo apt-get install giella-sme
308 ${0##*/} -x sme sme-nob
310 Install giella-sme through apt-get, then install download and set
311 up apertium-sme-nob, along with the nob dependency (but not sme).
315 List available language pairs in SVN trunk.
317 ${0##*/} -l | grep kaz
319 List available language pairs involving Kazakh.
324 local -r pattern="$1"
329 [[ ${element} = "${pattern}" ]] && return 0
336 curl -Ss --fail "${gitroot}/apertium-${module}/master/.gitmodules" \
337 | grep "[[:space:]]*url = .*.git$" \
338 | sed 's%.*url = .*/%%' \
339 | sed 's/[.]git$//' \
340 | sed 's/^apertium-//'
345 local -a modules=("$@")
348 # Defaulting to all modules:
349 if [[ ${#modules[@]} -eq 0 ]]; then
350 modules=( "${pmodules[@]}" )
352 # Sanity-check input:
353 for module in "${modules[@]}"; do
354 if ! is_in "${module}" "${pmodules[@]}"; then
355 echo "ERROR: '${module}' not recognised as a language pair module"'!' >&2
362 for module in "${modules[@]}"; do
363 echo "# Pairs in ${module}:"
364 list_modules "${module}" |grep -e '-'
369 list_language_modules() {
370 local -a modules=("$@")
373 # Defaulting to all modules:
374 if [[ ${#modules[@]} -eq 0 ]]; then
375 modules=( "${lmodules[@]}" )
377 # Sanity-check input:
378 for module in "${modules[@]}"; do
379 if ! is_in "${module}" "${lmodules[@]}"; then
380 echo "ERROR: '${module}' not recognised as an language module module"'!' >&2
387 for module in "${modules[@]}"; do
388 echo "# Language modules in ${module}:"
389 list_modules "${module}" | grep -ve '-'
394 if ! command -V git >/dev/null; then
397 You need to install git first!
399 If you use apt-get, it's typically:
401 sudo apt-get install git
403 If you use rpm/dnf, it's typically:
413 local do_list_pairs=false
414 local keep_going=false
415 local do_list_language_modules=false
416 local skip_if_up_to_date=false
419 while getopts ":hklmsx:d:" opt; do
426 skip+=( "${OPTARG}" )
435 do_list_language_modules=true
441 skip_if_up_to_date=true
444 echo "ERROR: Invalid option: -$OPTARG" >&2
451 shift "$((OPTIND-1))"
453 if ${do_list_pairs}; then
455 elif ${do_list_language_modules}; then
456 list_language_modules "$@"
458 if [[ $# -lt 1 ]]; then
459 echo "ERROR: No language pair specified." >&2
465 get_data "${depth}" "${keep_going}" "${skip_if_up_to_date}" "$d" "${skip[@]:-}"
470 if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
471 echo "${BASH_SOURCE[0]} is being sourced; chmod +x and use ./${BASH_SOURCE[0]} to actually run." >&2