summaryrefslogtreecommitdiff
path: root/autogen-pkg.sh
blob: 0162d71fa08a10e82baa738b1934f563ad444d09 (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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
# guile-gnome
# Copyright (C) 2001,2003,2004 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or    
# modify it under the terms of the GNU General Public License as   
# published by the Free Software Foundation; either version 2 of   
# the License, or (at your option) any later version.              
                                                                 
# This program is distributed in the hope that it will be useful,  
# but WITHOUT ANY WARRANTY; without even the implied warranty of   
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    
# GNU General Public License for more details.                     
                                                                 
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact:

# Free Software Foundation           Voice:  +1-617-542-5942
# 59 Temple Place - Suite 330        Fax:    +1-617-542-2652
# Boston, MA  02111-1307,  USA       gnu@gnu.org

pkgs_ordered=""
checks_catted=""

# Defines the release manager. Packages from someone else will carry a
# date and releaser stamp.
release_manager="Andy Wingo"

sort_pkgs()
{
  local packages="$@"
  ( 
    for pkg in $packages; do
      in_graph=0
      for check in $pkg/*-checks.ac; do
	if [ -f $check ]; then
	  dep_pkg=`echo $check | sed -e "s,^$pkg/\(.*\)-checks\.ac$,\1,"`
	  if [ -d $dep_pkg ]; then
            in_graph=1
	    echo "$pkg $dep_pkg"
	  else
            echo "$checks_catted" | grep -q $dep_pkg;
	    if test $? -eq 1; then
	      cat $check >> configure.ac
	      checks_catted="$checks_catted $dep_pkg"
	    fi
	  fi
        fi
      done
      if test $in_graph -eq 0; then
        echo "$pkg null"
      fi
    done 
  ) | tsort | tac | grep -v '^null$' | tr '\n' ' '
}

get_version()
{
    local packages="$@"
    version_pkgs=""

    for i in $packages; do
        if test -f $i/VERSION; then
            if test -z "$version_pkgs"; then
                version_pkgs=$i
            else
                version_pkgs="$i $version_pkgs"
            fi
        fi
    done

    case `echo "$version_pkgs" | wc -w` in
        0)  
	    version=`date +%Y%m%d`
            echo "+ warning: no subpackage has a VERSION"
            ;;
        1)  
            version=`head -n 1 $version_pkgs/VERSION`
            echo "+ using VERSION $version from $version_pkgs"
            ;;
        *)  
	    version=`date +%Y%m%d`
            echo "+ warning: multiple subpackages with VERSION: $version_pkgs"
            ;;
    esac
}

determine_package()
{
    local packages="$@"

    while read line; do
        if echo $line | egrep -q '^(#.*|[[:space:]]*)$'; then
            continue
        elif echo $line | egrep -qv '^[[:space:]]*[[:alnum:]_-]+:.*$'; then
            echo "Warning: bad PACKAGES statement: $line">&2
            continue
        fi
        package=`echo $line|sed -re 's/^[[:space:]]*([[:alnum:]_-]+):.*$/\\1/'`
        subpackages=`echo $line|sed -re 's/^[^:]*:(.*)$/\\1/'`
        subpackages=`for p in $subpackages; do echo $p; done | sort | xargs echo`
        if test "$packages" = "$subpackages"; then
            return
        fi
    done < PACKAGES
    echo "Warning: package set '$packages' does not form a source package; configuring as guile-gnome-custom"
    package=guile-gnome-custom
}
    
autogen_pkg()
{
    # Check and parse release ID
    # Figure out list of packages
    packages=""
    pkgs_path="."
    for dir in [a-z]*; do
	if [ -f $dir/package.ac ]; then
	    packages="$packages $dir"
	fi
    done
    if test -z "$packages"; then
        echo "No sub-packages present in source tree."
        echo
        echo "You probably just pulled this branch from bzr. Guile-GNOME can"
        echo "be configured to build many different packages, as listed in"
        echo "PACKAGES. To pull those packages from the net, try the scripts"
        echo "in ./scripts/."
        echo
        echo "For example, to check out the source packages for "
        echo "guile-gnome-platform, try:"
        echo
        echo "  ./scripts/get-packages guile-gnome-platform"
        echo
        exit 1
    fi
    packages=`for p in $packages; do echo $p; done | sort | xargs echo`
    determine_package $packages

    # versioning
    get_version $packages
    if bzr whoami | grep -qv "$release_manager"; then
        version="$version+$source";
    fi
    
    echo "+ configuring tree as $package, version $version"

    # prelude of configure.ac
    cat > configure.ac <<EOF
dnl -- WARNING: generated by $0, changes will be lost
AC_PREREQ(2.52)
AC_INIT(autogen-pkg.sh)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE($package, $version)

AC_SUBST(VERSION,$version)

# Meaning of the API version
# --------------------------
#
# If 0, guile-gnome is unstable, and the API might change anytime.
# Otherwise, guile-gnome is stable. Future incompatible releases will
# bump this number so as to allow parallel, incompatible versions to
# coexist.
API_VERSION=0
AC_SUBST(API_VERSION)

AM_MAINTAINER_MODE
AC_DISABLE_STATIC

AC_ISC_POSIX
AC_PROG_CC
AC_STDC_HEADERS
AC_PROG_LIBTOOL

AC_SUBST(AG_PKG_CONFIG_PATH, [\$pkg_config_path])
AG_PACKAGES="$packages"
AC_SUBST(AG_PACKAGES)

if test "x\$prefix" = xNONE; then
   AC_MSG_ERROR([No explicit prefix given.

Guile-GNOME requires you to explicitly enter in a prefix when
configuring. This is because the default prefix, /usr/local, is not in
the default guile load path. What you probably want to do is to run

  \$0 --prefix=/usr

so that guile can find the guile-gnome modules when they are installed.

If you choose to install to a prefix that is not in guile's load path,
you will need to modify GUILE_LOAD_PATH and LD_LIBRARY_PATH every time
you run guile. (Which is a pain.)])
fi

MK=""; AC_SUBST(MK)
EOF

    cat >> configure.ac <<'EOF'
WARN_CFLAGS=-Wall
AC_ARG_ENABLE([Werror], AC_HELP_STRING([--disable-Werror],[Don't stop the build on errors]),
        [], WARN_CFLAGS="-Wall -Werror")
AC_SUBST(WARN_CFLAGS)

DEBUG_CFLAGS=
AC_ARG_ENABLE([debug], AC_HELP_STRING([--disable-debug],[Disable debugging information]),
        [], DEBUG_CFLAGS=-g)
AC_SUBST(DEBUG_CFLAGS)

DISABLE_DEPRECATED=false
AC_ARG_ENABLE([deprecated],
AC_HELP_STRING([--disable-deprecated],[Disable wrapping of functions deprecated upstream]),
        DISABLE_DEPRECATED=true, DISABLE_DEPRECATED=false)

# Optimize the DSO symbol hash table -- see ulrich drepper's paper,
# "how to write shared libraries"
GNULD_LDFLAGS=-Wl,-O1
AC_SUBST(GNULD_LDFLAGS)
AM_LDFLAGS='$(GNULD_LDFLAGS)'
AC_SUBST(AM_LDFLAGS)

#
# Check for Guile
#
AC_MSG_CHECKING(for Guile)
guile-config link > /dev/null || {
   echo "configure: cannot find guile-config; is Guile installed?" 1>&2
   exit 1
}
GUILE_VERSION=`guile-config info guileversion`
if test "$GUILE_VERSION" \< 1.6.4; then
   AC_MSG_ERROR([Guile 1.6.4 or newer is required, but you only have $GUILEVERSION.])
fi
GUILE_CFLAGS="`guile-config compile`"
GUILE_LIBS="`guile-config link`"
AC_SUBST(GUILE_CFLAGS)
AC_SUBST(GUILE_LIBS)
AC_MSG_RESULT(yes)

# Check for g-wrap

PKG_CHECK_MODULES(G_WRAP, g-wrap-2.0-guile >= 1.9.7)
AC_SUBST(G_WRAP_CFLAGS)
AC_SUBST(G_WRAP_LIBS)
AC_SUBST(G_WRAP_MODULE_DIR, `${PKG_CONFIG} --variable=module_directory g-wrap-2.0-guile`)
AC_SUBST(G_WRAP_LIB_DIR, `echo $G_WRAP_MODULE_DIR | sed -e 's|share/guile|lib|'`)

PACKAGES_TO_BUILD=""
PACKAGES_NOT_BUILT=""
record_check()
{
    local package=$1;
    local buildp=$2;
    case $buildp in
        yes|true)
            if test -z "$PACKAGES_TO_BUILD"; then
                PACKAGES_TO_BUILD="$package"
            else
                PACKAGES_TO_BUILD="$package $PACKAGES_TO_BUILD"
            fi
            ;;
        no|false)
            if test -z "$PACKAGES_NOT_BUILT"; then
                PACKAGES_NOT_BUILT="$package"
            else
                PACKAGES_NOT_BUILT="$package $PACKAGES_NOT_BUILT"
            fi
            ;;
        *)
            echo "bad record_check value: \"$buildp\" (for package \"$package\")"
            exit 1
            ;;
    esac
}

report_checks()
{
    if test -z "$PACKAGES_TO_BUILD"; then
        AC_MSG_ERROR([All wrappers failed their prerequisites.

These following wrappers cannot be built:
  $PACKAGES_NOT_BUILT

Check the README files in the above subdirectories, install the necessary
packages, and try again.
])
    elif test -z "$PACKAGES_NOT_BUILT"; then
        AC_MSG_NOTICE([
All available wrappers will be built:
  $PACKAGES_TO_BUILD

])
    else
        AC_MSG_NOTICE([Some packages will not be built.

These wrappers will be built:
  $PACKAGES_TO_BUILD

These wrappers failed their prerequisites and will NOT be built:
  $PACKAGES_NOT_TO_BUILD

Check the README files in the above subdirectories for more information
on the prerequisites of a package.
])
    fi
}

# Per-package checks follow
EOF

    # package checks
    for pkg in $packages; do
      echo "# $pkg" >> configure.ac
      cat $pkg/package.ac >> configure.ac
    done
    
    echo "+ sorting package dependencies..."
    pkgs_ordered=`sort_pkgs $packages`
    echo "  $pkgs_ordered"
    
    # postlude
    (
        echo report_checks
	echo
	echo "AC_CONFIG_FILES(dev-environ, [chmod +x ./dev-environ])"
	echo "AC_CONFIG_FILES("
	echo "Makefile"
	find $packages -name Makefile.am | egrep -v '{arch}|\+\+|,,' | sed -e 's/\.am$//'
	for pkg in $packages; do
	  if [ -f $pkg/files.ac ]; then
	    while read file; do
	      echo "$pkg/$file"
	    done < $pkg/files.ac
	  fi
	done
	echo ")"
	echo "AC_OUTPUT" 
    ) >> configure.ac

    cat > Makefile.am <<EOF
# this file is generated by autogen-pkg.sh

SUBDIRS = $pkgs_ordered
EOF
    cat Makefile.am.bottom >> Makefile.am
}