Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / acinclude.m4
1 dnl dolt, a replacement for libtool
2 dnl Copyright © 2007-2008 Josh Triplett <josh@freedesktop.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 i?86-*-linux*|i?86-apple-darwin*|x86_64-*-linux*|powerpc-*-linux*|powerpc64-*-linux* \
26 |amd64-*-freebsd*|i?86-*-freebsd*|ia64-*-freebsd*|arm*-*-linux*|sparc*-*-linux*|mips*-*-linux*|x86_64-apple-darwin*|aarch64*)
27     pic_options='-fPIC'
28     ;;
29 ?86-pc-cygwin*|i?86-pc-cygwin*|i?86-pc-mingw32*)
30     pic_options='-DDLL_EXPORT'
31     ;;
32 i?86-apple-darwin*|arm-apple-darwin*)
33     pic_options='-fno-common'
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) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
42     LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
43 else
44     AC_MSG_RESULT([yes, replacing libtool])
45
46 dnl Start writing out doltcompile.
47     cat <<__DOLTCOMPILE__EOF__ >doltcompile
48 #!$DOLT_BASH
49 __DOLTCOMPILE__EOF__
50     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
51 args=("$[]@")
52 for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
53     if test x"${args@<:@$arg@:>@}" = x-o ; then
54         objarg=$((arg+1))
55         break
56     fi
57 done
58 if test x$objarg = x ; then
59     echo 'Error: no -o on compiler command line' 1>&2
60     exit 1
61 fi
62 lo="${args@<:@$objarg@:>@}"
63 obj="${lo%.lo}"
64 if test x"$lo" = x"$obj" ; then
65     echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
66     exit 1
67 fi
68 objbase="${obj##*/}"
69 __DOLTCOMPILE__EOF__
70
71 dnl Write out shared compilation code.
72     if test x$enable_shared = xyes; then
73         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
74 libobjdir="${obj%$objbase}.libs"
75 if 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
82 fi
83 pic_object="$libobjdir/$objbase.o"
84 args@<:@$objarg@:>@="$pic_object"
85 __DOLTCOMPILE__EOF__
86     cat <<__DOLTCOMPILE__EOF__ >>doltcompile
87 "\${args@<:@@@:>@}" $pic_options -DPIC || exit \$?
88 __DOLTCOMPILE__EOF__
89     fi
90
91 dnl Write out static compilation code.
92 dnl Avoid duplicate compiler output if also building shared objects.
93     if test x$enable_static = xyes; then
94         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
95 non_pic_object="$obj.o"
96 args@<:@$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
109 dnl Write out the code to write the .lo file.
110 dnl The second line of the .lo file must match "^# Generated by .*libtool"
111     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
112 {
113 echo "# $lo - a libtool object file"
114 echo "# Generated by doltcompile, not libtool"
115 __DOLTCOMPILE__EOF__
116
117     if test x$enable_shared = xyes; then
118         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
119 echo "pic_object='.libs/${objbase}.o'"
120 __DOLTCOMPILE__EOF__
121     else
122         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
123 echo pic_object=none
124 __DOLTCOMPILE__EOF__
125     fi
126
127     if test x$enable_static = xyes; then
128         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
129 echo "non_pic_object='${objbase}.o'"
130 __DOLTCOMPILE__EOF__
131     else
132         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
133 echo non_pic_object=none
134 __DOLTCOMPILE__EOF__
135     fi
136
137     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
138 } > "$lo"
139 __DOLTCOMPILE__EOF__
140
141 dnl 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
146 dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
147 dnl a target, so write out a libtool wrapper to handle that case.
148 dnl Note that doltlibtool does not handle inferred tags or option arguments
149 dnl without '=', because automake does not use them.
150     cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
151 #!$DOLT_BASH
152 __DOLTLIBTOOL__EOF__
153     cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
154 top_builddir_slash="${0%%doltlibtool}"
155 : ${top_builddir_slash:=./}
156 args=()
157 modeok=false
158 tagok=false
159 for arg in "$[]@"; do
160     case "$arg" in
161         --silent) ;;
162         --mode=compile) modeok=true ;;
163         --tag=CC|--tag=CXX) tagok=true ;;
164         --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 ])