acinclude/ax_gcc_archflag.m4
author Ryan C. Gordon <icculus@icculus.org>
Mon, 29 Oct 2018 20:00:03 -0400
changeset 12369 68c87b40b434
parent 5029 5d7d48157be7
permissions -rw-r--r--
winmain: Don't use SDL_malloc (or SDL_stack_alloc, which might be malloc).

Otherwise, we are using the allocator before the app can set up its own hooks.

Now we use VirtualAlloc, and WideCharToMultiByte (because SDL_iconv uses
SDL_malloc, too!) to get ready to call into SDL_main.

This also makes console_wmain() call into the same routines as everything
else, so we don't have to deal with those allocations, too. Hopefully we
end up with the same results from GetCommandLine() as we do in wargv.

Fixes Bugzilla #4340.
slouken@5029
     1
# ===========================================================================
slouken@5029
     2
#      http://www.gnu.org/software/autoconf-archive/ax_gcc_archflag.html
slouken@5029
     3
# ===========================================================================
slouken@5029
     4
#
slouken@5029
     5
# SYNOPSIS
slouken@5029
     6
#
slouken@5029
     7
#   AX_GCC_ARCHFLAG([PORTABLE?], [ACTION-SUCCESS], [ACTION-FAILURE])
slouken@5029
     8
#
slouken@5029
     9
# DESCRIPTION
slouken@5029
    10
#
slouken@5029
    11
#   This macro tries to guess the "native" arch corresponding to the target
slouken@5029
    12
#   architecture for use with gcc's -march=arch or -mtune=arch flags. If
slouken@5029
    13
#   found, the cache variable $ax_cv_gcc_archflag is set to this flag and
slouken@5029
    14
#   ACTION-SUCCESS is executed; otherwise $ax_cv_gcc_archflag is is set to
slouken@5029
    15
#   "unknown" and ACTION-FAILURE is executed. The default ACTION-SUCCESS is
slouken@5029
    16
#   to add $ax_cv_gcc_archflag to the end of $CFLAGS.
slouken@5029
    17
#
slouken@5029
    18
#   PORTABLE? should be either [yes] (default) or [no]. In the former case,
slouken@5029
    19
#   the flag is set to -mtune (or equivalent) so that the architecture is
slouken@5029
    20
#   only used for tuning, but the instruction set used is still portable. In
slouken@5029
    21
#   the latter case, the flag is set to -march (or equivalent) so that
slouken@5029
    22
#   architecture-specific instructions are enabled.
slouken@5029
    23
#
slouken@5029
    24
#   The user can specify --with-gcc-arch=<arch> in order to override the
slouken@5029
    25
#   macro's choice of architecture, or --without-gcc-arch to disable this.
slouken@5029
    26
#
slouken@5029
    27
#   When cross-compiling, or if $CC is not gcc, then ACTION-FAILURE is
slouken@5029
    28
#   called unless the user specified --with-gcc-arch manually.
slouken@5029
    29
#
slouken@5029
    30
#   Requires macros: AX_CHECK_COMPILER_FLAGS, AX_GCC_X86_CPUID
slouken@5029
    31
#
slouken@5029
    32
#   (The main emphasis here is on recent CPUs, on the principle that doing
slouken@5029
    33
#   high-performance computing on old hardware is uncommon.)
slouken@5029
    34
#
slouken@5029
    35
# LICENSE
slouken@5029
    36
#
slouken@5029
    37
#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
slouken@5029
    38
#   Copyright (c) 2008 Matteo Frigo
slouken@5029
    39
#
slouken@5029
    40
#   This program is free software: you can redistribute it and/or modify it
slouken@5029
    41
#   under the terms of the GNU General Public License as published by the
slouken@5029
    42
#   Free Software Foundation, either version 3 of the License, or (at your
slouken@5029
    43
#   option) any later version.
slouken@5029
    44
#
slouken@5029
    45
#   This program is distributed in the hope that it will be useful, but
slouken@5029
    46
#   WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@5029
    47
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
slouken@5029
    48
#   Public License for more details.
slouken@5029
    49
#
slouken@5029
    50
#   You should have received a copy of the GNU General Public License along
slouken@5029
    51
#   with this program. If not, see <http://www.gnu.org/licenses/>.
slouken@5029
    52
#
slouken@5029
    53
#   As a special exception, the respective Autoconf Macro's copyright owner
slouken@5029
    54
#   gives unlimited permission to copy, distribute and modify the configure
slouken@5029
    55
#   scripts that are the output of Autoconf when processing the Macro. You
slouken@5029
    56
#   need not follow the terms of the GNU General Public License when using
slouken@5029
    57
#   or distributing such scripts, even though portions of the text of the
slouken@5029
    58
#   Macro appear in them. The GNU General Public License (GPL) does govern
slouken@5029
    59
#   all other use of the material that constitutes the Autoconf Macro.
slouken@5029
    60
#
slouken@5029
    61
#   This special exception to the GPL applies to versions of the Autoconf
slouken@5029
    62
#   Macro released by the Autoconf Archive. When you make and distribute a
slouken@5029
    63
#   modified version of the Autoconf Macro, you may extend this special
slouken@5029
    64
#   exception to the GPL to apply to your modified version as well.
slouken@5029
    65
slouken@5029
    66
#serial 8
slouken@5029
    67
slouken@5029
    68
AC_DEFUN([AX_GCC_ARCHFLAG],
slouken@5029
    69
[AC_REQUIRE([AC_PROG_CC])
slouken@5029
    70
AC_REQUIRE([AC_CANONICAL_HOST])
slouken@5029
    71
slouken@5029
    72
AC_ARG_WITH(gcc-arch, [AS_HELP_STRING([--with-gcc-arch=<arch>], [use architecture <arch> for gcc -march/-mtune, instead of guessing])],
slouken@5029
    73
	ax_gcc_arch=$withval, ax_gcc_arch=yes)
slouken@5029
    74
slouken@5029
    75
AC_MSG_CHECKING([for gcc architecture flag])
slouken@5029
    76
AC_MSG_RESULT([])
slouken@5029
    77
AC_CACHE_VAL(ax_cv_gcc_archflag,
slouken@5029
    78
[
slouken@5029
    79
ax_cv_gcc_archflag="unknown"
slouken@5029
    80
slouken@5029
    81
if test "$GCC" = yes; then
slouken@5029
    82
slouken@5029
    83
if test "x$ax_gcc_arch" = xyes; then
slouken@5029
    84
ax_gcc_arch=""
slouken@5029
    85
if test "$cross_compiling" = no; then
slouken@5029
    86
case $host_cpu in
slouken@5029
    87
  i[[3456]]86*|x86_64*) # use cpuid codes, in part from x86info-1.7 by D. Jones
slouken@5029
    88
     AX_GCC_X86_CPUID(0)
slouken@5029
    89
     AX_GCC_X86_CPUID(1)
slouken@5029
    90
     case $ax_cv_gcc_x86_cpuid_0 in
slouken@5029
    91
       *:756e6547:*:*) # Intel
slouken@5029
    92
          case $ax_cv_gcc_x86_cpuid_1 in
slouken@5029
    93
	    *5[[48]]?:*:*:*) ax_gcc_arch="pentium-mmx pentium" ;;
slouken@5029
    94
	    *5??:*:*:*) ax_gcc_arch=pentium ;;
slouken@5029
    95
	    *6[[3456]]?:*:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
slouken@5029
    96
	    *6a?:*[[01]]:*:*) ax_gcc_arch="pentium2 pentiumpro" ;;
slouken@5029
    97
	    *6a?:*[[234]]:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
slouken@5029
    98
	    *6[[9d]]?:*:*:*) ax_gcc_arch="pentium-m pentium3 pentiumpro" ;;
slouken@5029
    99
	    *6[[78b]]?:*:*:*) ax_gcc_arch="pentium3 pentiumpro" ;;
slouken@5029
   100
	    *6??:*:*:*) ax_gcc_arch=pentiumpro ;;
slouken@5029
   101
            *f3[[347]]:*:*:*|*f4[1347]:*:*:*)
slouken@5029
   102
		case $host_cpu in
slouken@5029
   103
                  x86_64*) ax_gcc_arch="nocona pentium4 pentiumpro" ;;
slouken@5029
   104
                  *) ax_gcc_arch="prescott pentium4 pentiumpro" ;;
slouken@5029
   105
                esac ;;
slouken@5029
   106
            *f??:*:*:*) ax_gcc_arch="pentium4 pentiumpro";;
slouken@5029
   107
          esac ;;
slouken@5029
   108
       *:68747541:*:*) # AMD
slouken@5029
   109
          case $ax_cv_gcc_x86_cpuid_1 in
slouken@5029
   110
	    *5[[67]]?:*:*:*) ax_gcc_arch=k6 ;;
slouken@5029
   111
	    *5[[8d]]?:*:*:*) ax_gcc_arch="k6-2 k6" ;;
slouken@5029
   112
	    *5[[9]]?:*:*:*) ax_gcc_arch="k6-3 k6" ;;
slouken@5029
   113
	    *60?:*:*:*) ax_gcc_arch=k7 ;;
slouken@5029
   114
	    *6[[12]]?:*:*:*) ax_gcc_arch="athlon k7" ;;
slouken@5029
   115
	    *6[[34]]?:*:*:*) ax_gcc_arch="athlon-tbird k7" ;;
slouken@5029
   116
	    *67?:*:*:*) ax_gcc_arch="athlon-4 athlon k7" ;;
slouken@5029
   117
	    *6[[68a]]?:*:*:*)
slouken@5029
   118
	       AX_GCC_X86_CPUID(0x80000006) # L2 cache size
slouken@5029
   119
	       case $ax_cv_gcc_x86_cpuid_0x80000006 in
slouken@5029
   120
                 *:*:*[[1-9a-f]]??????:*) # (L2 = ecx >> 16) >= 256
slouken@5029
   121
			ax_gcc_arch="athlon-xp athlon-4 athlon k7" ;;
slouken@5029
   122
                 *) ax_gcc_arch="athlon-4 athlon k7" ;;
slouken@5029
   123
	       esac ;;
slouken@5029
   124
	    *f[[4cef8b]]?:*:*:*) ax_gcc_arch="athlon64 k8" ;;
slouken@5029
   125
	    *f5?:*:*:*) ax_gcc_arch="opteron k8" ;;
slouken@5029
   126
	    *f7?:*:*:*) ax_gcc_arch="athlon-fx opteron k8" ;;
slouken@5029
   127
	    *f??:*:*:*) ax_gcc_arch="k8" ;;
slouken@5029
   128
          esac ;;
slouken@5029
   129
	*:746e6543:*:*) # IDT
slouken@5029
   130
	   case $ax_cv_gcc_x86_cpuid_1 in
slouken@5029
   131
	     *54?:*:*:*) ax_gcc_arch=winchip-c6 ;;
slouken@5029
   132
	     *58?:*:*:*) ax_gcc_arch=winchip2 ;;
slouken@5029
   133
	     *6[[78]]?:*:*:*) ax_gcc_arch=c3 ;;
slouken@5029
   134
	     *69?:*:*:*) ax_gcc_arch="c3-2 c3" ;;
slouken@5029
   135
	   esac ;;
slouken@5029
   136
     esac
slouken@5029
   137
     if test x"$ax_gcc_arch" = x; then # fallback
slouken@5029
   138
	case $host_cpu in
slouken@5029
   139
	  i586*) ax_gcc_arch=pentium ;;
slouken@5029
   140
	  i686*) ax_gcc_arch=pentiumpro ;;
slouken@5029
   141
        esac
slouken@5029
   142
     fi
slouken@5029
   143
     ;;
slouken@5029
   144
slouken@5029
   145
  sparc*)
slouken@5029
   146
     AC_PATH_PROG([PRTDIAG], [prtdiag], [prtdiag], [$PATH:/usr/platform/`uname -i`/sbin/:/usr/platform/`uname -m`/sbin/])
slouken@5029
   147
     cputype=`(((grep cpu /proc/cpuinfo | cut -d: -f2) ; ($PRTDIAG -v |grep -i sparc) ; grep -i cpu /var/run/dmesg.boot ) | head -n 1) 2> /dev/null`
slouken@5029
   148
     cputype=`echo "$cputype" | tr -d ' -' |tr $as_cr_LETTERS $as_cr_letters`
slouken@5029
   149
     case $cputype in
slouken@5029
   150
         *ultrasparciv*) ax_gcc_arch="ultrasparc4 ultrasparc3 ultrasparc v9" ;;
slouken@5029
   151
         *ultrasparciii*) ax_gcc_arch="ultrasparc3 ultrasparc v9" ;;
slouken@5029
   152
         *ultrasparc*) ax_gcc_arch="ultrasparc v9" ;;
slouken@5029
   153
         *supersparc*|*tms390z5[[05]]*) ax_gcc_arch="supersparc v8" ;;
slouken@5029
   154
         *hypersparc*|*rt62[[056]]*) ax_gcc_arch="hypersparc v8" ;;
slouken@5029
   155
         *cypress*) ax_gcc_arch=cypress ;;
slouken@5029
   156
     esac ;;
slouken@5029
   157
slouken@5029
   158
  alphaev5) ax_gcc_arch=ev5 ;;
slouken@5029
   159
  alphaev56) ax_gcc_arch=ev56 ;;
slouken@5029
   160
  alphapca56) ax_gcc_arch="pca56 ev56" ;;
slouken@5029
   161
  alphapca57) ax_gcc_arch="pca57 pca56 ev56" ;;
slouken@5029
   162
  alphaev6) ax_gcc_arch=ev6 ;;
slouken@5029
   163
  alphaev67) ax_gcc_arch=ev67 ;;
slouken@5029
   164
  alphaev68) ax_gcc_arch="ev68 ev67" ;;
slouken@5029
   165
  alphaev69) ax_gcc_arch="ev69 ev68 ev67" ;;
slouken@5029
   166
  alphaev7) ax_gcc_arch="ev7 ev69 ev68 ev67" ;;
slouken@5029
   167
  alphaev79) ax_gcc_arch="ev79 ev7 ev69 ev68 ev67" ;;
slouken@5029
   168
slouken@5029
   169
  powerpc*)
slouken@5029
   170
     cputype=`((grep cpu /proc/cpuinfo | head -n 1 | cut -d: -f2 | cut -d, -f1 | sed 's/ //g') ; /usr/bin/machine ; /bin/machine; grep CPU /var/run/dmesg.boot | head -n 1 | cut -d" " -f2) 2> /dev/null`
slouken@5029
   171
     cputype=`echo $cputype | sed -e 's/ppc//g;s/ *//g'`
slouken@5029
   172
     case $cputype in
slouken@5029
   173
       *750*) ax_gcc_arch="750 G3" ;;
slouken@5029
   174
       *740[[0-9]]*) ax_gcc_arch="$cputype 7400 G4" ;;
slouken@5029
   175
       *74[[4-5]][[0-9]]*) ax_gcc_arch="$cputype 7450 G4" ;;
slouken@5029
   176
       *74[[0-9]][[0-9]]*) ax_gcc_arch="$cputype G4" ;;
slouken@5029
   177
       *970*) ax_gcc_arch="970 G5 power4";;
slouken@5029
   178
       *POWER4*|*power4*|*gq*) ax_gcc_arch="power4 970";;
slouken@5029
   179
       *POWER5*|*power5*|*gr*|*gs*) ax_gcc_arch="power5 power4 970";;
slouken@5029
   180
       603ev|8240) ax_gcc_arch="$cputype 603e 603";;
slouken@5029
   181
       *) ax_gcc_arch=$cputype ;;
slouken@5029
   182
     esac
slouken@5029
   183
     ax_gcc_arch="$ax_gcc_arch powerpc"
slouken@5029
   184
     ;;
slouken@5029
   185
esac
slouken@5029
   186
fi # not cross-compiling
slouken@5029
   187
fi # guess arch
slouken@5029
   188
slouken@5029
   189
if test "x$ax_gcc_arch" != x -a "x$ax_gcc_arch" != xno; then
slouken@5029
   190
for arch in $ax_gcc_arch; do
slouken@5029
   191
  if test "x[]m4_default([$1],yes)" = xyes; then # if we require portable code
slouken@5029
   192
    flags="-mtune=$arch"
slouken@5029
   193
    # -mcpu=$arch and m$arch generate nonportable code on every arch except
slouken@5029
   194
    # x86.  And some other arches (e.g. Alpha) don't accept -mtune.  Grrr.
slouken@5029
   195
    case $host_cpu in i*86|x86_64*) flags="$flags -mcpu=$arch -m$arch";; esac
slouken@5029
   196
  else
slouken@5029
   197
    flags="-march=$arch -mcpu=$arch -m$arch"
slouken@5029
   198
  fi
slouken@5029
   199
  for flag in $flags; do
slouken@5029
   200
    AX_CHECK_COMPILER_FLAGS($flag, [ax_cv_gcc_archflag=$flag; break])
slouken@5029
   201
  done
slouken@5029
   202
  test "x$ax_cv_gcc_archflag" = xunknown || break
slouken@5029
   203
done
slouken@5029
   204
fi
slouken@5029
   205
slouken@5029
   206
fi # $GCC=yes
slouken@5029
   207
])
slouken@5029
   208
AC_MSG_CHECKING([for gcc architecture flag])
slouken@5029
   209
AC_MSG_RESULT($ax_cv_gcc_archflag)
slouken@5029
   210
if test "x$ax_cv_gcc_archflag" = xunknown; then
slouken@5029
   211
  m4_default([$3],:)
slouken@5029
   212
else
slouken@5029
   213
  m4_default([$2], [CFLAGS="$CFLAGS $ax_cv_gcc_archflag"])
slouken@5029
   214
fi
slouken@5029
   215
])