build_clean.sh 4.96 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
    echo "  -s|--snapshot TEXT: use TEXT as the snapshot version for the new package (overwrites \$NM_BUILD_SNAPSHOT environment)"
27
    echo "  -r|--release: built a release tarball (this option must be alone)"
28 29 30 31 32 33 34 35 36 37 38 39
}


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"

40 41
IGNORE_DIRTY=0
GIT_CLEAN=0
42
QUICK=0
43
NO_DIST=0
44
WITH_LIST=(--with test)
45
SOURCE_FROM_GIT=0
46
SNAPSHOT="$NM_BUILD_SNAPSHOT"
47

48 49
NARGS=$#

50 51 52
while [[ $# -gt 0 ]]; do
    A="$1"
    shift
53 54 55 56 57 58 59 60
    case "$A" in
        -h|--help|-\?|help)
            usage
            exit 0
            ;;
        -f|--force)
            IGNORE_DIRTY=1
            ;;
61 62 63 64 65
        -r|--release)
            [[ $NARGS -eq 1 ]] || die "--release option must be alone"
            export NMTST_CHECK_GTK_DOC=1
            BUILDTYPE=SRPM
            ;;
66 67 68
        -c|--clean)
            GIT_CLEAN=1
            ;;
69 70 71
        -S|--srpm)
            BUILDTYPE=SRPM
            ;;
72 73 74 75 76
        -s|--snapshot)
            [[ $# -gt 0 ]] || die "Missing argument to $A"
            SNAPSHOT="$1"
            shift
            ;;
77 78 79 80 81 82 83 84
        -g|--git)
            NO_DIST=1
            IGNORE_DIRTY=1
            SOURCE_FROM_GIT=1
            ;;
        -Q|--quick)
            QUICK=1
            ;;
85 86
        -N|--no-dist)
            NO_DIST=1
87
            IGNORE_DIRTY=1
88
            SOURCE_FROM_GIT=0
89
            ;;
90
        -w|--with)
91 92 93
            [[ $# -gt 0 ]] || die "Missing argument to $A"
            WITH_LIST=("${WITH_LIST[@]}" "--with" "$1")
            shift
94 95
            ;;
        -W|--without)
96 97 98
            [[ $# -gt 0 ]] || die "Missing argument to $A"
            WITH_LIST=("${WITH_LIST[@]}" "--without" "$1")
            shift
99
            ;;
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
        *)
            usage
            die "Unexpected argument \"$A\""
            ;;
    esac
done

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.
115
    if [[ "x$(LANG=C git clean -ndx | grep '^Would \(remove contrib/\|skip repository libgsystem/\).*$' -v)" != x ]]; then
116
        die "The working directory is not clean. Refuse to run. Try \`$0 --force\`, \`$0 --clean\`, or \`git clean -e :/contrib -dx -n\`"
117 118
    fi
    if [[ "x$(git status --porcelain)" != x ]]; then
119
        die "The working directory has local changes. Refuse to run. Try \`$0 --force\`"
120
    fi
121 122
fi

123
if [[ $NO_DIST != 1 ]]; then
124
    ./autogen.sh \
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
        --program-prefix= \
        --prefix=/usr \
        --exec-prefix=/usr \
        --bindir=/usr/bin \
        --sbindir=/usr/sbin \
        --sysconfdir=/etc \
        --datadir=/usr/share \
        --includedir=/usr/include \
        --libdir=/usr/lib \
        --libexecdir=/usr/libexec \
        --localstatedir=/var \
        --sharedstatedir=/var/lib \
        --mandir=/usr/share/man \
        --infodir=/usr/share/info \
        \
        --disable-dependency-tracking \
141 142 143 144 145 146 147 148 149 150 151 152
        --enable-gtk-doc \
        --enable-introspection \
        --with-libnm-glib \
        --enable-ifcfg-rh \
        --enable-ifupdown \
        --enable-ibft \
        --with-config-logging-backend-default=syslog \
        --with-libaudit=yes-disabled-by-default \
        --enable-polkit=yes \
        --with-config-dhcp-default=internal \
        --with-config-dns-rc-manager-default=symlink \
        || die "Error autogen.sh"
153
    if [[ $QUICK == 1 ]]; then
154
        make dist -j 7 || die "Error make dist"
155
    else
156
        make distcheck -j 7 || die "Error make distcheck"
157
    fi
158
fi
159

160
export SOURCE_FROM_GIT
161
export BUILDTYPE
162
export NM_RPMBUILD_ARGS="${WITH_LIST[@]}"
163
export SNAPSHOT
164

165
"$SCRIPTDIR"/build.sh
166