summaryrefslogtreecommitdiff
path: root/acsite.m4
blob: 8de5c5526a53d763cc3834fa2939c4c03ddd4fae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
dnl ============================================================
dnl Force configure to run under /bin/bash
dnl ============================================================
m4_define([AC_MCPU_REQUIRE_BASH], [dnl
m4_divert_push([M4SH-SANITIZE])dnl

if test ! -x /bin/bash; then
  echo "configure: error: /bin/bash is required" >&2
  exit 1
fi

CONFIG_SHELL=/bin/bash
export CONFIG_SHELL

m4_divert_pop([M4SH-SANITIZE])dnl
])dnl


dnl ============================================================
dnl Support for Configuration Headers
dnl
dnl    configure.ac:
dnl       AC_MCPU_HEADLINE(<short-name>, <long-name>,
dnl                        <vers-var>, <copyright>)
dnl ============================================================
m4_define([AC_MCPU_HEADLINE], [dnl
m4_divert_push([M4SH-INIT])dnl
{
  if test ".`echo dummy [$]@ | grep help`" = .; then

    ####### Use a `Quadrigaph'. '@<:@' gives you [ and '@:>@' gives you ] :
    TB=`echo -n -e '\033@<:@1m'`
    TN=`echo -n -e '\033@<:@0m'`

    ####### Get the short product version from AC_INIT().
    $3="AC_PACKAGE_VERSION"
    AC_SUBST($3)

    ####### Print configuration headline.
    echo "Configuring:"
    echo ""
    echo "${TB}$1${TN} ($2), Version ${TB}${$3}${TN}"
    echo "$4"
    echo ""
  fi
}
m4_divert_pop([M4SH-INIT])dnl
])dnl


dnl ============================================================
dnl Display Configuration Headers
dnl
dnl    configure.ac:
dnl       AC_MSG_CFG_PART(<text>)
dnl ============================================================
AC_DEFUN([AC_MSG_CFG_PART],[dnl
   AC_MSG_RESULT()
   AC_MSG_RESULT([${TB}$1:${TN}])
])dnl


dnl ============================================================
dnl GNU GCC is required by LibMCPU.
dnl ============================================================
AC_DEFUN([MCPU_REQUIRE_GCC], [dnl
  AC_MSG_CHECKING([whether $CC is GNU GCC])
  AC_COMPILE_IFELSE([
    AC_LANG_SOURCE([[
#if !defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
#error LibMCPU requires GNU GCC
#endif
int main( void ) { return 0; }
    ]])
  ], [
    AC_MSG_RESULT([yes])
  ], [
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([LibMCPU requires GNU GCC])
  ])
])


dnl ============================================================
dnl Provide the Autoconf state required by cpu/sysdeps/*/
dnl preconfigure.ac fragments.  The generated preconfigure files
dnl are sourced by the top-level configure after AC_PROG_CC.
dnl ============================================================
define([MCPU_PROVIDES], [dnl
AC_PROVIDE([AC_CONFIG_AUX_DIR_DEFAULT])dnl
AC_PROVIDE([AC_CONFIG_SUBDIRS])dnl
AC_PROVIDE([_AS_ECHO_N_PREPARE])dnl
AC_PROVIDE([_AS_ECHO_PREPARE])dnl
AC_PROVIDE([_AS_CR_PREPARE])dnl
AC_PROVIDE([_AS_TR_SH_PREPARE])dnl
AC_PROVIDE([_AS_VAR_ARITH_PREPARE])dnl
AC_PROVIDE([AC_PROG_INSTALL])dnl
AC_PROVIDE([AC_PROG_CC])dnl
AC_PROVIDE([AC_PROG_CPP])dnl
AC_PROVIDE([_AS_PATH_SEPARATOR_PREPARE])dnl
AC_PROVIDE([_AS_TEST_PREPARE])dnl
AC_PROVIDE([_AS_BASENAME_PREPARE])dnl
AC_PROVIDE([_AS_ME_PREPARE])dnl
AC_PROVIDE([_AS_LINENO_PREPARE])dnl
AC_PROVIDE([AS_SHELL_FN_as_fn_set_status])dnl
AC_PROVIDE([AS_SHELL_FN_as_fn_exit])dnl
AC_PROVIDE([AS_SHELL_FN_as_fn_arith])dnl
AC_PROVIDE([AS_SHELL_FN_ac_fn_c_try_compile])dnl
define([AS_MESSAGE_LOG_FD],5)dnl
define([AS_MESSAGE_FD],6)dnl
m4_wrap([m4_divert_pop([BODY])[]])
m4_divert_push([BODY])[]dnl
# This file is generated from preconfigure.ac by Autoconf.  DO NOT EDIT!
define([_AC_LANG], [C])dnl
])dnl


dnl ============================================================
dnl Find and source cpu/sysdeps/*/preconfigure fragments.
dnl
dnl   MCPU_PRECONFIGURE([$srcdir], [for cpu/sysdeps])
dnl ============================================================
AC_DEFUN([MCPU_PRECONFIGURE], [dnl
if frags=`ls -d $1/cpu/sysdeps/*/preconfigure 2> /dev/null`
then
  AC_MSG_CHECKING([$2 preconfigure fragments])
  mcpu_frag_names=
  for frag in $frags; do
    name=`echo "$frag" | sed 's@/[[^/]]*[$]@@;s@^.*/@@'`
    mcpu_frag_names="$mcpu_frag_names $name"
  done
  AC_MSG_RESULT([$mcpu_frag_names])
  for frag in $frags; do
    . "$frag"
  done
fi
])


dnl ============================================================
dnl Build the ordered cpu/sysdeps search path for the configured
dnl HOST.  The algorithm follows the historical LibMPU sysdeps
dnl model: architecture preconfigure fragments may refine MACHINE
dnl (including the ABI/data model), existing OS/CPU directories are
dnl discovered from the most specific to the most generic, and
dnl Implies/Implies-before/Implies-after expand the inheritance
dnl chain before cpu/sysdeps/generic is appended.
dnl
dnl Substitutions:
dnl   base_machine          canonical base host architecture
dnl   submachine           optional --with-cpu suffix
dnl   MCPU_HOST_MACHINE    refined machine[/data-model]
dnl   MCPU_HOST_DATA_MODEL ILP32/LP64/... selected by preconfigure
dnl   sysnames             ordered source lookup directories
dnl ============================================================
AC_DEFUN([MCPU_SYSDEP_DIR_NAMES], [dnl
case "$host_os" in
  linux*) ;;
  gnu*) host_os=`echo "$host_os" | sed -e 's/gnu/gnu-gnu/'` ;;
esac

config_machine=$host_cpu
config_vendor=$host_vendor
config_os=$host_os

test "$config_vendor" = unknown && config_vendor=
config_os="`echo "$config_os" | sed 's/^unknown-//'`"

machine=$config_machine
vendor=$config_vendor
os=$config_os
base_os=''
base_machine=
MCPU_HOST_DATA_MODEL=

submachine=
AC_ARG_WITH([cpu],
  AS_HELP_STRING([--with-cpu=CPU], [select host CPU variant for sysdeps]),
  [dnl
    case "$withval" in
      yes | '') AC_MSG_ERROR([--with-cpu requires an argument]) ;;
      no) ;;
      *) submachine="$withval" ;;
    esac
  ])

AC_ARG_ENABLE([debug-configure],
  AS_HELP_STRING([--enable-debug-configure],
                 [show detailed cpu/sysdeps directory selection @<:@default=no@:>@]),
  [enable_debug_configure=$enableval],
  [enable_debug_configure=no])
case "$enable_debug_configure" in
  no) enable_debug_configure='' ;;
  *) ;;
esac

MCPU_PRECONFIGURE([$srcdir], [for cpu/sysdeps])

test -n "$base_machine" || base_machine=$machine
AC_SUBST([base_machine])
AC_SUBST([submachine])

sysdep_dir=$srcdir/cpu/sysdeps
AC_MSG_CHECKING([cpu sysdep dirs])
os="`echo "$os" | sed 's/\([[0-9A-Z]]\)[[v_]]\([[0-9A-Z]]\)/\1.\2/g'`"

test "x$base_os" != x || case "$os" in
  linux*) base_os=unix/sysv ;;
esac

# OS candidates: linux-gnu, linux, etc.
tail=$os
ostry=$os
while o=`echo "$tail" | sed 's/\.[[^.]]*$//'`; test "$o" != "$tail"; do
  ostry="$ostry /$o"
  tail=$o
done
o=`echo "$tail" | sed 's/[[0-9]]*$//'`
if test "$o" != "$tail"; then
  ostry="$ostry /$o"
fi
o=`echo "$tail" | sed 's/-.*$//'`
if test "$o" != "$tail"; then
  ostry="$ostry /$o"
fi

# Base OS hierarchy: unix/sysv -> unix/sysv, unix.
base=
tail=$base_os
while b=`echo "$tail" | sed 's@^\(.*\)/\([[^/]]*\)[$]@& \1@'`; test -n "$b"; do
  set $b
  base="$base /[$]1"
  tail="[$]2"
done

# Machine hierarchy: x86_64/64 -> x86_64/64, x86_64.
mach=
tail=$machine${submachine:+/$submachine}
while m=`echo "$tail" | sed 's@^\(.*\)/\([[^/]]*\)[$]@& \1@'`; test -n "$m"; do
  set $m
  mach="$mach /[$]1"
  tail="[$]2"
done

sysnames=
os_used=
machine_used=
submachine_used=
for b in $base ''; do
  for m0 in $mach ''; do
    for v in /$vendor ''; do
      test "$v" = / && continue
      for o in /$ostry ''; do
        test "$o" = / && continue
        for m in $mach ''; do
          try_suffix="$m0$b$v$o$m"
          if test -n "$try_suffix"; then
            try="cpu/sysdeps$try_suffix"
            test -n "$enable_debug_configure" && echo "configure: sysdeps try: $try" >&2
            if test -d "$srcdir/$try"; then
              case " $sysnames " in
                *" $try "*) ;;
                *) sysnames="$sysnames $try" ;;
              esac
              { test -n "$o" || test -n "$b"; } && os_used=t
              { test -n "$m" || test -n "$m0"; } && machine_used=t
              case x${m0:-$m} in
                x*/$submachine) test -n "$submachine" && submachine_used=t ;;
              esac
            fi
          fi
        done
      done
    done
  done
done

# The sysdeps layer is deliberately narrower than the generic C build.
# If LibMPU itself was not usable AC_CHECK_LIBMPU has already stopped
# configure.  Here we additionally require a known LibMCPU host OS/CPU
# hierarchy; generic alone never constitutes a supported HOST.
if test -z "$os_used" && test "$os" != none; then
  AC_MSG_ERROR([Not supported HOST $host: no cpu/sysdeps operating-system hierarchy for $os])
fi
if test -z "$machine_used" && test "$machine" != none; then
  AC_MSG_ERROR([Not supported HOST $host: no cpu/sysdeps machine hierarchy for $machine])
fi
if test -n "$submachine" && test -z "$submachine_used"; then
  AC_MSG_ERROR([Not supported HOST $host: CPU variant $submachine is not represented in cpu/sysdeps])
fi

# Expand existing names through parent directories and Implies files.
set $sysnames
names=
while test [$]# -gt 0; do
  name=[$]1
  shift

  case " $names " in
    *" $name "*) continue ;;
  esac

  name_base=`echo "$name" | sed -e 's@\(.*cpu/sysdeps\)/.*@\1@'`

  Implies=
  Implies_before=
  Implies_after=
  for implies_file in Implies Implies-before Implies-after; do
    implies_type=`echo "$implies_file" | sed 's/-/_/'`
    eval ${implies_type}=
    if test -f "$srcdir/$name/$implies_file"; then
      implied_candidate="`sed 's/#.*$//' < "$srcdir/$name/$implies_file"`"
      for x in $implied_candidate; do
        found=no
        try="$name_base/$x"
        test -n "$enable_debug_configure" && echo "configure: $name/$implies_file -> $try" >&2
        if test -d "$srcdir/$try"; then
          eval "${implies_type}=\"\$${implies_type} \$try\""
          found=yes
        fi
        if test "$found" = no; then
          AC_MSG_WARN([$name/$implies_file specifies nonexistent $x])
        fi
      done
    fi
  done

  names="$names $name"

changequote(,)dnl
  parent="`echo "$name" | sed -n -e 's=/[^/]*$==' -e '/cpu\/sysdeps$/q' -e p`"
changequote([,])dnl

  test -n "$enable_debug_configure" &&
    echo "configure: sysdeps select: $name; implies='$Implies'; parent='$parent'; before='$Implies_before'; after='$Implies_after'" >&2

  sysnames="`echo $Implies [$]* $Implies_before $parent $Implies_after`"
  test -n "$sysnames" && set $sysnames
done

default_sysnames="cpu/sysdeps/generic"
sysnames="`echo $names $default_sysnames`"
MCPU_HOST_MACHINE=$machine

AC_SUBST([MCPU_HOST_MACHINE])
AC_SUBST([MCPU_HOST_DATA_MODEL])
AC_SUBST([sysnames])

AC_MSG_RESULT([$sysnames])
])

AC_DEFUN([AC_LIBMCPU_LT_VERSION_INFO],
[AC_MSG_CHECKING(for MCPU Library Version Information)
#
# Made LT_VERSION_INFO (may be used libtool-next-version from libtool-2.6.2):
#
# LT_VERSION_INFO="current:revision:age"
#
info="$1"

current=`echo ${info} | cut -f1 -d':'`
revision=`echo ${info} | cut -f2 -d':'`
age=`echo ${info} | cut -f3 -d':'`

ac_cv_libmcpu_lt_release="${current}.${revision}"
ac_cv_libmcpu_lt_current="${current}"
ac_cv_libmcpu_lt_revision="${revision}"
ac_cv_libmcpu_lt_age="${age}"

ac_cv_libmcpu_lt_version_info="${current}:${revision}:${age}"

AC_SUBST(LIBMCPU_LT_RELEASE, $ac_cv_libmcpu_lt_release)
AC_SUBST(LIBMCPU_LT_VERSION_INFO, $ac_cv_libmcpu_lt_version_info)
AC_SUBST(LIBMCPU_LT_CURRENT, $ac_cv_libmcpu_lt_current)
AC_SUBST(LIBMCPU_LT_REVISION, $ac_cv_libmcpu_lt_revision)
AC_SUBST(LIBMCPU_LT_AGE, $ac_cv_libmcpu_lt_age)

AC_MSG_RESULT($ac_cv_libmcpu_lt_version_info)
if test "$ac_cv_libmcpu_lt_version_info" = ""; then
AC_MSG_ERROR([
********   ${TB}The MCPU Library Version Information does not declared.${TN}])
fi
])


dnl ============================================================
dnl  Test if LD_LIBRARY_PATH contains the notation for the
dnl  current directory since this would lead to problems
dnl  installing/building kxlibc .
dnl
dnl  LD_LIBRARY_PATH contains the current directory if one
dnl  of the following is true:
dnl     - one of the terminals (":" and ";") is the first or
dnl       last sign;
dnl     - two terminals occur directly after each other;
dnl     - the path contains an element with a dot in it .
dnl ============================================================
AC_DEFUN([AC_LD_LIBRARY_PATH],
[AC_MSG_CHECKING(for LD_LIBRARY_PATH does not contain current directory)
changequote(,)dnl
case ${LD_LIBRARY_PATH} in
   [:\;]* | *[:\;] | *[:\;][:\;]* |  *[:\;]. | .[:\;]*| . | *[:\;].[:\;]* )
      ld_library_path_setting="contains current directory"
      ;;
   *)
      ld_library_path_setting="ok"
      ;;
esac
changequote([,])dnl
AC_MSG_RESULT($ld_library_path_setting)
if test "$ld_library_path_setting" != "ok"; then
AC_MSG_ERROR([
********   ${TB}LD_LIBRARY_PATH shouldn't contain the current directory when${TN}
********   ${TB}building MCPU Library. Please change the environment variable${TN}
********   ${TB}and run configure again.${TN}])
fi
])