• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1dnl dolt, a replacement for libtool
2dnl Copyright © 2007-2010 Josh Triplett <josh@joshtriplett.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
18AS_IF([test x$DOLT_BASH = x], [dolt_supported=no])
19AS_IF([test x$GCC != xyes], [dolt_supported=no])
20
21AS_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)
27AS_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
35dnl Start writing out doltcompile.
36    cat <<__DOLTCOMPILE__EOF__ >doltcompile
37#!$DOLT_BASH
38__DOLTCOMPILE__EOF__
39    cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
40args=("$[]@")
41for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
42    if test x"${args@<:@$arg@:>@}" = x-o ; then
43        objarg=$((arg+1))
44        break
45    fi
46done
47if test x$objarg = x ; then
48    echo 'Error: no -o on compiler command line' 1>&2
49    exit 1
50fi
51lo="${args@<:@$objarg@:>@}"
52obj="${lo%.lo}"
53if test x"$lo" = x"$obj" ; then
54    echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
55    exit 1
56fi
57objbase="${obj##*/}"
58__DOLTCOMPILE__EOF__
59
60dnl Write out shared compilation code.
61    if test x$enable_shared = xyes; then
62        cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
63libobjdir="${obj%$objbase}.libs"
64if 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
71fi
72pic_object="$libobjdir/$objbase.o"
73args@<:@$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
86dnl Write out static compilation code.
87dnl Avoid duplicate compiler output if also building shared objects.
88    if test x$enable_static = xyes; then
89        cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
90non_pic_object="$obj.o"
91args@<:@$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
104dnl Write out the code to write the .lo file.
105dnl The second line of the .lo file must match "^# Generated by .*libtool"
106    cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
107{
108echo "# $lo - a libtool object file"
109echo "# Generated by doltcompile, not libtool"
110__DOLTCOMPILE__EOF__
111
112    if test x$enable_shared = xyes; then
113        cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
114echo "pic_object='.libs/${objbase}.o'"
115__DOLTCOMPILE__EOF__
116    else
117        cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
118echo pic_object=none
119__DOLTCOMPILE__EOF__
120    fi
121
122    if test x$enable_static = xyes; then
123        cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
124echo "non_pic_object='${objbase}.o'"
125__DOLTCOMPILE__EOF__
126    else
127        cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
128echo non_pic_object=none
129__DOLTCOMPILE__EOF__
130    fi
131
132    cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
133} > "$lo"
134__DOLTCOMPILE__EOF__
135
136dnl 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
141dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
142dnl a target, so write out a libtool wrapper to handle that case.
143dnl Note that doltlibtool does not handle inferred tags or option arguments
144dnl without '=', because automake does not use them.
145    cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
146#!$DOLT_BASH
147__DOLTLIBTOOL__EOF__
148    cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
149top_builddir_slash="${0%%doltlibtool}"
150: ${top_builddir_slash:=./}
151args=()
152modeok=false
153tagok=false
154for 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
163done
164if $modeok && $tagok ; then
165    . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
166else
167    exec ${top_builddir_slash}libtool "$[]@"
168fi
169__DOLTLIBTOOL__EOF__
170
171dnl Done writing out doltlibtool; substitute it for libtool.
172    chmod +x doltlibtool
173    LIBTOOL='$(top_builddir)/doltlibtool'
174
175DOLT_CLEANFILES="doltlibtool doltcompile"
176AC_SUBST(DOLT_CLEANFILES)
177])
178AC_SUBST(LTCOMPILE)
179AC_SUBST(LTCXXCOMPILE)
180# end dolt
181])
182