1 dnl dolt, a replacement for libtool
2 dnl Copyright © 2007-2010 Josh Triplett <josh@joshtriplett.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.
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.
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])
18 if test x$DOLT_BASH = x; then
21 if test x$GCC != xyes; then
26 |amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*)
30 pic_options='-fno-common'
39 if test x$dolt_supported = xno ; then
40 AC_MSG_RESULT([no, falling back to libtool])
41 LTCOMPILE='$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
42 LTCXXCOMPILE='$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
43 m4_pattern_allow([AM_V_lt])
45 AC_MSG_RESULT([yes, replacing libtool])
47 dnl Start writing out doltcompile.
48 cat <<__DOLTCOMPILE__EOF__ >doltcompile
51 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
53 for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
54 if test x"${args@<:@$arg@:>@}" = x-o ; then
59 if test x$objarg = x ; then
60 echo 'Error: no -o on compiler command line' 1>&2
63 lo="${args@<:@$objarg@:>@}"
65 if test x"$lo" = x"$obj" ; then
66 echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
72 dnl Write out shared compilation code.
73 if test x$enable_shared = xyes; then
74 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
75 libobjdir="${obj%$objbase}.libs"
76 if test ! -d "$libobjdir" ; then
77 mkdir_out="$(mkdir "$libobjdir" 2>&1)"
79 if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
80 echo "$mkdir_out" 1>&2
84 pic_object="$libobjdir/$objbase.o"
85 args@<:@$objarg@:>@="$pic_object"
87 cat <<__DOLTCOMPILE__EOF__ >>doltcompile
88 "\${args@<:@@@:>@}" $pic_options -DPIC || exit \$?
92 dnl Write out static compilation code.
93 dnl Avoid duplicate compiler output if also building shared objects.
94 if test x$enable_static = xyes; then
95 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
96 non_pic_object="$obj.o"
97 args@<:@$objarg@:>@="$non_pic_object"
99 if test x$enable_shared = xyes; then
100 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
101 "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
104 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
105 "${args@<:@@@:>@}" || exit $?
110 dnl Write out the code to write the .lo file.
111 dnl The second line of the .lo file must match "^# Generated by .*libtool"
112 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
114 echo "# $lo - a libtool object file"
115 echo "# Generated by doltcompile, not libtool"
118 if test x$enable_shared = xyes; then
119 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
120 echo "pic_object='.libs/${objbase}.o'"
123 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
128 if test x$enable_static = xyes; then
129 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
130 echo "non_pic_object='${objbase}.o'"
133 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
134 echo non_pic_object=none
138 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
142 dnl Done writing out doltcompile; substitute it for libtool compilation.
144 LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
145 LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
147 dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
148 dnl a target, so write out a libtool wrapper to handle that case.
149 dnl Note that doltlibtool does not handle inferred tags or option arguments
150 dnl without '=', because automake does not use them.
151 cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
154 cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
155 top_builddir_slash="${0%%doltlibtool}"
156 : ${top_builddir_slash:=./}
160 for arg in "$[]@"; do
162 --mode=compile) modeok=true ;;
163 --tag=CC|--tag=CXX) tagok=true ;;
165 *) args@<:@${#args[@]}@:>@="$arg" ;;
168 if $modeok && $tagok ; then
169 . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
171 exec ${top_builddir_slash}libtool "$[]@"
175 dnl Done writing out doltlibtool; substitute it for libtool.
177 LIBTOOL='$(top_builddir)/doltlibtool'
180 AC_SUBST(LTCXXCOMPILE)