3 # This shell script handles all host based configuration for newlib.
4 # It sets various shell variables based on the the host and the
5 # configuration options. You can modify this shell script without
6 # needing to rerun autoconf.
8 # This shell script should be invoked as
10 # If it encounters an error, it will exit with a message.
12 # FIXME: This script is too complicated. It does things in too many
13 # different ways. This was taken from the old Cygnus configure script
14 # with only minor changes. It should be cleaned up.
16 # FIXME: The general approach of picking and choosing which
17 # directories to configure, other than machine_dir and sys_dir, is
18 # potentially confusing.
20 # It uses the following shell variables:
21 # host The configuration host
22 # host_cpu The configuration host CPU
23 # newlib_mb --enable-newlib-mb ("yes", "no")
24 # target_optspace --enable-target-optspace ("yes", "no", "")
25 # newlib_multithread --enable-newlib-multithread ("yes", "no", "yes")
26 # newlib_elix_level --enable-newlib-elix-level ("1","2","3","4") ("4")
27 # newlib_io_c99_formats --enable-newlib-io-c99-formats ("yes", "no", "")
28 # newlib_io_long_long --enable-newlib-io-long-long ("yes", "no", "")
29 # newlib_io_long_double --enable-newlib-io-long-double ("yes", "no", "")
30 # newlib_global_stdio_streams --enable-global-stdio-streams ("yes", "no, "")
31 # newlib_fno_builtin --disable-newlib-fno-builtin ("yes", "no, "")
32 # newlib_reent_check_verify --enable-newlib-reent-check-verify ("yes", "no, "")
34 # It sets the following shell variables:
35 # newlib_cflags Special CFLAGS to use when building
36 # machine_dir Subdirectory of libc/machine to configure
37 # shared_machine_dir Subdirectory of libc/machine for files shared
38 # between specific architectures, optional
39 # sys_dir Subdirectory of libc/sys to configure
40 # have_sys_mach_dir Is there a machine subdirectory in sys subdirectory
41 # posix_dir "posix" to build libc/posix, "" otherwise
42 # signal_dir "signal" to build libc/signal, "" otherwise
43 # stdio64_dir "stdio64" to build libc/stdio64, "" otherwise
44 # syscall_dir "syscalls" to build libc/syscalls, "" otherwise
45 # unix_dir "unix" to build libc/unix, "" otherwise
46 # lpfx library object prefix - generated when no libtool
47 # crt1 name of crt1 object if one is provided
48 # crt1_dir directory where crt1 object is found
49 # have_crt0 "yes"/"no" if crt0 is/isn't provided.
50 # "" if crt0 is provided when sys_dir is set
51 # have_init_fini have init/fini ("yes" or "no", set to "yes" by default)
52 # noinclude list of include files to not install
54 newlib_cflags="-D_LIBC"
72 default_newlib_io_c99_formats=no
73 default_newlib_io_long_long=no
74 default_newlib_io_long_double=no
75 default_newlib_io_pos_args=no
76 default_newlib_atexit_dynamic_alloc=yes
77 default_newlib_nano_malloc=no
78 default_newlib_reent_check_verify=yes
82 case "${target_optspace}:${host}" in
84 newlib_cflags="${newlib_cflags} -Os"
86 :m32r-* | :d10v-* | :d30v-* | :avr-* | :m32c-* | :msp430*-* | :nds32* | :pru-* | :rl78-* )
87 newlib_cflags="${newlib_cflags} -Os"
93 case "${newlib_fno_builtin}:${host}" in
95 newlib_cflags="${newlib_cflags} -fno-builtin"
98 newlib_cflags="${newlib_cflags}"
101 # For now, all targets default to using -fno-builtin until tested without
102 newlib_cflags="${newlib_cflags} -fno-builtin"
106 # Get the source directories to use for the CPU type.
107 # machine_dir should supply CPU dependent routines, such as setjmp.
108 # newlib_cflags is passed to gcc when compiling.
109 # THIS TABLE IS ALPHA SORTED. KEEP IT THAT WAY.
111 case "${host_cpu}" in
117 libm_machine_dir=aarch64
120 newlib_cflags="${newlib_cflags} -D__DYNAMIC_REENT__"
122 libm_machine_dir=amdgcn
123 newlib_cv_initfinit_array=yes
136 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -mcall-prologues"
145 # The size of the (kernel_)time_t passed from or to a
146 # simulator or a Linux kernel is mandated by the
147 # gettimeofday and time system calls and fixed to 32 bits, the
148 # size of a long. Instead of churning as 64 bits what is anyway
149 # 32 bits, it makes more sense to default to long.
150 test -z "${enable_newlib_long_time_t}" && newlib_long_time_t=yes
158 default_newlib_atexit_dynamic_alloc="no"
171 newlib_cflags="${newlib_cflags} -DCOMPACT_CTYPE"
181 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED"
196 libm_machine_dir=i386
198 shared_machine_dir=shared_x86
199 # Don't use for these since they provide their own setjmp.
201 *-*-sco* | *-*-cygwin*)
218 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY"
225 m68hc11|m6811|m68hc12|m6812)
227 newlib_cflags="-DPREFER_SIZE_OVER_SPEED -Os -mrelax"
233 newlib_cflags="${newlib_cflags} -DCOMPACT_CTYPE"
237 newlib_cflags="${newlib_cflags} -m88000"
241 newlib_cflags="${newlib_cflags} -m88110"
246 machine_dir=microblaze
253 libm_machine_dir=mips
261 default_newlib_io_long_long="yes"
268 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY"
269 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
270 newlib_cflags="${newlib_cflags} -mOs "
271 newlib_cflags="${newlib_cflags} -mhwmult=none "
273 default_newlib_nano_malloc="yes"
280 libm_machine_dir=nds32
281 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections"
282 newlib_cflags="${newlib_cflags} -DHAVE_RENAME"
289 newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DMALLOC_PROVIDED"
297 libm_machine_dir=powerpc
300 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED"
301 newlib_cflags="${newlib_cflags} -DNO_EXEC"
302 newlib_cflags="${newlib_cflags} -DSMALL_MEMORY"
303 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
304 default_newlib_nano_malloc="yes"
305 default_newlib_atexit_dynamic_alloc="no"
310 libm_machine_dir=riscv
312 newlib_cflags="${newlib_cflags} -DHAVE_NANOSLEEP"
313 default_newlib_atexit_dynamic_alloc="no"
318 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY"
319 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
323 default_newlib_io_long_long="yes"
324 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
330 libm_machine_dir=sparc
332 # FIXME: Might wish to make MALLOC_ALIGNMENT more generic.
333 newlib_cflags="${newlib_cflags} -DMALLOC_ALIGNMENT=8"
350 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED "
360 libm_machine_dir=x86_64
361 shared_machine_dir=shared_x86
367 machine_dir=xstormy16
368 newlib_cflags="${newlib_cflags} -DMALLOC_PROVIDED"
369 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED"
372 libm_machine_dir=xtensa
374 newlib_cflags="${newlib_cflags} -mlongcalls"
375 default_newlib_atexit_dynamic_alloc="no"
385 newlib_cflags="${newlib_cflags} -D_POSIX_MODE"
386 newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED"
387 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
388 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
391 echo '***' "Newlib does not support CPU ${host_cpu}" 1>&2
396 # Disable thread support if requested.
398 if [ "${newlib_multithread}" = "no" ] ; then
399 newlib_cflags="${newlib_cflags} -D__SINGLE_THREAD__"
402 # Disable syscall support if requested.
404 if [ "${newlib_may_supply_syscalls}" = "no" ] ; then
405 newlib_cflags="${newlib_cflags} -D__NO_SYSCALLS__"
408 # Enable multibyte support if requested or it is defaulted
411 if [ "x${newlib_mb}" = "x" ]; then
419 # Disable printf/scanf floating-point support if requested.
421 if [ "${newlib_io_float}" = "no" ] ; then
422 newlib_cflags="${newlib_cflags} -DNO_FLOATING_POINT"
425 # Get the source directories to use for the host. unix_dir is set
426 # to unix to get some standard Unix routines. posix_dir is set to get some
427 # standard Posix routines. sys_dir should supply system dependent routines
429 # THIS TABLE IS ALPHA SORTED. KEEP IT THAT WAY.
440 *-*-rtems*) # generic RTEMS support
453 newlib_cflags="${newlib_cflags} -D_NO_GLOB -D_NO_EXECVE -D_NO_GETLOGIN -D_NO_GETPWENT -D_NO_GETUT"
454 newlib_cflags="${newlib_cflags} -D_NO_GETPASS -D_NO_SIGSET -D_NO_WORDEXP -D_NO_POPEN -D_NO_POSIX_SPAWN"
455 newlib_cflags="${newlib_cflags} -DHAVE_FCNTL -DHAVE_BLKSIZE -DHAVE_OPENDIR -DHAVE_RENAME"
456 newlib_cflags="${newlib_cflags} -DGETREENT_PROVIDED -DSIGNAL_PROVIDED"
468 if [ "x${newlib_may_supply_syscalls}" = "xno" ] ; then
489 # crt0 is provided by libgloss.
518 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
519 newlib_cflags="${newlib_cflags} -D_I386MACH_DISABLE_HW_INTERRUPTS"
526 m68hc11-*-*|m6811-*-*|m6812-*-*|m68hc12-*-*)
536 default_newlib_io_long_long="yes"
537 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
540 machine_dir=microblaze
551 or1k-*-elf | or1knd-*-elf)
553 newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED "
563 default_newlib_io_long_long="yes"
564 default_newlib_atexit_dynamic_alloc="no"
567 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
581 if [ "x${newlib_may_supply_syscalls}" = "xno" ] ; then
596 # Host specific flag settings -- usually for features that are not
597 # general enough or broad enough to be handled above.
598 # THIS TABLE IS ALPHA SORTED. KEEP IT THAT WAY.
602 test -z "$cygwin_srcdir" && cygwin_srcdir="${abs_newlib_basedir}/../winsup/cygwin"
604 default_newlib_io_c99_formats="yes"
605 default_newlib_io_long_long="yes"
606 default_newlib_io_long_double="yes"
607 default_newlib_io_pos_args="yes"
608 CC="${CC} -I${cygwin_srcdir}/include"
609 newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DGETREENT_PROVIDED -DSIGNAL_PROVIDED -DHAVE_BLKSIZE -DHAVE_FCNTL -DMALLOC_PROVIDED -DHAVE_CHDIR -DHAVE_FCHDIR"
612 # RTEMS supplies its own versions of some routines:
613 # malloc() (reentrant version)
614 # exit() RTEMS has a "global" reent to flush
615 # signal()/raise() RTEMS has its own including pthread signals
616 # _XYZ_r() RTEMS has its own reentrant routines
618 # NOTE: When newlib malloc uses a semaphore, RTEMS will switch to that.
620 default_newlib_io_long_long="yes"
621 default_newlib_io_c99_formats="yes"
622 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
623 newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DMALLOC_PROVIDED -DEXIT_PROVIDED -DSIGNAL_PROVIDED -DGETREENT_PROVIDED -DREENTRANT_SYSCALLS_PROVIDED -DHAVE_NANOSLEEP -DHAVE_BLKSIZE -DHAVE_FCNTL -DHAVE_ASSERT_FUNC"
624 # turn off unsupported items in posix directory
625 newlib_cflags="${newlib_cflags} -D_NO_GETLOGIN -D_NO_GETPWENT -D_NO_GETUT -D_NO_GETPASS -D_NO_SIGSET -D_NO_WORDEXP -D_NO_POPEN -D_NO_POSIX_SPAWN"
627 # VxWorks supplies its own version of malloc, and the newlib one
628 # doesn't work because VxWorks does not have sbrk.
630 newlib_cflags="${newlib_cflags} -DMALLOC_PROVIDED -DMISSING_SYSCALL_NAMES -DHAVE_FCNTL"
632 # TIRTOS supplies its own version of malloc
634 newlib_cflags="${newlib_cflags} -D__DYNAMIC_REENT__ -DMALLOC_PROVIDED"
636 # UDI doesn't have exec, so system() should fail the right way
638 newlib_cflags="${newlib_cflags} -DNO_EXEC"
642 default_newlib_io_long_long="yes"
647 default_newlib_io_long_long="yes"
651 newlib_cflags="${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE"
655 # If newlib is supplying syscalls, select which debug protocol is being used.
656 # ARM_RDP_MONITOR selects the Demon monitor.
657 # ARM_RDI_MONITOR selects the Angel monitor.
658 # If neither are defined, then hard coded defaults will be used
659 # to create the program's environment.
660 # If --disable-newlib-supplied-syscalls is specified, then the end-user
661 # may specify the protocol via gcc spec files supplied by libgloss.
662 if [ "x${newlib_may_supply_syscalls}" = "xyes" ] ; then
663 # newlib_cflags="${newlib_cflags} -DARM_RDP_MONITOR"
664 newlib_cflags="${newlib_cflags} -DARM_RDI_MONITOR"
666 newlib_cflags="${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE"
669 newlib_cflags="${newlib_cflags} -DNO_EXEC -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES"
674 cris-*-* | crisv32-*-*)
675 default_newlib_io_long_long="yes"
676 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -D_USE_WRITE -DCOMPACT_CTYPE"
683 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DMISSING_SYSCALL_NAMES"
687 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
691 newlib_cflags="${newlib_cflags} -DSMALL_MEMORY"
695 newlib_cflags="${newlib_cflags} -DABORT_MESSAGE -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES"
700 newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED"
703 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
711 default_newlib_io_long_long="yes"
718 default_newlib_io_long_long="yes"
719 newlib_cflags="${newlib_cflags} -DSMALL_DTOA -DSMALL_MEMORY"
720 # Simulator only extensions for H8300.
721 # Uncomment the next line to enable them.
722 # newlib_cflags="${newlib_cflags} -D__SIMULATOR__"
726 newlib_cflags="${newlib_cflags} -DSMALL_DTOA -DSMALL_MEMORY"
729 newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED -DHAVE_FCNTL"
731 i[34567]86-*-netware*)
732 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DNO_EXEC -DABORT_PROVIDED -DCLOCK_PROVIDED -DMALLOC_PROVIDED -DHAVE_FCNTL"
735 newlib_cflags="${newlib_cflags} -Os -DPREFER_SIZE_OVER_SPEED -ffunction-sections -fomit-frame-pointer -DREENTRANT_SYSCALL_PROVIDED"
736 if [ "${newlib_multithread}" = "no" ] ; then
737 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
740 newlib_cflags="${newlib_cflags} -D__DYNAMIC_REENT__"
745 default_newlib_io_long_long="yes"
751 default_newlib_io_long_long="yes"
752 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DABORT_PROVIDED"
756 # Pass -msdata=sdata so _impure_ptr goes in .sdata.
757 # We don't generate sda relocs however for upward compatibility.
758 # FIXME: This is necessary because the default multilib doesn't
759 # use --print-multi-lib.
760 newlib_cflags="${newlib_cflags} -msdata=sdata"
763 m68hc11-*-*|m6811-*-*|m68hc12-*-*|m6812-*-*)
764 newlib_cflags="${newlib_cflags} -DNO_EXEC -DABORT_PROVIDED -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES"
767 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
774 default_newlib_io_long_long="yes"
775 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DSMALL_MEMORY -D_REENT_SMALL"
778 default_newlib_io_long_long="yes"
779 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
782 default_newlib_io_long_long="yes"
783 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
787 # We need every symbol 32-bit aligned, so the invalid
788 # construct with attribute ((alias ("_ctype_b+127"))) breaks.
789 newlib_cflags="${newlib_cflags} -DCOMPACT_CTYPE"
794 moxie-*-elf* | moxie-*-rtems*)
796 default_newlib_io_long_long="yes"
800 default_newlib_io_long_long="yes"
801 newlib_cflags="${newlib_cflags} -Os -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY"
805 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
813 powerpc*-*-eabialtivec*)
814 default_newlib_io_long_long="yes"
815 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
818 default_newlib_io_long_long="yes"
819 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
823 powerpc*-*-linux* | \
827 default_newlib_io_long_long="yes"
828 newlib_cflags="${newlib_cflags} -mrelocatable-lib -mno-eabi -mstrict-align -DMISSING_SYSCALL_NAMES"
831 newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DHAVE_FCNTL -D_NO_POSIX_SPAWN"
836 newlib_cflags="${newlib_cflags} -DSMALL_MEMORY -D_REENT_SMALL"
842 default_newlib_io_long_long="yes"
846 newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED"
849 newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED -DHAVE_BLKSIZE -DHAVE_FCNTL"
850 # This either belongs elsewhere or nowhere. But I need *something*,
851 # so for now it's here ...
854 newlib_cflags="${newlib_cflags} -DTARGET_PTR_SIZE=32" ;;
856 newlib_cflags="${newlib_cflags} -DTARGET_PTR_SIZE=64" ;;
861 newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED"
870 newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
875 newlib_cflags="${newlib_cflags} -DSMALL_DTOA -DSMALL_MEMORY"
883 xtensa*-*-* | xtensa*-*)
890 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
895 # Use defaults for certain settings if not specified by user
897 # Enable C99 format support in I/O routines if requested.
898 if [ "x${newlib_io_c99_formats}" = "x" ]; then
899 if [ ${default_newlib_io_c99_formats} = "yes" ]; then
900 newlib_io_c99_formats="yes";
904 # Enable long long support in I/O routines if requested.
905 if [ "x${newlib_io_long_long}" = "x" ]; then
906 if [ ${default_newlib_io_long_long} = "yes" ]; then
907 newlib_io_long_long="yes";
911 # Enable long double support in I/O routines if requested.
912 if [ "x${newlib_io_long_double}" = "x" ]; then
913 if [ ${default_newlib_io_long_double} = "yes" ]; then
914 newlib_io_long_double="yes";
918 # Enable printf positional argument support if requested.
919 if [ "x${newlib_io_pos_args}" = "x" ]; then
920 if [ ${default_newlib_io_pos_args} = "yes" ]; then
921 newlib_io_pos_args="yes";
925 # Disable atexit dynamic allocation if requested.
926 if [ "x${newlib_atexit_dynamic_alloc}" = "x" ]; then
927 if [ ${default_newlib_atexit_dynamic_alloc} = "yes" ]; then
928 newlib_atexit_dynamic_alloc="yes";
932 # Enable nano-malloc if requested.
933 if [ "x${newlib_nano_malloc}" = "x" ]; then
934 if [ ${default_newlib_nano_malloc} = "yes" ]; then
935 newlib_nano_malloc="yes";
939 # Enable _REENT_CHECK macro memory allocation verification.
940 if [ "x${newlib_reent_check_verify}" = "x" ]; then
941 if [ ${default_newlib_reent_check_verify} = "yes" ]; then
942 newlib_reent_check_verify="yes";
946 # Remove rpc headers if xdr_dir not specified
947 if [ "x${xdr_dir}" = "x" ]; then
948 noinclude="${noinclude} rpc/types.h rpc/xdr.h"
951 # Have init/finit if not explicitly specified otherwise
952 if [ "x${have_init_fini}" != "xno" ]; then
953 newlib_cflags="${newlib_cflags} -D_HAVE_INIT_FINI"
956 if test -z "${have_crt0}" && test -n "${sys_dir}"; then
960 # Target-specific defaults
961 case "${host_cpu}" in
963 if [[ -z ${newlib_global_stdio_streams} ]]; then
964 newlib_global_stdio_streams="yes";