1dnl dolt, a replacement for libtool 2dnl Copyright © 2007-2008 Josh Triplett <josh@freedesktop.org> 3dnl Copying and distribution of this file, with or without modification, 4dnl are permitted in any medium without royalty provided the copyright 5dnl notice and this notice are preserved. 6dnl 7dnl To use dolt, invoke the DOLT macro immediately after the libtool macros. 8dnl Optionally, copy this file into acinclude.m4, to avoid the need to have it 9dnl installed when running autoconf on your project. 10 11AC_DEFUN([DOLT], [ 12AC_REQUIRE([AC_CANONICAL_HOST]) 13# dolt, a replacement for libtool 14# Josh Triplett <josh@freedesktop.org> 15AC_PATH_PROG(DOLT_BASH, bash) 16AC_MSG_CHECKING([if dolt supports this host]) 17dolt_supported=yes 18if test x$DOLT_BASH = x; then 19 dolt_supported=no 20fi 21if test x$GCC != xyes; then 22 dolt_supported=no 23fi 24case $host in 25i?86-*-linux*|x86_64-*-linux*|powerpc-*-linux* \ 26|amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*) 27 pic_options='-fPIC' 28 ;; 29i?86-apple-darwin*) 30 pic_options='-fno-common' 31 ;; 32*mingw32*) 33 pic_options='-DDLL_EXPORT' 34 ;; 35*) 36 dolt_supported=no 37 ;; 38esac 39if test x$dolt_supported = xno ; then 40 AC_MSG_RESULT([no, falling back to libtool]) 41 LTCOMPILE='$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)' 42 LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)' 43else 44 AC_MSG_RESULT([yes, replacing libtool]) 45 46dnl Start writing out doltcompile. 47 cat <<__DOLTCOMPILE__EOF__ >doltcompile 48#!$DOLT_BASH 49__DOLTCOMPILE__EOF__ 50 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 51args=("$[]@") 52for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do 53 if test x"${args@<:@$arg@:>@}" = x-o ; then 54 objarg=$((arg+1)) 55 break 56 fi 57done 58if test x$objarg = x ; then 59 echo 'Error: no -o on compiler command line' 1>&2 60 exit 1 61fi 62lo="${args@<:@$objarg@:>@}" 63obj="${lo%.lo}" 64if test x"$lo" = x"$obj" ; then 65 echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2 66 exit 1 67fi 68objbase="${obj##*/}" 69__DOLTCOMPILE__EOF__ 70 71dnl Write out shared compilation code. 72 if test x$enable_shared = xyes; then 73 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 74libobjdir="${obj%$objbase}.libs" 75if test ! -d "$libobjdir" ; then 76 mkdir_out="$(mkdir "$libobjdir" 2>&1)" 77 mkdir_ret=$? 78 if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then 79 echo "$mkdir_out" 1>&2 80 exit $mkdir_ret 81 fi 82fi 83pic_object="$libobjdir/$objbase.o" 84args@<:@$objarg@:>@="$pic_object" 85__DOLTCOMPILE__EOF__ 86 cat <<__DOLTCOMPILE__EOF__ >>doltcompile 87"\${args@<:@@@:>@}" $pic_options -DPIC || exit \$? 88__DOLTCOMPILE__EOF__ 89 fi 90 91dnl Write out static compilation code. 92dnl Avoid duplicate compiler output if also building shared objects. 93 if test x$enable_static = xyes; then 94 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 95non_pic_object="$obj.o" 96args@<:@$objarg@:>@="$non_pic_object" 97__DOLTCOMPILE__EOF__ 98 if test x$enable_shared = xyes; then 99 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 100"${args@<:@@@:>@}" >/dev/null 2>&1 || exit $? 101__DOLTCOMPILE__EOF__ 102 else 103 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 104"${args@<:@@@:>@}" || exit $? 105__DOLTCOMPILE__EOF__ 106 fi 107 fi 108 109dnl Write out the code to write the .lo file. 110dnl The second line of the .lo file must match "^# Generated by .*libtool" 111 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 112{ 113echo "# $lo - a libtool object file" 114echo "# Generated by doltcompile, not libtool" 115__DOLTCOMPILE__EOF__ 116 117 if test x$enable_shared = xyes; then 118 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 119echo "pic_object='.libs/${objbase}.o'" 120__DOLTCOMPILE__EOF__ 121 else 122 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 123echo pic_object=none 124__DOLTCOMPILE__EOF__ 125 fi 126 127 if test x$enable_static = xyes; then 128 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 129echo "non_pic_object='${objbase}.o'" 130__DOLTCOMPILE__EOF__ 131 else 132 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 133echo non_pic_object=none 134__DOLTCOMPILE__EOF__ 135 fi 136 137 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 138} > "$lo" 139__DOLTCOMPILE__EOF__ 140 141dnl Done writing out doltcompile; substitute it for libtool compilation. 142 chmod +x doltcompile 143 LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)' 144 LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)' 145 146dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for 147dnl a target, so write out a libtool wrapper to handle that case. 148dnl Note that doltlibtool does not handle inferred tags or option arguments 149dnl without '=', because automake does not use them. 150 cat <<__DOLTLIBTOOL__EOF__ > doltlibtool 151#!$DOLT_BASH 152__DOLTLIBTOOL__EOF__ 153 cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool 154top_builddir_slash="${0%%doltlibtool}" 155: ${top_builddir_slash:=./} 156args=() 157modeok=false 158tagok=false 159for arg in "$[]@"; do 160 case "$arg" in 161 --silent) ;; 162 --mode=compile) modeok=true ;; 163 --tag=CC|--tag=CXX) tagok=true ;; 164 *) args@<:@${#args[@]}@:>@="$arg" ;; 165 esac 166done 167if $modeok && $tagok ; then 168 . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}" 169else 170 exec ${top_builddir_slash}libtool "$[]@" 171fi 172__DOLTLIBTOOL__EOF__ 173 174dnl Done writing out doltlibtool; substitute it for libtool. 175 chmod +x doltlibtool 176 LIBTOOL='$(top_builddir)/doltlibtool' 177fi 178AC_SUBST(LTCOMPILE) 179AC_SUBST(LTCXXCOMPILE) 180# end dolt 181]) 182