summarylogtreecommitdiffstats
path: root/makepkg-mingw
blob: 15647f0beef9df51ff0d509bf991ba355226d50a (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
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
#!/usr/bin/env bash
#   makepkg-mingw - wrapper for makepkg to build mingw-w64 packages under  MSYS2
#
#   Copyright (c) 2013 Alexey Pavlov <alexpux@gmail.com>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

set -e

plain() {
  local mesg=$1; shift
  printf "${BOLD}    ${mesg}${ALL_OFF}\n" "$@" >&2
}

print_warning() {
  local mesg=$1; shift
  printf "${YELLOW}=> WARNING:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

print_msg1() {
  local mesg=$1; shift
  printf "${GREEN}==> ${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

print_msg2() {
  local mesg=$1; shift
  printf "${BLUE}  ->${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

print_error() {
  local mesg=$1; shift
  printf "${RED}==> ERROR:${ALL_OFF}${BOLD} ${mesg}${ALL_OFF}\n" "$@" >&2
}

if /usr/bin/tput setaf 0 &>/dev/null; then
  ALL_OFF="$(/usr/bin/tput sgr0)"
  BOLD="$(/usr/bin/tput bold)"
  BLUE="${BOLD}$(/usr/bin/tput setaf 4)"
  GREEN="${BOLD}$(/usr/bin/tput setaf 2)"
  RED="${BOLD}$(/usr/bin/tput setaf 1)"
  YELLOW="${BOLD}$(/usr/bin/tput setaf 3)"
else
  ALL_OFF="\e[1;0m"
  BOLD="\e[1;1m"
  BLUE="${BOLD}\e[1;34m"
  GREEN="${BOLD}\e[1;32m"
  RED="${BOLD}\e[1;31m"
  YELLOW="${BOLD}\e[1;33m"
fi

readonly ALL_OFF BOLD BLUE GREEN RED YELLOW

# For certain flags skip our processing and just forward to makepkg
for _arg in "$@"; do
  if [ "${_arg}" = "--help" ] || [ "${_arg}" = "-h" ]; then
    /usr/bin/makepkg "$@"
    echo -e "makepkg-mingw:\n"
    echo '  $MINGW_ARCH      Space separated list of environments to build for.'
    echo '                   Defaults to the active environment.'
    exit 0
  fi
  if [ "${_arg}" = "--version" ] || [ "${_arg}" = "-V" ]; then
    /usr/bin/makepkg "$@"
    exit 0
  fi
done

# For backwards compatibility
if [[ -z "${MINGW_ARCH}" ]] && [[ -n "${MINGW_INSTALLS}" ]]; then
  print_warning "MINGW_INSTALLS is deprecated, use MINGW_ARCH instead"
  MINGW_ARCH="${MINGW_INSTALLS}";
fi

# Validate or set MINGW_ARCH
MINGW_ARCH_ALLOWED=('mingw32' 'mingw64' 'clang32' 'clang64' 'clangarm64' 'ucrt64')
MINGW_ARCH="${MINGW_ARCH,,}"
if [[ -z "$MINGW_ARCH" ]]; then
  # In case MINGW_ARCH isn't set we default to MSYSTEM, or error out
  if [[ " ${MINGW_ARCH_ALLOWED[*]} " = *" ${MSYSTEM,,} "* ]]; then
    MINGW_ARCH="${MSYSTEM,,}"
  else
    print_warning 'MINGW_ARCH not set and not called from a MINGW environment, defaulting to mingw64. This will fail in the future!'
    MINGW_ARCH='mingw64'
  fi
else
  # Make sure MINGW_ARCH is valid
  for _mingw in ${MINGW_ARCH}; do
    if [[ ! " ${MINGW_ARCH_ALLOWED[*]} " = *" ${_mingw} "* ]]; then
      print_error "MINGW_ARCH: '${_mingw}' unknown, possible values: ${MINGW_ARCH_ALLOWED[*]}"
      exit 1
    fi
  done
fi
print_msg1 "MINGW_ARCH: ${MINGW_ARCH}"

for _mingw in ${MINGW_ARCH}; do
  print_msg2 "Building ${_mingw}..."

  MSYSTEM="${_mingw^^}" \
  CHERE_INVOKING=1 \
    bash -leo pipefail -c "/usr/bin/makepkg --config /etc/makepkg_mingw.conf \"\$@\"" bash "$@"

done

exit 0