2008-05-21 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 dolt supports this host])
17 dolt_supported=yes
18 if test x$DOLT_BASH = x; then
19     dolt_supported=no
20 fi
21 if test x$GCC != xyes; then
22     dolt_supported=no
23 fi
24 case $host in
25 i?86-*-linux*|x86_64-*-linux*|powerpc-*-linux*) ;;
26 amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*) ;;
27 *) dolt_supported=no ;;
28 esac
29 if test x$dolt_supported = xno ; then
30     AC_MSG_RESULT([no, falling back to libtool])
31     LTCOMPILE='$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
32     LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
33 else
34     AC_MSG_RESULT([yes, replacing libtool])
35
36 dnl Start writing out doltcompile.
37     cat <<__DOLTCOMPILE__EOF__ >doltcompile
38 #!$DOLT_BASH
39 __DOLTCOMPILE__EOF__
40     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
41 args=("$[]@")
42 for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
43     if test x"${args@<:@$arg@:>@}" = x-o ; then
44         objarg=$((arg+1))
45         break
46     fi
47 done
48 if test x$objarg = x ; then
49     echo 'Error: no -o on compiler command line' 1>&2
50     exit 1
51 fi
52 lo="${args@<:@$objarg@:>@}"
53 obj="${lo%.lo}"
54 if test x"$lo" = x"$obj" ; then
55     echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
56     exit 1
57 fi
58 objbase="${obj##*/}"
59 __DOLTCOMPILE__EOF__
60
61 dnl Write out shared compilation code.
62     if test x$enable_shared = xyes; then
63         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
64 libobjdir="${obj%$objbase}.libs"
65 if test ! -d "$libobjdir" ; then
66     mkdir_out="$(mkdir "$libobjdir" 2>&1)"
67     mkdir_ret=$?
68     if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
69         echo "$mkdir_out" 1>&2
70         exit $mkdir_ret
71     fi
72 fi
73 pic_object="$libobjdir/$objbase.o"
74 args@<:@$objarg@:>@="$pic_object"
75 "${args@<:@@@:>@}" -fPIC -DPIC || exit $?
76 __DOLTCOMPILE__EOF__
77     fi
78
79 dnl Write out static compilation code.
80 dnl Avoid duplicate compiler output if also building shared objects.
81     if test x$enable_static = xyes; then
82         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
83 non_pic_object="$obj.o"
84 args@<:@$objarg@:>@="$non_pic_object"
85 __DOLTCOMPILE__EOF__
86         if test x$enable_shared = xyes; then
87             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
88 "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
89 __DOLTCOMPILE__EOF__
90         else
91             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
92 "${args@<:@@@:>@}" || exit $?
93 __DOLTCOMPILE__EOF__
94         fi
95     fi
96
97 dnl Write out the code to write the .lo file.
98 dnl The second line of the .lo file must match "^# Generated by .*libtool"
99     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
100 {
101 echo "# $lo - a libtool object file"
102 echo "# Generated by doltcompile, not libtool"
103 __DOLTCOMPILE__EOF__
104
105     if test x$enable_shared = xyes; then
106         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
107 echo "pic_object='$pic_object'"
108 __DOLTCOMPILE__EOF__
109     else
110         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
111 echo pic_object=none
112 __DOLTCOMPILE__EOF__
113     fi
114
115     if test x$enable_static = xyes; then
116         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
117 echo "non_pic_object='$non_pic_object'"
118 __DOLTCOMPILE__EOF__
119     else
120         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
121 echo non_pic_object=none
122 __DOLTCOMPILE__EOF__
123     fi
124
125     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
126 } > "$lo"
127 __DOLTCOMPILE__EOF__
128
129 dnl Done writing out doltcompile; substitute it for libtool compilation.
130     chmod +x doltcompile
131     LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
132     LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
133 fi
134 AC_SUBST(LTCOMPILE)
135 AC_SUBST(LTCXXCOMPILE)
136 # end dolt
137 ])