Make sure that the args array is initialized
[sxemacs] / m4 / sxe-bldenv.m4
1 dnl sxe-bldenv.m4 -- Things for/on the build environment
2
3 AC_DEFUN([SXE_LD_EXPORT_DYNAMIC], [dnl
4         AC_MSG_CHECKING([if linker understands -export-dynamic])
5         SXE_DUMP_LIBS
6         LDFLAGS="-export-dynamic $LDFLAGS"
7         AC_LINK_IFELSE([AC_LANG_PROGRAM([[
8 #include <stdlib.h>
9 ]],[[
10 return 0;
11 ]])],  [AC_MSG_RESULT([yes])
12         have_ld_export_dynamic="yes"], [
13         AC_MSG_RESULT([no])
14         have_ld_export_dynamic="no"])
15         SXE_RESTORE_LIBS
16 ])dnl SXE_LD_EXPORT_DYNAMIC
17
18 dnl SXE_RILLY_COMPUTE_LD_RUN_PATH()
19 AC_DEFUN([SXE_RILLY_COMPUTE_LD_RUN_PATH], [dnl
20         if test "$add_runtime_path" = "yes" -a -n "$dash_r"; then
21                 ## Remove runtime paths from current ld switches
22                 ld_switch_site=`echo   '' $ld_switch_site   | sed -e 's:^ ::' -e "s/$dash_r[[^ ]]*//g"`
23                 ld_switch_x_site=`echo '' $ld_switch_x_site | sed -e 's:^ ::' -e "s/$dash_r[[^ ]]*//g"`
24
25                 ## Fix up Runtime path
26                 ## If LD_RUN_PATH is set in environment, use that.
27                 ## In this case, assume user has set the right value.
28                 runpath=""
29                 runpath_dirs=""
30                 if test -n "$LD_RUN_PATH"; then
31                         runpath="$LD_RUN_PATH"
32                 elif test "$GCC" = "yes"; then
33                         ## Compute runpath from gcc's -v output
34                         ld_switch_run_save="$ld_switch_run"
35                         ld_switch_run=""
36                         echo "int main(int argc, char *argv[[]]) {return 0;}" \
37                                 > conftest.c
38                         xe_runpath_link='${CC-cc} -o conftest -v $CFLAGS '"$xe_ldflags"' conftest.$ac_ext 2>&1 1>/dev/null'
39                         for arg in `eval "$xe_runpath_link" | grep ' -L'`; do
40                                 case "$arg" in
41                                 P,* | -L* | -R* )
42                                         for dir in `echo '' "$arg" | sed -e 's:^ ::' -e 's/^..//' -e 'y/:/ /'`; do
43                                                 SXE_ADD_RUNPATH_DIR(["$dir"])
44                                         done
45                                         ;;
46                                 esac
47                         done
48                         ld_switch_run="$ld_switch_run_save"
49                         rm -f conftest*
50                 else
51                         ## Add all directories with .so files to runpath
52                         for arg in $ld_switch_site $ld_switch_x_site; do
53                                 case "$arg" in
54                                 -L*)
55                                         SXE_ADD_RUNPATH_DIR(`echo '' "$arg" | sed -e 's:^ ::' -e 's/^-L//'`)
56                                         ;;
57                                 esac
58                         done
59                         ## Sometimes /opt/SUNWdt/lib is the only
60                         ## installed Motif available
61                         if test "$opsys $need_motif" = "sol2 yes"; then
62                                 xe_runpath_dir="/opt/SUNWdt/lib";
63                                 eval "$xe_add_unique_runpath_dir";
64                         fi
65                 fi dnl Compute $runpath
66
67                 if test -n "$runpath"; then
68                         ld_switch_run="${dash_r}${runpath}"
69                         SXE_PROTECT_LINKER_FLAGS(ld_switch_run)
70                         if test "$extra_verbose" = "yes"; then
71                                 echo "Setting runpath to $runpath"
72                         fi
73                 fi
74         fi
75 ])dnl SXE_RILLY_COMPUTE_LD_RUN_PATH
76
77 AC_DEFUN([SXE_COMPUTE_LD_RUN_PATH], [dnl
78         ## --with-site-runtime-libraries (multiple dirs)
79         SXE_COLON_TO_SPACE(with_site_runtime_libraries)
80         if test -n "$with_site_runtime_libraries"; then
81                 LD_RUN_PATH="`echo $with_site_runtime_libraries | sed -e 's/  */:/g'`"
82                 export LD_RUN_PATH
83                 for path in $with_site_runtime_libraries; do
84                         dnl SXE_APPEND("-R$path ", $ld_switch_run)
85                         SXE_APPEND(["-R${path} "], [LDFLAGS])
86                 done
87         fi
88
89         ## -------------------------------------
90         ## Compute runtime library path
91         ## -------------------------------------
92
93         ## Linux systems have dynamic runtime library directories listed in
94         ## /etc/ld.so.conf.  Since those are used at run time, it seems pretty
95         ## safe to use them at link time, and less controversial than forcing
96         ## the run-time to use the link-time libraries.  This also helps avoid
97         ## mismatches between the link-time and run-time libraries.
98
99         ## #### Unfortunately, there are horrible libc4 and libc5 libraries
100         ## listed in /etc/ld.so.conf on some systems, and including them on
101         ## the link path leads to linking in utterly broken libc's.
102         ## There are many clever ways of approaching this problem,
103         ## but finding one that actually works...
104
105         ## if test -z "$LD_RUN_PATH" -a -r "/etc/ld.so.conf"; then
106         ##   for dir in `cat /etc/ld.so.conf`; do
107         ##     test -d "$dir" && SXE_APPEND(-L${dir}, ld_switch_system)
108         ##   done
109         ##   add_runtime_path=no
110         ## fi
111
112         if test -n "$add_runtime_path"; then
113                 :
114         elif test "$with_dynamic" = "no"; then
115                 add_runtime_path=no
116         elif test -n "$LD_RUN_PATH"; then
117                 add_runtime_path=yes
118         else
119                 case "$opsys" in
120                 sol2 | irix* | *bsd* | decosf* )
121                         add_runtime_path=yes
122                         ;;
123                 * )
124                         add_runtime_path=no
125                         ;;
126                 esac
127         fi
128
129         if test "$add_runtime_path" = "yes"; then
130                 ## Try to autodetect runtime library flag (usually -R),
131                 ## and whether it works (or at least does no harm)
132                 AC_MSG_CHECKING([for runtime libraries flag])
133                 case "$opsys" in
134                 sol2 )
135                         dash_r="-R"
136                         ;;
137                 decosf* | linux* | irix*)
138                         dash_r="-rpath "
139                         ;;
140                 *)
141                         dash_r=""
142                         for try_dash_r in "-R" "-R " "-rpath "; do
143                                 xe_check_libs="${try_dash_r}/no/such/file-or-directory"
144                                 SXE_PROTECT_LINKER_FLAGS(xe_check_libs)
145                                 AC_LINK_IFELSE([AC_LANG_SOURCE([[]])],
146                                         [dash_r="$try_dash_r"])
147                                 xe_check_libs=""
148                                 test -n "$dash_r" && break
149                         done
150                         ;;
151                 esac
152                 if test -n "$dash_r"; then
153                         AC_MSG_RESULT("${dash_r}")
154                 else
155                         AC_MSG_RESULT([NONE])
156                 fi
157         fi
158
159         xe_add_unique_runpath_dir='
160         xe_add_p=yes
161         for xe_dir in $runpath_dirs; do   dnl Uniquify
162                 test "$xe_dir" = "$xe_runpath_dir" && xe_add_p=no
163         done
164         if test "$xe_add_p" = "yes"; then
165                 test -n "$runpath" && runpath="${runpath}:"
166                 runpath="${runpath}${xe_runpath_dir}"
167                 runpath_dirs="$runpath_dirs $xe_runpath_dir"
168         fi'
169
170         ## t3h real computation
171         SXE_RILLY_COMPUTE_LD_RUN_PATH
172 ])dnl SXE_COMPUTE_LD_RUN_PATH
173
174
175 AC_DEFUN([SXE_COMPUTE_SITE_PREFIXES], [dnl
176         ## ---------------------------------------------------------------
177         ## Add site and system specific flags to compile and link commands
178         ## ---------------------------------------------------------------
179
180         dnl --with-site-libraries (multiple dirs)
181         SXE_COLON_TO_SPACE(with_site_libraries)
182         if test -n "$with_site_libraries"; then
183                 for arg in $with_site_libraries; do
184                         case "$arg" in
185                         -* )
186                                 ;;
187                         * )
188                                 test -d "$arg" || \
189                                 SXE_DIE("Invalid site library \`$arg': no such directory")
190                                 arg="-L${arg}"
191                                 ;;
192                         esac
193                         SXE_APPEND($arg, ld_switch_site)
194                 done
195         fi
196
197         dnl --with-site-includes (multiple dirs)
198         SXE_COLON_TO_SPACE(with_site_includes)
199         if test -n "$with_site_includes"; then
200                 for arg in $with_site_includes; do
201                         case "$arg" in
202                         -* )
203                                 ;;
204                         * )
205                                 test -d "$arg" || \
206                                 SXE_DIE("Invalid site include \`$arg': no such directory")
207                                 arg="-I${arg}"
208                                 ;;
209                         esac
210                         SXE_APPEND($arg, c_switch_site)
211                         SXE_APPEND($arg, CPPFLAGS)
212                 done
213         fi
214
215         dnl --with-site-prefixes (multiple dirs)
216         dnl --with-site-prefixes=dir1:dir2 is a convenient shorthand for
217         dnl --with-site-libraries=dir1/lib:dir2/lib
218         dnl --with-site-includes=dir1/include:dir2/include
219         ## Site prefixes take precedence over the standard places, but not over
220         ## with-site-includes and with-site-libraries.
221         SXE_COLON_TO_SPACE(with_site_prefixes)
222         if test -n "$with_site_prefixes"; then
223                 for dir in $with_site_prefixes; do
224                         lib_dir="${dir}/lib"
225                         inc_dir="${dir}/include"
226                         if test ! -d "$dir"; then
227                                 SXE_DIE("Invalid site prefix \`$dir': no such directory")
228                         elif test ! -d "$lib_dir"; then
229                                 SXE_DIE("Invalid site prefix \`$dir': no such directory \`$lib_dir'")
230                         else
231                                 if test -d "$inc_dir"; then
232                                         SXE_APPEND(["-I$inc_dir"], [CPPFLAGS])
233                                 fi
234                                 SXE_APPEND(["-L$lib_dir"], [LDFLAGS])
235                         fi
236                 done
237         fi
238
239         dnl GNU software installs by default into /usr/local/{include,lib}
240         if test -d "/usr/local/include" -a -d "/usr/local/lib"; then
241                 SXE_APPEND(["-L/usr/local/lib"], [LDFLAGS])
242                 SXE_APPEND(["-I/usr/local/include"], [CPPFLAGS])
243         fi
244
245         dnl Extra system-specific library directories - please add to list
246         for dir in "/usr/ccs/lib"; do
247                 dnl test -d "$dir" && SXE_APPEND(-L${dir}, ld_switch_system)
248                 if test -d "$dir"; then
249                         SXE_APPEND([-L${dir}], [LDFLAGS])
250                 fi
251         done
252 ])dnl SXE_COMPUTE_SITE_PREFIXES
253
254
255 AC_DEFUN([SXE_EXPLORE_BUILD_ENVIRONMENT], [dnl
256 dnl AC_ARG_PROGRAM
257         AC_CANONICAL_BUILD
258         AC_CANONICAL_HOST
259
260         dnl Local paths
261         test "x$prefix" = xNONE && prefix=$ac_default_prefix
262         # Let make expand exec_prefix.
263         if test "x$exec_prefix" = xNONE; then
264                 exec_prefix='${prefix}'
265         else
266                 AC_DEFINE([EXEC_PREFIX_USER_DEFINED], [1],
267                         [exec-prefix has been specified on the configure line.])
268         fi
269         ##datarootdir='${prefix}/share'
270         if test "x$datadir" != 'x${prefix}/share' && \
271            test "x$datadir" != 'x${datarootdir}'; then
272                 AC_DEFINE([INFODIR_USER_DEFINED], [1], [Description here!])
273                 AC_DEFINE([LISPDIR_USER_DEFINED], [1], [Description here!])
274                 AC_DEFINE([ETCDIR_USER_DEFINED], [1], [Description here!])
275                 AC_DEFINE([DOCDIR_USER_DEFINED], [1], [Description here!])
276         ##else
277         ##      datadir='${prefix}/share'
278         fi
279         
280         if test "x$libdir" != 'x${exec_prefix}/lib'; then
281                 AC_DEFINE([ARCHLIBDIR_USER_DEFINED], [1], [Description here!])
282                 AC_DEFINE([MODULEDIR_USER_DEFINED], [1], [Description here!])
283                 AC_DEFINE([SITEMODULEDIR_USER_DEFINED], [1], [Description here!])
284         fi
285         ##if test "x$mandir" = 'x${prefix}/man' || \
286         ##   test "x$mandir" = 'x${datarootdir}/man'; then
287         ##      mandir='${prefix}/man/man1'
288         ##fi
289         if test "x$infodir" != 'x${prefix}/info' -a \
290                 "x$infodir" != 'x${datarootdir}/info'; then
291                 AC_DEFINE([INFODIR_USER_DEFINED], [1], [Description here!])
292         elif test "x$infodir" = 'x${prefix}/info'; then
293                 ## use new convention
294                 infodir='${prefix}/share/info'
295         fi
296
297         inststaticdir='${PROGNAME}'
298         instvardir='${PROGNAME}-${old_version}'
299         instvarsepdir='${PROGNAME}/${old_version}'
300         sitemoduledir='${libdir}/${inststaticdir}/${configuration}/site-modules'
301
302         dnl until someone explains what this is for!!!
303         dnl AC_SUBST([statedir], [$with_statedir])
304
305         ## Calculate canonical name for sxe_blddir (i.e. current directory)
306         SXE_COMPUTE_BLDDIR
307         ## ... and sxe_srcdir
308         SXE_COMPUTE_SRCDIR
309         ## general health checking
310         SXE_CHECK_SRCDIR_HEALTH
311
312         ## derive emodblddir from this
313         emodblddir=$sxe_blddir/modules
314         ## derivate emodsrcdir from srcdir
315         emodsrcdir=$sxe_srcdir/modules
316 ])dnl SXE_EXPLORE_BUILD_ENVIRONMENT
317
318 dnl sxe-bldenv.m4 ends here