1# -*- shell-script -*-
2#  Copyright (C) 2012-2016 Free Software Foundation, Inc.
3#  Contributed by Richard Henderson <rth@redhat.com>.
4#
5#  This file is part of the GNU Atomic Library (libatomic).
6#
7#  Libatomic is free software; you can redistribute it and/or modify it
8#  under the terms of the GNU General Public License as published by
9#  the Free Software Foundation; either version 3 of the License, or
10#  (at your option) any later version.
11#
12#  Libatomic is distributed in the hope that it will be useful, but WITHOUT ANY
13#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15#  more details.
16#
17#  Under Section 7 of GPL version 3, you are granted additional
18#  permissions described in the GCC Runtime Library Exception, version
19#  3.1, as published by the Free Software Foundation.
20#
21#  You should have received a copy of the GNU General Public License and
22#  a copy of the GCC Runtime Library Exception along with this program;
23#  see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24#  <http://www.gnu.org/licenses/>.
25
26# Map the target cpu to an ARCH sub-directory.  At the same time,
27# work out any special compilation flags as necessary.
28
29# Give operating systems the opportunity to discard XCFLAGS modifications based
30# on ${target_cpu}.  For example to allow proper use of multilibs.
31configure_tgt_pre_target_cpu_XCFLAGS="${XCFLAGS}"
32
33case "${target_cpu}" in
34  alpha*)
35	# fenv.c needs this option to generate inexact exceptions.
36	XCFLAGS="${XCFLAGS} -mfp-trap-mode=sui"
37	ARCH=alpha
38	;;
39  rs6000 | powerpc*)	ARCH=powerpc ;;
40  sh*)			ARCH=sh ;;
41
42  arm*)
43	ARCH=arm
44	case "${target}" in
45            arm*-*-freebsd*)
46                ;;
47            *)
48                # ??? Detect when -march=armv7 is already enabled.
49                try_ifunc=yes
50                ;;
51        esac
52        ;;
53  sparc)
54	case " ${CC} ${CFLAGS} " in
55	  *" -m64 "*)
56	    ;;
57	  *)
58	    if test -z "$with_cpu"; then
59	      XCFLAGS="${XCFLAGS} -mcpu=v9"
60	    fi
61	esac
62	ARCH=sparc
63	;;
64  sparc64|sparcv9)
65	case " ${CC} ${CFLAGS} " in
66	  *" -m32 "*)
67	    XCFLAGS="${XCFLAGS} -mcpu=v9"
68	    ;;
69	esac
70	ARCH=sparc
71	;;
72
73  i[3456]86)
74	case " ${CC} ${CFLAGS} " in
75	  *" -m64 "*|*" -mx32 "*)
76	    ;;
77	  *)
78	    if test -z "$with_arch"; then
79	      XCFLAGS="${XCFLAGS} -march=i486 -mtune=${target_cpu}"
80	      XCFLAGS="${XCFLAGS} -fomit-frame-pointer"
81	    fi
82	esac
83	ARCH=x86
84	# ??? Detect when -march=i686 is already enabled.
85	try_ifunc=yes
86	;;
87  x86_64)
88	case " ${CC} ${CFLAGS} " in
89	  *" -m32 "*)
90	    XCFLAGS="${XCFLAGS} -march=i486 -mtune=generic"
91	    XCFLAGS="${XCFLAGS} -fomit-frame-pointer"
92	    ;;
93	  *)
94	    ;;
95	esac
96	ARCH=x86
97	# ??? Detect when -mcx16 is already enabled.
98	try_ifunc=yes
99	;;
100
101  *)			ARCH="${target_cpu}" ;;
102esac
103
104# The cpu configury is always most relevant.
105if test -d ${srcdir}/config/$ARCH ; then
106  config_path="$ARCH"
107fi
108
109# Other system configury
110case "${target}" in
111  arm*-*-linux*)
112	# OS support for atomic primitives.
113	config_path="${config_path} linux/arm posix"
114	;;
115
116  *-*-linux* | *-*-gnu* | *-*-k*bsd*-gnu \
117  | *-*-netbsd* | *-*-freebsd* | *-*-openbsd* | *-*-dragonfly* \
118  | *-*-solaris2* | *-*-sysv4* | *-*-irix6* | *-*-osf* | *-*-hpux11* \
119  | *-*-darwin* | *-*-aix* | *-*-cygwin*)
120	# POSIX system.  The OS is supported.
121	config_path="${config_path} posix"
122	;;
123
124  *-*-mingw*)
125	# OS support for atomic primitives.
126        case ${target_thread_file} in
127          win32)
128            config_path="${config_path} mingw"
129            ;;
130          posix)
131            config_path="${config_path} posix"
132            ;;
133        esac
134	;;
135
136  *-*-rtems*)
137	XCFLAGS="${configure_tgt_pre_target_cpu_XCFLAGS}"
138	config_path="rtems"
139	;;
140
141  *-*-elf*)
142	# ??? No target OS.  We could be targeting bare-metal kernel-mode,
143	# or user-mode for some custom OS.  If the target supports TAS,
144	# we can build our own spinlocks, given there are no signals.
145	# If the target supports disabling interrupts, we can work in
146	# kernel-mode, given the system is not multi-processor.
147	UNSUPPORTED=1
148	;;
149
150  *)
151	# Who are you?
152	UNSUPPORTED=1
153	;;
154esac
155