]> Pileus Git - grits/blob - m4/dolt.m4
Add cube GtkGL example
[grits] / 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 i?86-apple-darwin*)
30     pic_options='-fno-common'
31     ;;
32 *)
33     dolt_supported=no
34     ;;
35 esac
36 if test x$dolt_supported = xno ; then
37     AC_MSG_RESULT([no, falling back to libtool])
38     LTCOMPILE='$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(COMPILE)'
39     LTCXXCOMPILE='$(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXXCOMPILE)'
40 else
41     AC_MSG_RESULT([yes, replacing libtool])
42
43 dnl Start writing out doltcompile.
44     cat <<__DOLTCOMPILE__EOF__ >doltcompile
45 #!$DOLT_BASH
46 __DOLTCOMPILE__EOF__
47     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
48 args=("$[]@")
49 for ((arg=0; arg<${#args@<:@@@:>@}; arg++)) ; do
50     if test x"${args@<:@$arg@:>@}" = x-o ; then
51         objarg=$((arg+1))
52         break
53     fi
54 done
55 if test x$objarg = x ; then
56     echo 'Error: no -o on compiler command line' 1>&2
57     exit 1
58 fi
59 lo="${args@<:@$objarg@:>@}"
60 obj="${lo%.lo}"
61 if test x"$lo" = x"$obj" ; then
62     echo "Error: libtool object file name \"$lo\" does not end in .lo" 1>&2
63     exit 1
64 fi
65 objbase="${obj##*/}"
66 __DOLTCOMPILE__EOF__
67
68 dnl Write out shared compilation code.
69     if test x$enable_shared = xyes; then
70         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
71 libobjdir="${obj%$objbase}.libs"
72 if test ! -d "$libobjdir" ; then
73     mkdir_out="$(mkdir "$libobjdir" 2>&1)"
74     mkdir_ret=$?
75     if test "$mkdir_ret" -ne 0 && test ! -d "$libobjdir" ; then
76         echo "$mkdir_out" 1>&2
77         exit $mkdir_ret
78     fi
79 fi
80 pic_object="$libobjdir/$objbase.o"
81 args@<:@$objarg@:>@="$pic_object"
82 __DOLTCOMPILE__EOF__
83     cat <<__DOLTCOMPILE__EOF__ >>doltcompile
84 "\${args@<:@@@:>@}" $pic_options -DPIC || exit \$?
85 __DOLTCOMPILE__EOF__
86     fi
87
88 dnl Write out static compilation code.
89 dnl Avoid duplicate compiler output if also building shared objects.
90     if test x$enable_static = xyes; then
91         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
92 non_pic_object="$obj.o"
93 args@<:@$objarg@:>@="$non_pic_object"
94 __DOLTCOMPILE__EOF__
95         if test x$enable_shared = xyes; then
96             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
97 "${args@<:@@@:>@}" >/dev/null 2>&1 || exit $?
98 __DOLTCOMPILE__EOF__
99         else
100             cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
101 "${args@<:@@@:>@}" || exit $?
102 __DOLTCOMPILE__EOF__
103         fi
104     fi
105
106 dnl Write out the code to write the .lo file.
107 dnl The second line of the .lo file must match "^# Generated by .*libtool"
108     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
109 {
110 echo "# $lo - a libtool object file"
111 echo "# Generated by doltcompile, not libtool"
112 __DOLTCOMPILE__EOF__
113
114     if test x$enable_shared = xyes; then
115         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
116 echo "pic_object='.libs/${objbase}.o'"
117 __DOLTCOMPILE__EOF__
118     else
119         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
120 echo pic_object=none
121 __DOLTCOMPILE__EOF__
122     fi
123
124     if test x$enable_static = xyes; then
125         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
126 echo "non_pic_object='${objbase}.o'"
127 __DOLTCOMPILE__EOF__
128     else
129         cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
130 echo non_pic_object=none
131 __DOLTCOMPILE__EOF__
132     fi
133
134     cat <<'__DOLTCOMPILE__EOF__' >>doltcompile
135 } > "$lo"
136 __DOLTCOMPILE__EOF__
137
138 dnl Done writing out doltcompile; substitute it for libtool compilation.
139     chmod +x doltcompile
140     LTCOMPILE='$(top_builddir)/doltcompile $(COMPILE)'
141     LTCXXCOMPILE='$(top_builddir)/doltcompile $(CXXCOMPILE)'
142
143 dnl automake ignores LTCOMPILE and LTCXXCOMPILE when it has separate CFLAGS for
144 dnl a target, so write out a libtool wrapper to handle that case.
145 dnl Note that doltlibtool does not handle inferred tags or option arguments
146 dnl without '=', because automake does not use them.
147     cat <<__DOLTLIBTOOL__EOF__ > doltlibtool
148 #!$DOLT_BASH
149 __DOLTLIBTOOL__EOF__
150     cat <<'__DOLTLIBTOOL__EOF__' >>doltlibtool
151 top_builddir_slash="${0%%doltlibtool}"
152 : ${top_builddir_slash:=./}
153 args=()
154 modeok=false
155 tagok=false
156 for arg in "$[]@"; do
157     case "$arg" in
158         --mode=compile) modeok=true ;;
159         --tag=CC|--tag=CXX) tagok=true ;;
160         *) args@<:@${#args[@]}@:>@="$arg" ;;
161     esac
162 done
163 if $modeok && $tagok ; then
164     . ${top_builddir_slash}doltcompile "${args@<:@@@:>@}"
165 else
166     exec ${top_builddir_slash}libtool "$[]@"
167 fi
168 __DOLTLIBTOOL__EOF__
169
170 dnl Done writing out doltlibtool; substitute it for libtool.
171     chmod +x doltlibtool
172     LIBTOOL='$(top_builddir)/doltlibtool'
173 fi
174 AC_SUBST(LTCOMPILE)
175 AC_SUBST(LTCXXCOMPILE)
176 # end dolt
177 ])