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
133 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -mcall-prologues"
142 # The size of the (kernel_)time_t passed from or to a
143 # simulator or a Linux kernel is mandated by the
144 # gettimeofday and time system calls and fixed to 32 bits, the
145 # size of a long. Instead of churning as 64 bits what is anyway
146 # 32 bits, it makes more sense to default to long.
147 test -z "${enable_newlib_long_time_t}" && newlib_long_time_t=yes
155 default_newlib_atexit_dynamic_alloc="no"
168 newlib_cflags="${newlib_cflags} -DCOMPACT_CTYPE"
178 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED"
193 libm_machine_dir=i386
195 shared_machine_dir=shared_x86
196 # Don't use for these since they provide their own setjmp.
198 *-*-sco* | *-*-cygwin*)
215 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY"
222 m68hc11|m6811|m68hc12|m6812)
224 newlib_cflags="-DPREFER_SIZE_OVER_SPEED -Os -mrelax"
230 newlib_cflags="${newlib_cflags} -DCOMPACT_CTYPE"
234 newlib_cflags="${newlib_cflags} -m88000"
238 newlib_cflags="${newlib_cflags} -m88110"
243 machine_dir=microblaze
250 libm_machine_dir=mips
258 default_newlib_io_long_long="yes"
265 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY"
266 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
267 newlib_cflags="${newlib_cflags} -mOs "
268 newlib_cflags="${newlib_cflags} -mhwmult=none "
270 default_newlib_nano_malloc="yes"
277 libm_machine_dir=nds32
278 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections"
279 newlib_cflags="${newlib_cflags} -DHAVE_RENAME"
286 newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DMALLOC_PROVIDED"
294 libm_machine_dir=powerpc
297 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED"
298 newlib_cflags="${newlib_cflags} -DNO_EXEC"
299 newlib_cflags="${newlib_cflags} -DSMALL_MEMORY"
300 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
301 default_newlib_nano_malloc="yes"
302 default_newlib_atexit_dynamic_alloc="no"
307 libm_machine_dir=riscv
309 newlib_cflags="${newlib_cflags} -DHAVE_NANOSLEEP"
310 default_newlib_atexit_dynamic_alloc="no"
315 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY"
316 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
320 default_newlib_io_long_long="yes"
321 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
327 libm_machine_dir=sparc
329 # FIXME: Might wish to make MALLOC_ALIGNMENT more generic.
330 newlib_cflags="${newlib_cflags} -DMALLOC_ALIGNMENT=8"
347 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED "
357 libm_machine_dir=x86_64
358 shared_machine_dir=shared_x86
364 machine_dir=xstormy16
365 newlib_cflags="${newlib_cflags} -DMALLOC_PROVIDED"
366 newlib_cflags="${newlib_cflags} -DPREFER_SIZE_OVER_SPEED"
369 libm_machine_dir=xtensa
371 newlib_cflags="${newlib_cflags} -mlongcalls"
372 default_newlib_atexit_dynamic_alloc="no"
382 newlib_cflags="${newlib_cflags} -D_POSIX_MODE"
383 newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED"
384 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
385 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
388 echo '***' "Newlib does not support CPU ${host_cpu}" 1>&2
393 # Disable thread support if requested.
395 if [ "${newlib_multithread}" = "no" ] ; then
396 newlib_cflags="${newlib_cflags} -D__SINGLE_THREAD__"
399 # Disable syscall support if requested.
401 if [ "${newlib_may_supply_syscalls}" = "no" ] ; then
402 newlib_cflags="${newlib_cflags} -D__NO_SYSCALLS__"
405 # Enable multibyte support if requested or it is defaulted
408 if [ "x${newlib_mb}" = "x" ]; then
416 # Disable printf/scanf floating-point support if requested.
418 if [ "${newlib_io_float}" = "no" ] ; then
419 newlib_cflags="${newlib_cflags} -DNO_FLOATING_POINT"
422 # Get the source directories to use for the host. unix_dir is set
423 # to unix to get some standard Unix routines. posix_dir is set to get some
424 # standard Posix routines. sys_dir should supply system dependent routines
426 # THIS TABLE IS ALPHA SORTED. KEEP IT THAT WAY.
437 *-*-rtems*) # generic RTEMS support
456 if [ "x${newlib_may_supply_syscalls}" = "xno" ] ; then
477 # crt0 is provided by libgloss.
506 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
507 newlib_cflags="${newlib_cflags} -D_I386MACH_DISABLE_HW_INTERRUPTS"
514 m68hc11-*-*|m6811-*-*|m6812-*-*|m68hc12-*-*)
524 default_newlib_io_long_long="yes"
525 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
528 machine_dir=microblaze
539 or1k-*-elf | or1knd-*-elf)
541 newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED "
551 default_newlib_io_long_long="yes"
552 default_newlib_atexit_dynamic_alloc="no"
555 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
569 if [ "x${newlib_may_supply_syscalls}" = "xno" ] ; then
587 # Host specific flag settings -- usually for features that are not
588 # general enough or broad enough to be handled above.
589 # THIS TABLE IS ALPHA SORTED. KEEP IT THAT WAY.
593 test -z "$cygwin_srcdir" && cygwin_srcdir="${abs_newlib_basedir}/../winsup/cygwin"
595 default_newlib_io_c99_formats="yes"
596 default_newlib_io_long_long="yes"
597 default_newlib_io_long_double="yes"
598 default_newlib_io_pos_args="yes"
599 CC="${CC} -I${cygwin_srcdir}/include"
600 newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DGETREENT_PROVIDED -DSIGNAL_PROVIDED -DHAVE_BLKSIZE -DHAVE_FCNTL -DMALLOC_PROVIDED -DHAVE_CHDIR -DHAVE_FCHDIR"
603 # RTEMS supplies its own versions of some routines:
604 # malloc() (reentrant version)
605 # exit() RTEMS has a "global" reent to flush
606 # signal()/raise() RTEMS has its own including pthread signals
607 # _XYZ_r() RTEMS has its own reentrant routines
609 # NOTE: When newlib malloc uses a semaphore, RTEMS will switch to that.
611 default_newlib_io_long_long="yes"
612 default_newlib_io_c99_formats="yes"
613 newlib_cflags="${newlib_cflags} -ffunction-sections -fdata-sections "
614 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"
615 # turn off unsupported items in posix directory
616 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"
618 # VxWorks supplies its own version of malloc, and the newlib one
619 # doesn't work because VxWorks does not have sbrk.
621 newlib_cflags="${newlib_cflags} -DMALLOC_PROVIDED -DMISSING_SYSCALL_NAMES -DHAVE_FCNTL"
623 # TIRTOS supplies its own version of malloc
625 newlib_cflags="${newlib_cflags} -D__DYNAMIC_REENT__ -DMALLOC_PROVIDED"
627 # UDI doesn't have exec, so system() should fail the right way
629 newlib_cflags="${newlib_cflags} -DNO_EXEC"
633 default_newlib_io_long_long="yes"
638 default_newlib_io_long_long="yes"
642 newlib_cflags="${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE"
646 # If newlib is supplying syscalls, select which debug protocol is being used.
647 # ARM_RDP_MONITOR selects the Demon monitor.
648 # ARM_RDI_MONITOR selects the Angel monitor.
649 # If neither are defined, then hard coded defaults will be used
650 # to create the program's environment.
651 # If --disable-newlib-supplied-syscalls is specified, then the end-user
652 # may specify the protocol via gcc spec files supplied by libgloss.
653 if [ "x${newlib_may_supply_syscalls}" = "xyes" ] ; then
654 # newlib_cflags="${newlib_cflags} -DARM_RDP_MONITOR"
655 newlib_cflags="${newlib_cflags} -DARM_RDI_MONITOR"
657 newlib_cflags="${newlib_cflags} -DHAVE_SYSCONF_PAGESIZE"
660 newlib_cflags="${newlib_cflags} -DNO_EXEC -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES"
665 cris-*-* | crisv32-*-*)
666 default_newlib_io_long_long="yes"
667 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -D_USE_WRITE -DCOMPACT_CTYPE"
674 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DMISSING_SYSCALL_NAMES"
678 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
682 newlib_cflags="${newlib_cflags} -DSMALL_MEMORY"
686 newlib_cflags="${newlib_cflags} -DABORT_MESSAGE -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES"
691 newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED"
694 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
702 default_newlib_io_long_long="yes"
709 default_newlib_io_long_long="yes"
710 newlib_cflags="${newlib_cflags} -DSMALL_DTOA -DSMALL_MEMORY"
711 # Simulator only extensions for H8300.
712 # Uncomment the next line to enable them.
713 # newlib_cflags="${newlib_cflags} -D__SIMULATOR__"
717 newlib_cflags="${newlib_cflags} -DSMALL_DTOA -DSMALL_MEMORY"
720 newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED -DHAVE_FCNTL"
722 i[34567]86-*-netware*)
723 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DNO_EXEC -DABORT_PROVIDED -DCLOCK_PROVIDED -DMALLOC_PROVIDED -DHAVE_FCNTL"
726 newlib_cflags="${newlib_cflags} -Os -DPREFER_SIZE_OVER_SPEED -ffunction-sections -fomit-frame-pointer -DREENTRANT_SYSCALL_PROVIDED"
727 if [ "${newlib_multithread}" = "no" ] ; then
728 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
731 newlib_cflags="${newlib_cflags} -D__DYNAMIC_REENT__"
736 default_newlib_io_long_long="yes"
742 default_newlib_io_long_long="yes"
743 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DABORT_PROVIDED"
747 # Pass -msdata=sdata so _impure_ptr goes in .sdata.
748 # We don't generate sda relocs however for upward compatibility.
749 # FIXME: This is necessary because the default multilib doesn't
750 # use --print-multi-lib.
751 newlib_cflags="${newlib_cflags} -msdata=sdata"
754 m68hc11-*-*|m6811-*-*|m68hc12-*-*|m6812-*-*)
755 newlib_cflags="${newlib_cflags} -DNO_EXEC -DABORT_PROVIDED -DSMALL_MEMORY -DMISSING_SYSCALL_NAMES"
758 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
765 default_newlib_io_long_long="yes"
766 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES -DSMALL_MEMORY -D_REENT_SMALL"
769 default_newlib_io_long_long="yes"
770 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
773 default_newlib_io_long_long="yes"
774 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
778 # We need every symbol 32-bit aligned, so the invalid
779 # construct with attribute ((alias ("_ctype_b+127"))) breaks.
780 newlib_cflags="${newlib_cflags} -DCOMPACT_CTYPE"
785 moxie-*-elf* | moxie-*-rtems*)
787 default_newlib_io_long_long="yes"
791 default_newlib_io_long_long="yes"
792 newlib_cflags="${newlib_cflags} -Os -DPREFER_SIZE_OVER_SPEED -DSMALL_MEMORY"
796 newlib_cflags="${newlib_cflags} -DHAVE_RENAME -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
804 powerpc*-*-eabialtivec*)
805 default_newlib_io_long_long="yes"
806 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
809 default_newlib_io_long_long="yes"
810 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
814 powerpc*-*-linux* | \
818 default_newlib_io_long_long="yes"
819 newlib_cflags="${newlib_cflags} -mrelocatable-lib -mno-eabi -mstrict-align -DMISSING_SYSCALL_NAMES"
822 newlib_cflags="${newlib_cflags} -DHAVE_OPENDIR -DHAVE_RENAME -DHAVE_FCNTL -D_NO_POSIX_SPAWN"
827 newlib_cflags="${newlib_cflags} -DSMALL_MEMORY -D_REENT_SMALL"
833 default_newlib_io_long_long="yes"
837 newlib_cflags="${newlib_cflags} -DSIGNAL_PROVIDED"
840 newlib_cflags="${newlib_cflags} -DREENTRANT_SYSCALLS_PROVIDED -DHAVE_BLKSIZE -DHAVE_FCNTL"
841 # This either belongs elsewhere or nowhere. But I need *something*,
842 # so for now it's here ...
845 newlib_cflags="${newlib_cflags} -DTARGET_PTR_SIZE=32" ;;
847 newlib_cflags="${newlib_cflags} -DTARGET_PTR_SIZE=64" ;;
852 newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED"
861 newlib_cflags="${newlib_cflags} -DCLOCK_PROVIDED -DHAVE_SYSTEM -DMISSING_SYSCALL_NAMES"
866 newlib_cflags="${newlib_cflags} -DSMALL_DTOA -DSMALL_MEMORY"
874 xtensa*-*-* | xtensa*-*)
881 newlib_cflags="${newlib_cflags} -DMISSING_SYSCALL_NAMES"
886 # Use defaults for certain settings if not specified by user
888 # Enable C99 format support in I/O routines if requested.
889 if [ "x${newlib_io_c99_formats}" = "x" ]; then
890 if [ ${default_newlib_io_c99_formats} = "yes" ]; then
891 newlib_io_c99_formats="yes";
895 # Enable long long support in I/O routines if requested.
896 if [ "x${newlib_io_long_long}" = "x" ]; then
897 if [ ${default_newlib_io_long_long} = "yes" ]; then
898 newlib_io_long_long="yes";
902 # Enable long double support in I/O routines if requested.
903 if [ "x${newlib_io_long_double}" = "x" ]; then
904 if [ ${default_newlib_io_long_double} = "yes" ]; then
905 newlib_io_long_double="yes";
909 # Enable printf positional argument support if requested.
910 if [ "x${newlib_io_pos_args}" = "x" ]; then
911 if [ ${default_newlib_io_pos_args} = "yes" ]; then
912 newlib_io_pos_args="yes";
916 # Disable atexit dynamic allocation if requested.
917 if [ "x${newlib_atexit_dynamic_alloc}" = "x" ]; then
918 if [ ${default_newlib_atexit_dynamic_alloc} = "yes" ]; then
919 newlib_atexit_dynamic_alloc="yes";
923 # Enable nano-malloc if requested.
924 if [ "x${newlib_nano_malloc}" = "x" ]; then
925 if [ ${default_newlib_nano_malloc} = "yes" ]; then
926 newlib_nano_malloc="yes";
930 # Enable _REENT_CHECK macro memory allocation verification.
931 if [ "x${newlib_reent_check_verify}" = "x" ]; then
932 if [ ${default_newlib_reent_check_verify} = "yes" ]; then
933 newlib_reent_check_verify="yes";
937 # Remove rpc headers if xdr_dir not specified
938 if [ "x${xdr_dir}" = "x" ]; then
939 noinclude="${noinclude} rpc/types.h rpc/xdr.h"
942 # Have init/finit if not explicitly specified otherwise
943 if [ "x${have_init_fini}" != "xno" ]; then
944 newlib_cflags="${newlib_cflags} -D_HAVE_INIT_FINI"
947 if test -z "${have_crt0}" && test -n "${sys_dir}"; then
951 # Target-specific defaults
952 case "${host_cpu}" in
954 if [[ -z ${newlib_global_stdio_streams} ]]; then
955 newlib_global_stdio_streams="yes";