summaryrefslogtreecommitdiff
path: root/autogen.sh
blob: 1183b13083c2815c83768bb6a89ca60a50f5cba9 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/sh
# Run this to generate all the initial makefiles, etc.

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

starting_point=$(pwd)

srcdir=$(dirname "$0")
test "$srcdir" || srcdir=.

cd "$srcdir" || {
    die "Failed to cd into $srcdir"
}

test -f src/libvirt.c || {
    die "$0 must live in the top-level libvirt directory"
}

dry_run=
no_git=
gnulib_srcdir=
extra_args=
while test "$#" -gt 0; do
    case "$1" in
    --dry-run)
        # This variable will serve both as an indicator of the fact that
        # a dry run has been requested, and to store the result of the
        # dry run. It will be ultimately used as return code for the
        # script: 0 means no action is necessary, 2 means that autogen.sh
        # needs to be executed, and 1 is reserved for failures
        dry_run=0
        shift
        ;;
    --no-git)
        no_git=" $1"
        shift
        ;;
    --gnulib-srcdir=*)
        gnulib_srcdir=" $1"
        shift
        ;;
    --gnulib-srcdir)
        gnulib_srcdir=" $1=$2"
        shift
        shift
        ;;
    --system)
        prefix=/usr
        sysconfdir=/etc
        localstatedir=/var
        if test -d $prefix/lib64; then
            libdir=$prefix/lib64
        else
            libdir=$prefix/lib
        fi
        extra_args="--prefix=$prefix --localstatedir=$localstatedir"
        extra_args="$extra_args --sysconfdir=$sysconfdir --libdir=$libdir"
        shift
        ;;
    *)
        # All remaining arguments will be passed to configure verbatim
        break
        ;;
    esac
done
no_git="$no_git$gnulib_srcdir"

gnulib_hash()
{
    local no_git=$1

    if test "$no_git"; then
        echo "no-git"
        return
    fi

    # Compute the hash we'll use to determine whether rerunning bootstrap
    # is required. The first is just the SHA1 that selects a gnulib snapshot.
    # The second ensures that whenever we change the set of gnulib modules used
    # by this package, we rerun bootstrap to pull in the matching set of files.
    # The third ensures that whenever we change the set of local gnulib diffs,
    # we rerun bootstrap to pull in those diffs.
    git submodule status .gnulib | awk '{ print $1 }'
    git hash-object bootstrap.conf
    git ls-tree -d HEAD gnulib/local | awk '{ print $3 }'
}

# Only look into git submodules if we're in a git checkout
if test -d .git || test -f .git; then

    # Check for dirty submodules
    if test -z "$CLEAN_SUBMODULE"; then
        for path in $(git submodule status | awk '{ print $2 }'); do
            case "$(git diff "$path")" in
                *-dirty*)
                    echo "error: $path is dirty, please investigate" >&2
                    echo "set CLEAN_SUBMODULE to discard submodule changes" >&2
                    exit 1
                    ;;
            esac
        done
    fi
    if test "$CLEAN_SUBMODULE" && test -z "$no_git"; then
        if test -z "$dry_run"; then
            echo "Cleaning up submodules..."
            git submodule foreach 'git clean -dfqx && git reset --hard' || {
                die "Cleaning up submodules failed"
            }
        fi
    fi

    # Update all submodules. If any of the submodules has not been
    # initialized yet, it will be initialized now; moreover, any submodule
    # with uncommitted changes will be returned to the expected state
    echo "Updating submodules..."
    git submodule update --init || {
        die "Updating submodules failed"
    }

    # The expected hash, eg. the one computed after the last
    # successful bootstrap run, is stored on disk
    state_file=.git-module-status
    expected_hash=$(cat "$state_file" 2>/dev/null)
    actual_hash=$(gnulib_hash "$no_git")

    if test "$actual_hash" = "$expected_hash" && \
       test -f po/Makevars && test -f AUTHORS; then
        # The gnulib hash matches our expectations, and all the files
        # that can only be generated through bootstrap are present:
        # we just need to run autoreconf. Unless we're performing a
        # dry run, of course...
        if test -z "$dry_run"; then
            echo "Running autoreconf..."
            autoreconf -if || {
                die "autoreconf failed"
            }
        fi
    else
        # Whenever the gnulib submodule or any of the related bits
        # has been changed in some way (see gnulib_hash) we need to
        # run bootstrap again. If we're performing a dry run, we
        # change the return code instead to signal our caller
        if test "$dry_run"; then
            dry_run=2
        else
            echo "Running bootstrap..."
            ./bootstrap$no_git --bootstrap-sync || {
                die "bootstrap failed"
            }
            gnulib_hash >"$state_file"
        fi
    fi
fi

# When performing a dry run, we can stop here
test "$dry_run" && exit "$dry_run"

# If asked not to run configure, we can stop here
test "$NOCONFIGURE" && exit 0

cd "$starting_point" || {
    die "Failed to cd into $starting_point"
}

if test "$OBJ_DIR"; then
    mkdir -p "$OBJ_DIR" || {
        die "Failed to create $OBJ_DIR"
    }
    cd "$OBJ_DIR" || {
        die "Failed to cd into $OBJ_DIR"
    }
fi

# Make sure we can find GNU make and tell the user
# the right command to run
MAKE=
for cmd in make gmake; do
    if $cmd -v 2>&1 | grep -q "GNU Make"; then
        MAKE=$cmd
        break
    fi
done
test "$MAKE" || {
    die "GNU make is required to build libvirt"
}

if test -z "$*" && test -z "$extra_args" && test -f config.status; then
    echo "Running config.status..."
    ./config.status --recheck || {
        die "config.status failed"
    }
else
    if test -z "$*" && test -z "$extra_args"; then
        echo "I am going to run configure with no arguments - if you wish"
        echo "to pass any to it, please specify them on the $0 command line."
    else
        echo "Running configure with $extra_args $@"
    fi
    "$srcdir/configure" $extra_args "$@" || {
        die "configure failed"
    }
fi

echo
echo "Now type '$MAKE' to compile libvirt."