module Rscons

  on_windows = RUBY_PLATFORM =~ /mingw|msys|cygwin/
  pic_flags = on_windows ? [] : %w[-fPIC]

  # Default Rscons construction variables.
  DEFAULT_CONSTRUCTION_VARIABLES = {
    "AR" => "ar",
    "ARCMD" => %w[${AR} ${ARFLAGS} ${_TARGET} ${_SOURCES}],
    "ARFLAGS" => %w[rcs],
    "AS" => "${CC}",
    "ASCMD" => %w[${AS} -c -o ${_TARGET} ${ASDEPGEN} ${INCPREFIX}${ASPPPATH} ${ASPPFLAGS} ${ASFLAGS} ${_SOURCES}],
    "ASCMD:direct" => %w[${AS} -o ${_TARGET} ${ASDEPGEN} ${INCPREFIX}${ASPPPATH} ${ASPPFLAGS} ${ASFLAGS} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
    "ASDEPGEN" => %w[-MMD -MF ${_DEPFILE}],
    "ASFLAGS" => [],
    "ASPPFLAGS" => "${CPPFLAGS}",
    "ASPPPATH" => "${CPPPATH}",
    "ASSUFFIX" => %w[.S],
    "CC" => "gcc",
    "CCCMD" => %w[${CC} -c -o ${_TARGET} ${CCDEPGEN} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${CFLAGS} ${CCFLAGS} ${_SOURCES}],
    "CCCMD:direct" => %w[${CC} -o ${_TARGET} ${CCDEPGEN} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${CFLAGS} ${CCFLAGS} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
    "CCDEPGEN" => %w[-MMD -MF ${_DEPFILE}],
    "CCFLAGS" => [],
    "CFLAGS" => [],
    "CPPDEFINES" => [],
    "CPPDEFPREFIX" => "-D",
    "CPPFLAGS" => %w[${CPPDEFPREFIX}${CPPDEFINES}],
    "CPPPATH" => [],
    "CPP_CMD" => %w[${_PREPROCESS_CC} -E ${_PREPROCESS_DEPGEN} -o ${_TARGET} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${_SOURCES}],
    "CSUFFIX" => %w[.c],
    "CXX" => "g++",
    "CXXCMD" => %w[${CXX} -c -o ${_TARGET} ${CXXDEPGEN} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${CXXFLAGS} ${CCFLAGS} ${_SOURCES}],
    "CXXCMD:direct" => %w[${CXX} -o ${_TARGET} ${CXXDEPGEN} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${CXXFLAGS} ${CCFLAGS} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
    "CXXDEPGEN" => %w[-MMD -MF ${_DEPFILE}],
    "CXXFLAGS" => [],
    "CXXSUFFIX" => %w[.cc .cpp .cxx .C],
    "DC" => "gdc",
    "DCCMD" => %w[${DC} -c -o ${_TARGET} ${DDEPGEN} ${INCPREFIX}${D_IMPORT_PATH} ${DFLAGS} ${_SOURCES}],
    "DCCMD:direct" => %w[${DC} -o ${_TARGET} ${DDEPGEN} ${INCPREFIX}${D_IMPORT_PATH} ${DFLAGS} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
    "DDEPGEN" => %w[-MMD -MF ${_DEPFILE}],
    "DEPFILESUFFIX" => ".mf",
    "DFLAGS" => [],
    "DISASM_CMD" => %w[${OBJDUMP} ${DISASM_FLAGS} ${_SOURCES}],
    "DISASM_FLAGS" => %w[--disassemble --source],
    "DSUFFIX" => %w[.d],
    "D_IMPORT_PATH" => [],
    "INCPREFIX" => "-I",
    "LD" => nil,
    "LDCMD" => %w[${LD} -o ${_TARGET} ${LDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
    "LDFLAGS" => [],
    "LEX" => "flex",
    "LEXSUFFIX" => %w[.l .ll],
    "LEX_CMD" => %w[${LEX} ${LEX_FLAGS} -o ${_TARGET} ${_SOURCES}],
    "LEX_FLAGS" => [],
    "LIBDIRPREFIX" => "-L",
    "LIBLINKPREFIX" => "-l",
    "LIBPATH" => [],
    "LIBS" => [],
    "LIBSUFFIX" => ".a",
    "OBJDUMP" => "objdump",
    "OBJSUFFIX" => %w[.o],
    "PROGSUFFIX" => on_windows ? ".exe" : "",
    "SHCC" => "${CC}",
    "SHCCCMD" => %w[${SHCC} -c -o ${_TARGET} ${CCDEPGEN} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${SHCFLAGS} ${SHCCFLAGS} ${_SOURCES}],
    "SHCCCMD:direct" => %w[${SHCC} -o ${_TARGET} ${CCDEPGEN} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${SHCFLAGS} ${SHCCFLAGS} ${SHLDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
    "SHCCFLAGS" => %w[${CCFLAGS}] + pic_flags,
    "SHCFLAGS" => %w[${CFLAGS}],
    "SHCXX" => "${CXX}",
    "SHCXXCMD" => %w[${SHCXX} -c -o ${_TARGET} ${CXXDEPGEN} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${SHCXXFLAGS} ${SHCCFLAGS} ${_SOURCES}],
    "SHCXXCMD:direct" => %w[${SHCXX} -o ${_TARGET} ${CXXDEPGEN} ${INCPREFIX}${CPPPATH} ${CPPFLAGS} ${SHCXXFLAGS} ${SHCCFLAGS} ${SHLDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
    "SHCXXFLAGS" => %w[${CXXFLAGS}],
    "SHDC" => "gdc",
    "SHDCCMD" => %w[${SHDC} -c -o ${_TARGET} ${INCPREFIX}${D_IMPORT_PATH} ${SHDFLAGS} ${_SOURCES}],
    "SHDCCMD:direct" => %w[${SHDC} -o ${_TARGET} ${INCPREFIX}${D_IMPORT_PATH} ${SHDFLAGS} ${SHLDFLAGS} ${_SOURCES} ${LIBDIRPREFIX}${LIBPATH} ${LIBLINKPREFIX}${LIBS}],
    "SHDFLAGS" => %w[${DFLAGS}] + pic_flags,
    "SHLD" => nil,
    "SHLDCMD" => %w[${SHLD} -o ${_TARGET} ${SHLDFLAGS} ${_SOURCES} ${SHLIBDIRPREFIX}${LIBPATH} ${SHLIBLINKPREFIX}${LIBS}],
    "SHLDFLAGS" => %w[${LDFLAGS} -shared],
    "SHLIBDIRPREFIX" => "-L",
    "SHLIBLINKPREFIX" => "-l",
    "SHLIBPREFIX" => on_windows ? "" : "lib",
    "SHLIBSUFFIX" => on_windows ? ".dll" : ".so",
    "YACC" => "bison",
    "YACCSUFFIX" => %w[.y .yy],
    "YACC_CMD" => %w[${YACC} ${YACC_FLAGS} -o ${_TARGET} ${_SOURCES}],
    "YACC_FLAGS" => %w[-d],
  }

end
