2008-06-25 Zoltan Varga <vargaz@gmail.com>
[mono.git] / acinclude.m4
1 dnl dolt, a replacement for libtool
2 dnl Copyright © 2007-2008 Josh Triplett <josh@freedesktop.org>
3 dnl Copying and distribution of this file, with or without modification,
4 dnl are permitted in any medium without royalty provided the copyright
5 dnl notice and this notice are preserved.
6 dnl
7 dnl To use dolt, invoke the DOLT macro immediately after the libtool macros.
8 dnl Optionally, copy this file into acinclude.m4, to avoid the need to have it
9 dnl installed when running autoconf on your project.
10
11 AC_DEFUN([DOLT], [
12 AC_REQUIRE([AC_CANONICAL_HOST])
13 # dolt, a replacement for libtool
14 # Josh Triplett <josh@freedesktop.org>
15 AC_PATH_PROG(DOLT_BASH, bash)
16 AC_MSG_CHECKING([if libtool sucks])
17 AC_MSG_RESULT([yup, it does])
18 AC_MSG_CHECKING([if dolt supports this host])
19 dolt_supported=yes
20 if test x$DOLT_BASH = x; then
21     dolt_supported=no
22 fi
23 if test x$GCC != xyes; then
24     dolt_supported=no
25 fi
26 case $host in
27 i?86-*-linux*|x86_64-*-linux*) ;;
28 *) dolt_supported=no ;;
29 esac
30 if test x$dolt_supported = xno ; then
31     AC_MSG_RESULT([no, falling back to libtool])
32 else
33     AC_MSG_RESULT([yes, replacing libtool])
34
35 dnl Start writing out doltcompile.
36     cat <<__DOLTCOMPILE__EOF__ >doltcompile
37 #!$DOLT_BASH
38 __DOLTCOMPILE__EOF__
39     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
40 args=("$[]@")
41 for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
42     if test x"${args@<:@$arg@:>@}" = x-o ; then
43         objarg=$((arg+1))
44         break
45     fi
46 done
47 if test x$objarg = x ; then
48     echo 'Error: no -o on compiler command line' 1>&2
49     exit 1
50 fi
51 lo="${args@<:@$objarg@:>@}"
52 obj="${lo%.lo}"
53 if test x"$lo" = x"$obj" ; then
54     echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
55     exit 1
56 fi
57 objbase="${obj##*/}"
58 __DOLTCOMPILE__EOF__
59
60 dnl Write out shared compilation code.
61     if test x$enable_shared = xyes; then
62         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
63 libobjdir="${obj%$objbase}.libs"
64 if test ! -d "$libobjdir" ; then
65     mkdir "$libobjdir"
66     mkdir_ret=$?
67     if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
68         exit $mkdir_ret
69     fi
70 fi
71 pic_object="$libobjdir/$objbase.o"
72 args@<:@$objarg@:>@="$pic_object"
73 "${args@<:@@@:>@}" -fPIC -DPIC
74 __DOLTCOMPILE__EOF__
75     fi
76
77 dnl Write out static compilation code.
78 dnl Avoid duplicate compiler output if also building shared objects.
79     if test x$enable_static = xyes; then
80         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
81 non_pic_object="$obj.o"
82 args@<:@$objarg@:>@="$non_pic_object"
83 __DOLTCOMPILE__EOF__
84         if test x$enable_shared = xyes; then
85             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
86 "${args@<:@@@:>@}" >/dev/null 2>&1
87 __DOLTCOMPILE__EOF__
88         else
89             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
90 "${args@<:@@@:>@}"
91 __DOLTCOMPILE__EOF__
92         fi
93     fi
94
95 dnl Write out the code to write the .lo file.
96 dnl The second line of the .lo file must match "^# Generated by .*libtool"
97     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
98 {
99 echo "# $lo - a libtool object file"
100 echo "# Generated by doltcompile, not libtool"
101 __DOLTCOMPILE__EOF__
102
103     if test x$enable_shared = xyes; then
104         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
105 echo "pic_object='$pic_object'"
106 __DOLTCOMPILE__EOF__
107     else
108         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
109 echo pic_object=none
110 __DOLTCOMPILE__EOF__
111     fi
112
113     if test x$enable_static = xyes; then
114         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
115 echo "non_pic_object='$non_pic_object'"
116 __DOLTCOMPILE__EOF__
117     else
118         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
119 echo non_pic_object=none
120 __DOLTCOMPILE__EOF__
121     fi
122
123     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
124 } > "$lo"
125 __DOLTCOMPILE__EOF__
126
127 dnl Done writing out doltcompile; substitute it for libtool compilation.
128     chmod +x doltcompile
129     LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
130     AC_SUBST(LTCOMPILE)
131     LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
132     AC_SUBST(LTCXXCOMPILE)
133 fi
134 # end dolt
135 ])