build_clean.sh 3.12 KB
Newer Older
1 2 3 4 5 6 7 8
#!/bin/bash


die() {
    echo "$*" >&2
    exit 1
}

9
usage() {
10
    echo "USAGE: $0 [-h|--help|-?|help] [-f|--force] [-c|--clean] [-Q|--quick]"
11 12 13
    echo
    echo "Does all the steps from a clean working directory to an RPM of NetworkManager"
    echo
14 15 16
    echo "Options:"
    echo "  --force: force build, even if working directory is not clean and has local modifications"
    echo "  --clean: run \`git-clean -fdx :/\` before build"
17
    echo "  --quick: only run \`make dist\` instead of \`make distcheck\`"
18
    echo "  --srpm: only build the SRPM"
19 20 21 22 23 24 25 26 27 28 29 30
}


ORIGDIR="$(readlink -f "$PWD")"
SCRIPTDIR="$(dirname "$(readlink -f "$0")")"
GITDIR="$(cd "$SCRIPTDIR" && git rev-parse --show-toplevel || die "Could not get GITDIR")"


[[ -x "$SCRIPTDIR"/build.sh ]] || die "could not find \"$SCRIPTDIR/build.sh\""

cd "$GITDIR" || die "could not change to $GITDIR"

31 32
IGNORE_DIRTY=0
GIT_CLEAN=0
33
QUICK=0
34
NO_BUILD=0
35
WITH_LIST=()
36

37
_next_with=
38
for A; do
39 40 41 42 43
    if [ -n "$_next_with" ]; then
        WITH_LIST=("${WITH_LIST[@]}" "$_next_with" "$A")
        _next_with=
        continue
    fi
44 45 46 47 48 49 50 51 52 53 54
    case "$A" in
        -h|--help|-\?|help)
            usage
            exit 0
            ;;
        -f|--force)
            IGNORE_DIRTY=1
            ;;
        -c|--clean)
            GIT_CLEAN=1
            ;;
55 56 57
        -Q|--quick)
            QUICK=1
            ;;
58 59 60
        -S|--srpm)
            BUILDTYPE=SRPM
            ;;
61 62 63 64
        -N|--no-build)
            NO_BUILD=1
            IGNORE_DIRTY=1
            ;;
65 66 67 68 69 70
        -w|--with)
            _next_with=--with
            ;;
        -W|--without)
            _next_with=--without
            ;;
71 72 73 74 75 76 77
        *)
            usage
            die "Unexpected argument \"$A\""
            ;;
    esac
done

78 79
test -n "$_next_with" && die "Missing argument to $_next_with"

80 81 82 83 84 85 86 87
if [[ $GIT_CLEAN == 1 ]]; then
    git clean -fdx :/
fi

if [[ $IGNORE_DIRTY != 1 ]]; then
    # check for a clean working directory.
    # We ignore the /contrib directory, because this is where the automation
    # scripts and the build results will be.
88
    if [[ "x$(LANG=C git clean -ndx | grep '^Would \(remove contrib/\|skip repository libgsystem/\).*$' -v)" != x ]]; then
89
        die "The working directory is not clean. Refuse to run. Try \`$0 --force\`, \`$0 --clean\`, or \`git clean -e :/contrib -dx -n\`"
90 91
    fi
    if [[ "x$(git status --porcelain)" != x ]]; then
92
        die "The working directory has local changes. Refuse to run. Try \`$0 --force\`"
93
    fi
94 95
fi

96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
if [[ $NO_BUILD != 1 ]]; then
    ./autogen.sh --enable-gtk-doc || die "Error autogen.sh"

    if [[ $QUICK == 1 ]]; then
        make -C shared || die "Error make -C shared"
        make -C introspection || die "Error make -C introspection"
        make -C libnm-core || die "Error make -C libnm-core"
        make -C libnm || die "Error make -C libnm"
        make -C libnm-util || die "Error make -C libnm-util"
        make -C libnm-glib || die "Error make -C libnm-glib"
        make dist || die "Error make distcheck"
    else
        make -j 10 || die "Error make"
        make distcheck || die "Error make distcheck"
    fi
111
fi
112

113
export BUILDTYPE
114
export NM_RPMBUILD_ARGS="${WITH_LIST[@]}"
115

116
"$SCRIPTDIR"/build.sh
117