]> git.sesse.net Git - vlc/blob - m4/dolt.m4
m4: enable dolt support for further apple platforms
[vlc] / m4 / dolt.m4
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.
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@freedesktop.org>
15 AC_PATH_PROG(DOLT_BASH, bash)
16 AC_MSG_CHECKING([if dolt supports this host])
17 dolt_supported=yes
18 if test x$DOLT_BASH = x; then
19     dolt_supported=no
20 fi
21 if test x$GCC != xyes; then
22     dolt_supported=no
23 fi
24 case $host in
25 *-*-linux* \
26 |amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*)
27     pic_options='-fPIC'
28     ;;
29 *-apple-darwin*)
30     pic_options='-fno-common'
31     ;;
32 *mingw*|*nacl*)
33     pic_options=''
34     ;;
35 *)
36     dolt_supported=no
37     ;;
38 esac
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])
44 else
45     AC_MSG_RESULT([yes, replacing libtool])
46
47 dnl Start writing out doltcompile.
48     cat <<__DOLTCOMPILE__EOF__ >doltcompile
49 #!$DOLT_BASH
50 __DOLTCOMPILE__EOF__
51     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
52 args=("$[]@")
53 for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
54     if test x"${args@<:@$arg@:>@}" = x-o ; then
55         objarg=$((arg+1))
56         break
57     fi
58 done
59 if test x$objarg = x ; then
60     echo 'Error: no -o on compiler command line' 1>&2
61     exit 1
62 fi
63 lo="${args@<:@$objarg@:>@}"
64 obj="${lo%.lo}"
65 if test x"$lo" = x"$obj" ; then
66     echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
67     exit 1
68 fi
69 objbase="${obj##*/}"
70 __DOLTCOMPILE__EOF__
71
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)"
78     mkdir_ret=$?
79     if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
80         echo "$mkdir_out" 1>&2
81         exit $mkdir_ret
82     fi
83 fi
84 pic_object="$libobjdir/$objbase.o"
85 args@<:@$objarg@:>@="$pic_object"
86 __DOLTCOMPILE__EOF__
87     cat <<__DOLTCOMPILE__EOF__ >>doltcompile
88 "\${args@<:@@@:>@}" $pic_options -DPIC || exit \$?
89 __DOLTCOMPILE__EOF__
90     fi
91
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"
98 __DOLTCOMPILE__EOF__
99         if test x$enable_shared = xyes; then
100             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
101 "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
102 __DOLTCOMPILE__EOF__
103         else
104             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
105 "${args@<:@@@:>@}" || exit $?
106 __DOLTCOMPILE__EOF__
107         fi
108     fi
109
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
113 {
114 echo "# $lo - a libtool object file"
115 echo "# Generated by doltcompile, not libtool"
116 __DOLTCOMPILE__EOF__
117
118     if test x$enable_shared = xyes; then
119         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
120 echo "pic_object='.libs/${objbase}.o'"
121 __DOLTCOMPILE__EOF__
122     else
123         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
124 echo pic_object=none
125 __DOLTCOMPILE__EOF__
126     fi
127
128     if test x$enable_static = xyes; then
129         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
130 echo "non_pic_object='${objbase}.o'"
131 __DOLTCOMPILE__EOF__
132     else
133         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
134 echo non_pic_object=none
135 __DOLTCOMPILE__EOF__
136     fi
137
138     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
139 } > "$lo"
140 __DOLTCOMPILE__EOF__
141
142 dnl Done writing out doltcompile; substitute it for libtool compilation.
143     chmod +x doltcompile
144     LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
145     LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
146
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
152 #!$DOLT_BASH
153 __DOLTLIBTOOL__EOF__
154     cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
155 top_builddir_slash="${0%%doltlibtool}"
156 : ${top_builddir_slash:=./}
157 args=()
158 modeok=false
159 tagok=false
160 for arg in "$[]@"; do
161     case "$arg" in
162         --mode=compile) modeok=true ;;
163         --tag=CC|--tag=CXX) tagok=true ;;
164         --silent|--quiet) ;;
165         *) args@<:@${#args[@]}@:>@="$arg" ;;
166     esac
167 done
168 if $modeok && $tagok ; then
169     . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
170 else
171     exec ${top_builddir_slash}libtool "$[]@"
172 fi
173 __DOLTLIBTOOL__EOF__
174
175 dnl Done writing out doltlibtool; substitute it for libtool.
176     chmod +x doltlibtool
177     LIBTOOL='$(top_builddir)/doltlibtool'
178 fi
179 AC_SUBST(LTCOMPILE)
180 AC_SUBST(LTCXXCOMPILE)
181 # end dolt
182 ])