
set (YAPOS_HEADERS
        getw.h

        iopreds.h
        yapio.h
        YapEncoding.h
        )

set (YAPOS_SOURCES
absf.c
  alias.c
  assets.c
  charsio.c
  chartypes.c
  console.c
  files.c
  fmem.c
 # fmemopen.c
 #android/fmemopen.c
  #  android/fopencookie.c
   #   android/open_memstream.c
  format.c
  iopreds.c
  mem.c
  #open_memstream.c
  pipes.c
  readline.c
  random.c
  readterm.c
  readutil.c
  sig.c
  sockets.c
  streams.c
  sysbits.c
  time.c
  writeterm.c
  ypsocks.c
  ypstdio.c
 cwalk/cwalk.c
 ${READLINE_SOURCES}
 )

  include_directories (../H ../include ../OPTYap . cwalk  ${GMP_INCLUDE_DIR} )

  
OPTION(WITH_READLINE " Enable GNU Readline" ON)


if (WITH_READLINE)



find_library( LIBREADLINE readline )

if (LIBREADLINE)
  set( LIBREADLINE ${LIBREADLINE} PARENT_SCOPE)

    set (HAVE_LIBREADLINE On)
    set (USE_READLINE On)
    list(APPEND YAPOS_SOURCES readline.c)
    
    check_include_files( "stdio.h;readline/readline.h" HAVE_READLINE_READLINE_H )
check_include_files( "stdio.h;readline/history.h"  HAVE_READLINE_HISTORY_H )
check_function_exists( add_history  HAVE_ADD_HISTORY )
check_function_exists( rl_begin_undo_group HAVE_RL_BEGIN_UNDO_GROUP)
check_function_exists( rl_clear_pending_input HAVE_RL_CLEAR_PENDING_INPUT)
check_function_exists( rl_discard_argument HAVE_RL_DISCARD_ARGUMENT)
check_symbol_exists( rl_filename_completion_function  stdio.h;readline/readline.h HAVE_RL_FILENAME_COMPLETION_FUNCTION)
check_function_exists( rl_free_line_state HAVE_RL_FREE_LINE_STATE )
check_function_exists( rl_insert_close  HAVE_RL_INSERT_CLOSE )
check_function_exists( rl_reset_after_signal  HAVE_RL_RESET_AFTER_SIGNAL )
check_function_exists( rl_set_keyboard_input_timeout  HAVE_RL_SET_KEYBOARD_INPUT_TIMEOUT )
check_function_exists( rl_set_prompt  HAVE_RL_SET_PROMPT)
check_function_exists( rl_set_signals  HAVE_RL_SET_SIGNALS)
check_symbol_exists( rl_catch_signals "stdio.h;readline/readline.h"   HAVE_DECL_RL_CATCH_SIGNALS )
check_type_size( rl_completion_func_t RL_COMPLETION_FUNC_T    )
check_symbol_exists( rl_done stdio.h;readline/readline.h  HAVE_DECL_RL_DONE )
CHECK_TYPE_SIZE( rl_hook_func_t  RL_HOOK_FUNC_T  )
check_symbol_exists( rl_event_hook stdio.h;readline/readline.h HAVE_DECL_RL_EVENT_HOOK )
check_symbol_exists( rl_readline_state stdio.h;readline/readline.h HAVE_DECL_RL_READLINE_STATE )
check_function_exists( add_history HAVE_ADD_HISTORY)
check_function_exists( remove_history HAVE_REMOVE_HISTORY)
check_function_exists( using_history HAVE_USING_HISTORY)

    endif()

endif()


SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 )

set (POSITION_INDEPENDENT_CODE TRUE)

  add_component (libYAPOs
    ${YAPOS_SOURCES}
    )



  set (YAPOS_PL_SOURCES
      edio.yap
      chartypes.yap
      yio.yap
  )

configure_file(${CMAKE_SOURCE_DIR}/os/YapIOConfig.h.cmake ${CMAKE_BINARY_DIR}/YapIOConfig.h)

add_to_dir(YAPOS PL_SOURCES ${YAP_INSTALL_DATADIR}/os)

   install (FILES ${YAPOS_PL_SOURCES}
    DESTINATION ${YAP_INSTALL_DATADIR}/Osu	 )

add_feature_info(ReadLine "WITH_READLINE" "GNU Readline library available at ${LIBREADLINE}")

