1 dnl dolt, a replacement for libtool 2 dnl Copyright 2007-2010 Josh Triplett <josh (a] 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. 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 (a] freedesktop.org> 15 AC_PATH_PROG([DOLT_BASH], [bash]) 16 AC_MSG_CHECKING([if dolt supports this host]) 17 dolt_supported=yes 18 AS_IF([test x$DOLT_BASH = x], [dolt_supported=no]) 19 AS_IF([test x$GCC != xyes], [dolt_supported=no]) 20 21 AS_CASE([$host], 22 [*-*-linux*|*-*-freebsd*], [pic_options='-fPIC'], 23 [*-apple-darwin*], [pic_options='-fno-common'], 24 [*mingw*|*nacl*], [pic_options=''] 25 [*], [dolt_supported=no] 26 ) 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]) 32 ], [ 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_out="$(mkdir "$libobjdir" 2>&1)" 66 mkdir_ret=$? 67 if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then 68 echo "$mkdir_out" 1>&2 69 exit $mkdir_ret 70 fi 71 fi 72 pic_object="$libobjdir/$objbase.o" 73 args@<:@$objarg@:>@="$pic_object" 74 __DOLTCOMPILE__EOF__ 75 cat <<__DOLTCOMPILE__EOF__ >>doltcompile 76 pic_options="$pic_options" 77 if test x\$passthrough = xtrue; then 78 pic_options="" 79 fi 80 __DOLTCOMPILE__EOF__ 81 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 82 "${args@<:@@@:>@}" $pic_options -DPIC || exit $? 83 __DOLTCOMPILE__EOF__ 84 fi 85 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" 92 __DOLTCOMPILE__EOF__ 93 if test x$enable_shared = xyes; then 94 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 95 "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $? 96 __DOLTCOMPILE__EOF__ 97 else 98 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 99 "${args@<:@@@:>@}" || exit $? 100 __DOLTCOMPILE__EOF__ 101 fi 102 fi 103 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 107 { 108 echo "# $lo - a libtool object file" 109 echo "# Generated by doltcompile, not libtool" 110 __DOLTCOMPILE__EOF__ 111 112 if test x$enable_shared = xyes; then 113 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 114 echo "pic_object='.libs/${objbase}.o'" 115 __DOLTCOMPILE__EOF__ 116 else 117 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 118 echo pic_object=none 119 __DOLTCOMPILE__EOF__ 120 fi 121 122 if test x$enable_static = xyes; then 123 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 124 echo "non_pic_object='${objbase}.o'" 125 __DOLTCOMPILE__EOF__ 126 else 127 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 128 echo non_pic_object=none 129 __DOLTCOMPILE__EOF__ 130 fi 131 132 cat <<'__DOLTCOMPILE__EOF__' >>doltcompile 133 } > "$lo" 134 __DOLTCOMPILE__EOF__ 135 136 dnl Done writing out doltcompile; substitute it for libtool compilation. 137 chmod +x doltcompile 138 LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)' 139 LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)' 140 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 146 #!$DOLT_BASH 147 __DOLTLIBTOOL__EOF__ 148 cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool 149 top_builddir_slash="${0%%doltlibtool}" 150 : ${top_builddir_slash:=./} 151 args=() 152 modeok=false 153 tagok=false 154 for arg in "$[]@"; do 155 case "$arg" in 156 --mode=compile) modeok=true ;; 157 --tag=CC|--tag=CXX) tagok=true ;; 158 --tag=disable-static) tagok=true ;; 159 --tag=ASM|--tag=YASM) tagok=true; passthrough=true;; 160 --silent|--quiet) ;; 161 *) args@<:@${#args[@]}@:>@="$arg" ;; 162 esac 163 done 164 if $modeok && $tagok ; then 165 . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}" 166 else 167 exec ${top_builddir_slash}libtool "$[]@" 168 fi 169 __DOLTLIBTOOL__EOF__ 170 171 dnl Done writing out doltlibtool; substitute it for libtool. 172 chmod +x doltlibtool 173 LIBTOOL='$(top_builddir)/doltlibtool' 174 175 DOLT_CLEANFILES="doltlibtool doltcompile" 176 AC_SUBST(DOLT_CLEANFILES) 177 ]) 178 AC_SUBST(LTCOMPILE) 179 AC_SUBST(LTCXXCOMPILE) 180 # end dolt 181 ]) 182