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 AS_IF([test x$DOLT_BASH = x], [dolt_supported=no])
19 AS_IF([test x$GCC != xyes], [dolt_supported=no])
22 [*-*-linux*|*-*-freebsd*], [pic_options='-fPIC'],
23 [*-apple-darwin*], [pic_options='-fno-common'],
24 [*mingw*|*nacl*], [pic_options='']
25 [*], [dolt_supported=no]
27 AS_IF([test x$dolt_supported = xno], [
28 AC_MSG_RESULT([no, falling back to libtool])
29 LTCOMPILE='$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
30 LTCXXCOMPILE='$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
31 m4_pattern_allow([AM_V_lt])
33 AC_MSG_RESULT([yes, replacing libtool])
35 dnl Start writing out doltcompile.
36 cat <<__DOLTCOMPILE__EOF__ >doltcompile
39 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
41 for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
42 if test x"${args@<:@$arg@:>@}" = x-o ; then
47 if test x$objarg = x ; then
48 echo 'Error: no -o on compiler command line' 1>&2
51 lo="${args@<:@$objarg@:>@}"
53 if test x"$lo" = x"$obj" ; then
54 echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
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_out="$(mkdir "$libobjdir" 2>&1)"
67 if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
68 echo "$mkdir_out" 1>&2
72 pic_object="$libobjdir/$objbase.o"
73 args@<:@$objarg@:>@="$pic_object"
75 cat <<__DOLTCOMPILE__EOF__ >>doltcompile
76 pic_options="$pic_options"
77 if test x\$passthrough = xtrue; then
81 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
82 ${args@<:@@@:>@} $pic_options -DPIC || exit $?
86 dnl Write out static compilation code.
87 dnl Avoid duplicate compiler output if also building shared objects.
88 if test x$enable_static = xyes; then
89 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
90 non_pic_object="$obj.o"
91 args@<:@$objarg@:>@="$non_pic_object"
93 if test x$enable_shared = xyes; then
94 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
95 "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
98 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
99 "${args@<:@@@:>@}" || exit $?
104 dnl Write out the code to write the .lo file.
105 dnl The second line of the .lo file must match "^# Generated by .*libtool"
106 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
108 echo "# $lo - a libtool object file"
109 echo "# Generated by doltcompile, not libtool"
112 if test x$enable_shared = xyes; then
113 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
114 echo "pic_object='.libs/${objbase}.o'"
117 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
122 if test x$enable_static = xyes; then
123 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
124 echo "non_pic_object='${objbase}.o'"
127 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
128 echo non_pic_object=none
132 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
136 dnl Done writing out doltcompile; substitute it for libtool compilation.
138 LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
139 LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
141 dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
142 dnl a target, so write out a libtool wrapper to handle that case.
143 dnl Note that doltlibtool does not handle inferred tags or option arguments
144 dnl without '=', because automake does not use them.
145 cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
148 cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
149 top_builddir_slash="${0%%doltlibtool}"
150 : ${top_builddir_slash:=./}
154 for arg in "$[]@"; do
156 --mode=compile) modeok=true ;;
157 --tag=CC|--tag=CXX) tagok=true ;;
158 --tag=ASM|--tag=YASM) tagok=true; passthrough=true;;
160 *) args@<:@${#args[@]}@:>@="$arg" ;;
163 if $modeok && $tagok ; then
164 . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
166 exec ${top_builddir_slash}libtool "$[]@"
170 dnl Done writing out doltlibtool; substitute it for libtool.
172 LIBTOOL='$(top_builddir)/doltlibtool'
174 DOLT_CLEANFILES="doltlibtool doltcompile"
175 AC_SUBST(DOLT_CLEANFILES)
178 AC_SUBST(LTCXXCOMPILE)