summaryrefslogtreecommitdiffstats
path: root/tools/mxe-activate
blob: 30fb61fc2320d26d47aa81d5bb4d52ef779f6d28 (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
export MXE_DIR=`pwd`
export BUILD=`$MXE_DIR/ext/config.guess`
export PATH=$MXE_DIR/usr/$BUILD/bin:$MXE_DIR/usr/bin:$PATH
MAKE=`gmake --help >/dev/null 2>&1 && echo g`make
SED=`gsed --help >/dev/null 2>&1 && echo g`sed

MXE_TRIPLETS=`grep ^MXE_TRIPLETS Makefile | cut -d '=' -f2 | cut -d ' ' -f2- | tr ' ' ','`
MXE_LIB_TYPES=`grep ^MXE_LIB_TYPES Makefile | cut -d '=' -f2 | cut -d ' ' -f2- | tr ' ' ','`
MXE_TARGET_LIST=`eval "echo {$MXE_TRIPLETS}.{$MXE_LIB_TYPES}"`

alias mxe='$MAKE -C $MXE_DIR --no-print-directory'

unset `compgen -e | \
    grep -vi '^EDITOR\|^HOME\|^LANG\|MXE\|^PATH' | \
    grep -vi 'PKG_CONFIG\|PROXY\|^PS1\|^TERM' | \
    tr '\n' ' '`

_mxe()
{
    local cur prev pkgs tgts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    pkgs=$( for x in `ls -l $MXE_DIR/src/*.mk | $SED -n 's,.*src/\(.*\)\.mk,\1,p'`; do echo ${x} ; done )
    tgts=$MXE_TARGET_LIST

    case "${cur}" in
    build-only-*_*)
        local base=`echo ${cur} | $SED -n 's,\(.*_\).*,\1,p'`
        local _tgts=$( for x in ${tgts}; do echo $base${x} ; done )
        COMPREPLY=( $(compgen -W "${_tgts}" -- ${cur}) )
        return 0
        ;;
    build-only-*)
        local _pkgs=$( for x in ${pkgs}; do echo build-only-${x} ; done )
        COMPREPLY=( $(compgen -W "${_pkgs}" -- ${cur}) )
        return 0
        ;;
    download-*)
        local _pkgs=$( for x in ${pkgs}; do echo download-${x} ; done )
        COMPREPLY=( $(compgen -W "${_pkgs}" -- ${cur}) )
        return 0
        ;;
    update-checksum-*)
        local _pkgs=$( for x in ${pkgs}; do echo update-checksum-${x} ; done )
        COMPREPLY=( $(compgen -W "${_pkgs}" -- ${cur}) )
        return 0
        ;;
    show-*deps-*)
        local base=`echo ${cur} | $SED -n 's,\(show.*deps-\).*,\1,p'`
        local _pkgs=$( for x in ${pkgs}; do echo $base${x} ; done )
        COMPREPLY=( $(compgen -W "${_pkgs}" -- ${cur}) )
        return 0
        ;;
    [!-]*)
        pkgs+=" build-only- check-requirements clean clean-pkg download download- update-checksum- show-deps- show-downstream-deps- show-upstream-deps-"
        COMPREPLY=( $(compgen -W "${pkgs}" -- ${cur}) )
        return 0
        ;;
    esac

}
complete -o nospace -o default -F _mxe mxe make gmake