. ../config/system
. ../config/site

def_vfork=undef
def_vprintf=undef
def_dirent=undef
def_atexit=undef
def_syms_underl=undef
def_random=undef
def_include_unistd_h=undef
def_sysconf=undef
def_getdtablesize=undef
def_bsd_signals=undef
def_posix_signals=undef
def_align_8byte=undef
def_can_dump=undef
def_fchmod_broken=undef
def_termio=undef
def_use_alloca=undef
def_include_alloca_h=undef
def_pragma_alloca=undef
def_coff=undef
def_ecoff=undef
def_xcoff=undef
def_elf=undef
def_macho=undef
def_use_ld=undef
def_use_rld=undef
def_use_shl=undef
def_pchb=undef
def_max_stack_size=undef
def_init_objects=undef
def_want_proto=undef
def_no_proto=undef
def_generational_gc=undef
def_use_ld_xflag=undef
def_cachectl_h=undef
def_syms_begin_with=undef
def_ansi_cpp=undef
def_can_load_obj=undef

if [ _$vfork = _yes ];            then def_vfork=define;            fi
if [ _$vprintf = _yes ];          then def_vprintf=define;          fi
if [ _$dirent = _yes ];           then def_dirent=define;           fi
if [ _$atexit = _yes ];           then def_atexit=define;           fi
if [ _$syms_with_underline = _yes ];
				  then def_syms_underl=define;      fi
if [ _$random = _yes ];           then def_random=define;           fi
if [ _$include_unistd_h = _yes ]; then def_include_unistd_h=define; fi
if [ _$sysconf = _yes ];          then def_sysconf=define;          fi
if [ _$getdtablesize = _yes ];    then def_getdtablesize=define;    fi
if [ _$align_8byte = _yes ];      then def_align_8byte=define;      fi
if [ _$can_dump = _yes ];         then def_can_dump=define;         fi
if [ _$fchmod_broken = _yes ];    then def_fchmod_broken=define;    fi
if [ _$termio = _yes ];           then def_termio=define;           fi
if [ _$use_alloca = _yes ];       then def_use_alloca=define;       fi
if [ _$include_alloca_h = _yes ]; then def_include_alloca_h=define; fi
if [ _$pragma_alloca = _yes ];    then def_pragma_alloca=define;    fi
if [ "_$pointer_constant_high_bits" != _ ];
				  then def_pchb=define;             fi
if [ "_$max_stack_size" != _ ];   then def_max_stack_size=define;   fi
if [ _$init_objects = _yes ];     then def_init_objects=define;     fi
if [ _$generational_gc = _yes ];  then def_generational_gc=define;  fi
if [ _$use_ld_xflag = _yes ];     then def_use_ld_xflag=define;     fi
if [ _$cachectl_h != _ ];         then def_cachectl_h=define;       fi
if [ _$ansi_cpp =  _yes ];        then def_ansi_cpp=define;         fi
if [ _$syms_begin_with != _ ];    then
    def_syms_begin_with=define
    syms_begin_char=\'$syms_begin_with\'
fi
if [ _$index != _yes ];           then
    def_index="#define index strchr"
fi
if [ _$bstring != _yes ]; then
    def_bcopy="#define bcopy(from,to,len) memcpy(to,from,len)"
    def_bzero="#define bzero(p,len)       memset(p,0,len)"
    def_bcmp="#define bcmp memcmp"
fi

case _$reliable_signals in
_bsd)    def_bsd_signals=define;;
_posix)  def_posix_signals=define;;
esac

case _$prototypes in
_yes)    def_want_proto=define;;
_no)     def_no_proto=define;;
esac

case _$aout_format in
_coff)   def_coff=define;;
_ecoff)  def_ecoff=define;;
_xcoff)  def_xcoff=define;;
_elf)    def_elf=define;;
_macho)  def_macho=define;;
esac

case _$load_obj in
_ld)     def_use_ld=define;      def_can_load_obj=define;;
_rld)    def_use_rld=define;     def_can_load_obj=define;;
_shl)    def_use_shl=define;     def_can_load_obj=define;;
_)       ;;
*)       echo Invalid value for symbol load_obj: $load_obj; exit 1;;
esac

if [ _$dont_init_if_name = _ ]; then
    def_dont_init="#undef DONT_INIT"
else
    def_dont_init="#define DONT_INIT \"$dont_init_if_name\""
fi

if [ _$load_obj = _shl ]; then
    load_libraries="$lib_dir/libutil.sl ${load_libraries}"
else
    load_libraries="$lib_dir/libutil.a ${load_libraries--lc}"
fi

echo Building config.h...
cat <<EOT >config.h
/* This file was produced by the Makefile in this directory.
 * If you want to change the value of a constant, edit ../config/system
 * or ../config/site and run make again.
 */

#ifndef CONFIG_H
#define CONFIG_H

#$def_vfork            VFORK
#$def_vprintf          VPRINTF
#$def_dirent           DIRENT
#$def_random           RANDOM
#$def_include_unistd_h INCLUDE_UNISTD_H
#$def_sysconf          SYSCONF
#$def_getdtablesize    GETDTABLESIZE
#$def_bsd_signals      BSD_SIGNALS
#$def_posix_signals    POSIX_SIGNALS
#$def_align_8byte      ALIGN_8BYTE
#$def_coff             COFF
#$def_ecoff            ECOFF
#$def_xcoff            XCOFF
#$def_elf              ELF
#$def_macho            MACH_O
#$def_use_ld_xflag     USE_XFLAG
#$def_can_load_obj     CAN_LOAD_OBJ
#$def_use_ld           USE_LD
#$def_use_rld          USE_RLD
#$def_use_shl          USE_SHL
#  define              LOAD_LIBRARIES    "${load_libraries}"
#$def_cachectl_h       CACHECTL_H        $cachectl_h
#  $def_atexit         ATEXIT
#$def_syms_begin_with  SYMS_BEGIN_WITH   $syms_begin_char
#$def_can_dump         CAN_DUMP
#  define              SEGMENT_SIZE      ${segment_size-unused}
#  define              FILE_TEXT_START   ${file_text_start-unused}
#  define              MEM_TEXT_START    ${mem_text_start-unused}
#  define              TEXT_LENGTH_ADJ   ${text_length_adj-unused}
#  define              TEXT_START        ${ecoff_text_start-unused}
#  define              DATA_START        ${ecoff_data_start-unused}
#  define              COFF_PAGESIZE     ${coff_pagesize-unused}
#  $def_fchmod_broken  FCHMOD_BROKEN
#$def_termio           TERMIO
#$def_use_alloca       USE_ALLOCA
#$def_include_alloca_h INCLUDE_ALLOCA_H
#$def_pragma_alloca    PRAGMA_ALLOCA
#define                TIME_H            $time_h
#$def_pchb             POINTER_CONSTANT_HIGH_BITS  $pointer_constant_high_bits
#$def_max_stack_size   MAX_STACK_SIZE    $max_stack_size
#$def_generational_gc  GENERATIONAL_GC
$def_index
$def_bcopy
$def_bzero
$def_bcmp

#$def_init_objects     INIT_OBJECTS
$def_dont_init
#define                SCM_DIR           "$scheme_dir"
#define                LIB_DIR           "$lib_dir"
#define                HEAP_SIZE         $default_heap_size

#$def_want_proto       WANT_PROTOTYPES
#$def_no_proto         NO_PROTOTYPES
#$def_ansi_cpp         ANSI_CPP

#endif
EOT
