summaryrefslogtreecommitdiffstats
path: root/zz_config/win-builds-switch.in
blob: 054c1a59ef245183328c4f70bccebab6247418d7 (plain)
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
#!/bin/awk /^#_/ { print gensub("^#_", "", "1") } END { exit 1 }
# The shebang above will display the message below for people who run the
# script in a new shell instead of sourcing it in their current shell.

#_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#_
#_  ERROR!
#_
#_  This script is being executed in a separate shell while it has to execute
#_  in an already existing one.
#_
#_  This means you have started this script as "win-builds-switch 64" (or 32)
#_  while you need to prepend ". " in front of that command for it to be
#_  effective:
#_    source win-builds-switch 64
#_
#_  (and before you ask, while your mistake has been noticed automatically, it
#_  cannot be corrected automatically)
#_
#_!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

replace_in_path() {
  local GLOB="${1}"
  local RE="${2}"
  local REPLACEMENT="${3}"

  case ":${PATH}:" in
    *:${GLOB}:*) PATH="$(echo "${PATH}" | sed "s;${RE};${REPLACEMENT};g")" ;;
    *)           PATH="${REPLACEMENT}:${PATH}" ;;
  esac
  export PATH
  echo 'Set ${PATH}='"${PATH}"'.' 1>&2
}

put_toolchain_in_path() {
  local BASE="${1}"
  local BITS="${2}"

  local BASE2
  if [ -n "${BITS}" ]; then
    BASE2="${BASE}_"
  else
    BASE2="${BASE}"
  fi

  replace_in_path \
    "/opt/${BASE2}??/bin" \
    "/opt/${BASE2}../bin" \
    "/opt/${BASE2}${BITS}/bin"
}

unset PKG_CONFIG_PATH
echo 'Unset ${PKG_CONFIG_LIBDIR}.' 1>&2

if [ x"$1" = x"clean" ]; then
  unset PKG_CONFIG_LIBDIR
  echo 'Unset ${PKG_CONFIG_LIBDIR}.' 1>&2
  export PATH="$(echo "${PATH}" | sed -e 's;/opt/windows_../bin;;g' -e 's/::/:/g')"
  echo 'Set ${PATH}='"${PATH}"'.' 1>&2
else
  if ! grep '^\(CYGWIN\|Linux\)' /proc/version >/dev/null 2>/dev/null; then
    # MSYS
    PKG_CONFIG_LIBDIR="!{YYPREFIX}/lib@@LIBDIRSUFFIX@@/pkgconfig"
    put_toolchain_in_path "windows" "@@BITS@@"
  else
    # Cygwin, Linux, possibly any other
    PKG_CONFIG_LIBDIR="@@YYPREFIX_TARGET@@/lib@@LIBDIRSUFFIX@@/pkgconfig"
    put_toolchain_in_path "cross_toolchain" "@@BITS@@"
    put_toolchain_in_path "native_toolchain" ""
  fi

  export PKG_CONFIG_LIBDIR
  echo 'Set ${PKG_CONFIG_LIBDIR}='"${PKG_CONFIG_LIBDIR}"'.' 1>&2
fi