ci: Update image list
[libvirt/ericb.git] / autogen.sh
blob9afad8f9d556626927cd3aa4efcaebf8a4e40f69
1 #!/bin/sh
2 # Run this to generate all the initial makefiles, etc.
4 die()
6 echo "error: $1" >&2
7 exit 1
10 starting_point=$(pwd)
12 srcdir=$(dirname "$0")
13 test "$srcdir" || srcdir=.
15 cd "$srcdir" || {
16 die "Failed to cd into $srcdir"
19 test -f src/libvirt.c || {
20 die "$0 must live in the top-level libvirt directory"
23 dry_run=
24 no_git=
25 gnulib_srcdir=
26 extra_args=
27 while test "$#" -gt 0; do
28 case "$1" in
29 --dry-run)
30 # This variable will serve both as an indicator of the fact that
31 # a dry run has been requested, and to store the result of the
32 # dry run. It will be ultimately used as return code for the
33 # script: 0 means no action is necessary, 2 means that autogen.sh
34 # needs to be executed, and 1 is reserved for failures
35 dry_run=0
36 shift
38 --no-git)
39 no_git=" $1"
40 shift
42 --gnulib-srcdir=*)
43 gnulib_srcdir=" $1"
44 shift
46 --gnulib-srcdir)
47 gnulib_srcdir=" $1=$2"
48 shift
49 shift
51 --system)
52 prefix=/usr
53 sysconfdir=/etc
54 localstatedir=/var
55 if test -d $prefix/lib64; then
56 libdir=$prefix/lib64
57 else
58 libdir=$prefix/lib
60 extra_args="--prefix=$prefix --localstatedir=$localstatedir"
61 extra_args="$extra_args --sysconfdir=$sysconfdir --libdir=$libdir"
62 shift
65 # All remaining arguments will be passed to configure verbatim
66 break
68 esac
69 done
70 no_git="$no_git$gnulib_srcdir"
72 gnulib_hash()
74 local no_git=$1
76 if test "$no_git"; then
77 echo "no-git"
78 return
81 # Compute the hash we'll use to determine whether rerunning bootstrap
82 # is required. The first is just the SHA1 that selects a gnulib snapshot.
83 # The second ensures that whenever we change the set of gnulib modules used
84 # by this package, we rerun bootstrap to pull in the matching set of files.
85 # The third ensures that whenever we change the set of local gnulib diffs,
86 # we rerun bootstrap to pull in those diffs.
87 git submodule status .gnulib | awk '{ print $1 }'
88 git hash-object bootstrap.conf
89 git ls-tree -d HEAD gnulib/local | awk '{ print $3 }'
92 # Only look into git submodules if we're in a git checkout
93 if test -d .git || test -f .git; then
95 # Check for dirty submodules
96 if test -z "$CLEAN_SUBMODULE"; then
97 for path in $(git submodule status | awk '{ print $2 }'); do
98 case "$(git diff "$path")" in
99 *-dirty*)
100 echo "error: $path is dirty, please investigate" >&2
101 echo "set CLEAN_SUBMODULE to discard submodule changes" >&2
102 exit 1
104 esac
105 done
107 if test "$CLEAN_SUBMODULE" && test -z "$no_git"; then
108 if test -z "$dry_run"; then
109 echo "Cleaning up submodules..."
110 git submodule foreach 'git clean -dfqx && git reset --hard' || {
111 die "Cleaning up submodules failed"
116 # Update all submodules. If any of the submodules has not been
117 # initialized yet, it will be initialized now; moreover, any submodule
118 # with uncommitted changes will be returned to the expected state
119 echo "Updating submodules..."
120 git submodule update --init || {
121 die "Updating submodules failed"
124 # The expected hash, eg. the one computed after the last
125 # successful bootstrap run, is stored on disk
126 state_file=.git-module-status
127 expected_hash=$(cat "$state_file" 2>/dev/null)
128 actual_hash=$(gnulib_hash "$no_git")
130 if test "$actual_hash" = "$expected_hash" && test -f AUTHORS; then
131 # The gnulib hash matches our expectations, and all the files
132 # that can only be generated through bootstrap are present:
133 # we just need to run autoreconf. Unless we're performing a
134 # dry run, of course...
135 if test -z "$dry_run"; then
136 echo "Running autoreconf..."
137 autoreconf -if || {
138 die "autoreconf failed"
141 else
142 # Whenever the gnulib submodule or any of the related bits
143 # has been changed in some way (see gnulib_hash) we need to
144 # run bootstrap again. If we're performing a dry run, we
145 # change the return code instead to signal our caller
146 if test "$dry_run"; then
147 dry_run=2
148 else
149 echo "Running bootstrap..."
150 ./bootstrap$no_git --bootstrap-sync || {
151 die "bootstrap failed"
153 gnulib_hash >"$state_file"
158 # When performing a dry run, we can stop here
159 test "$dry_run" && exit "$dry_run"
161 # If asked not to run configure, we can stop here
162 test "$NOCONFIGURE" && exit 0
164 cd "$starting_point" || {
165 die "Failed to cd into $starting_point"
168 if test "$OBJ_DIR"; then
169 mkdir -p "$OBJ_DIR" || {
170 die "Failed to create $OBJ_DIR"
172 cd "$OBJ_DIR" || {
173 die "Failed to cd into $OBJ_DIR"
177 # Make sure we can find GNU make and tell the user
178 # the right command to run
179 MAKE=
180 for cmd in make gmake; do
181 if $cmd -v 2>&1 | grep -q "GNU Make"; then
182 MAKE=$cmd
183 break
185 done
186 test "$MAKE" || {
187 die "GNU make is required to build libvirt"
190 if test -z "$*" && test -z "$extra_args" && test -f config.status; then
191 echo "Running config.status..."
192 ./config.status --recheck || {
193 die "config.status failed"
195 else
196 if test -z "$*" && test -z "$extra_args"; then
197 echo "I am going to run configure with no arguments - if you wish"
198 echo "to pass any to it, please specify them on the $0 command line."
199 else
200 echo "Running configure with $extra_args $@"
202 "$srcdir/configure" $extra_args "$@" || {
203 die "configure failed"
207 echo
208 echo "Now type '$MAKE' to compile libvirt."