build_clean.sh 3.87 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] [-S|--srpm] [-g|--git] [-Q|--quick] [-N|--no-dist] [[-w|--with OPTION] ...] [[-W|--without OPTION] ...]"
11
    echo
12
    echo "Does all the steps from a clean git working directory to an RPM of NetworkManager"
13
    echo
14 15 16
    echo "This is also the preferred way to create a distribution tarball for release:"
    echo "  $ $0 -c -S"
    echo
17
    echo "Options:"
18 19 20 21 22 23 24 25
    echo "  -f|--force: force build, even if working directory is not clean and has local modifications"
    echo "  -c|--clean: run \`git-clean -fdx :/\` before build"
    echo "  -S|--srpm: only build the SRPM"
    echo "  -g|--git: create tarball from current git HEAD (skips make dist)"
    echo "  -Q|--quick: only run \`make dist\` instead of \`make distcheck\`"
    echo "  -N|--no-dist: skip creating the source tarball if you already did \`make dist\`"
    echo "  -w|--with \$OPTION: pass --with \$OPTION to rpmbuild. For example --with debug"
    echo "  -W|--without \$OPTION: pass --without \$OPTION to rpmbuild. For example --without debug"
26 27 28 29 30 31 32 33 34 35 36 37
}


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"

38 39
IGNORE_DIRTY=0
GIT_CLEAN=0
40
QUICK=0
41
NO_DIST=0
42
WITH_LIST=()
43
SOURCE_FROM_GIT=0
44

45
_next_with=
46
for A; do
47 48 49 50 51
    if [ -n "$_next_with" ]; then
        WITH_LIST=("${WITH_LIST[@]}" "$_next_with" "$A")
        _next_with=
        continue
    fi
52 53 54 55 56 57 58 59 60 61 62
    case "$A" in
        -h|--help|-\?|help)
            usage
            exit 0
            ;;
        -f|--force)
            IGNORE_DIRTY=1
            ;;
        -c|--clean)
            GIT_CLEAN=1
            ;;
63 64 65
        -S|--srpm)
            BUILDTYPE=SRPM
            ;;
66 67 68 69 70 71 72 73 74 75
        -g|--git)
            NO_DIST=1
            IGNORE_DIRTY=1
            SOURCE_FROM_GIT=1
            ;;
        -Q|--quick)
            NO_DIST=0
            QUICK=1
            SOURCE_FROM_GIT=0
            ;;
76 77
        -N|--no-dist)
            NO_DIST=1
78
            IGNORE_DIRTY=1
79
            SOURCE_FROM_GIT=0
80
            ;;
81 82 83 84 85 86
        -w|--with)
            _next_with=--with
            ;;
        -W|--without)
            _next_with=--without
            ;;
87 88 89 90 91 92 93
        *)
            usage
            die "Unexpected argument \"$A\""
            ;;
    esac
done

94 95
test -n "$_next_with" && die "Missing argument to $_next_with"

96 97 98 99 100 101 102 103
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.
104
    if [[ "x$(LANG=C git clean -ndx | grep '^Would \(remove contrib/\|skip repository libgsystem/\).*$' -v)" != x ]]; then
105
        die "The working directory is not clean. Refuse to run. Try \`$0 --force\`, \`$0 --clean\`, or \`git clean -e :/contrib -dx -n\`"
106 107
    fi
    if [[ "x$(git status --porcelain)" != x ]]; then
108
        die "The working directory has local changes. Refuse to run. Try \`$0 --force\`"
109
    fi
110 111
fi

112
if [[ $NO_DIST != 1 ]]; then
113 114 115 116 117 118 119 120 121 122 123 124 125
    ./autogen.sh --enable-gtk-doc || die "Error autogen.sh"

    if [[ $QUICK == 1 ]]; then
        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
126
fi
127

128
export SOURCE_FROM_GIT
129
export BUILDTYPE
130
export NM_RPMBUILD_ARGS="${WITH_LIST[@]}"
131

132
"$SCRIPTDIR"/build.sh
133