#!/bin/sh

. config/options $1

setup_toolchain host

cd $PKG_BUILD

./configure --no-qt-gui

make

mkdir -p $ROOT/$TOOLCHAIN/bin
  cp -P bin/cmake $ROOT/$TOOLCHAIN/bin
  cp -P bin/cpack $ROOT/$TOOLCHAIN/bin
  cp -P bin/ctest $ROOT/$TOOLCHAIN/bin

mkdir -p $ROOT/$TOOLCHAIN/etc

  cat >$ROOT/$TOOLCHAIN/etc/cmake-$TARGET_NAME.conf <<EOF
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
SET(CMAKE_C_COMPILER   $TARGET_CC)
SET(CMAKE_CXX_COMPILER $TARGET_CXX)

# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH  $SYSROOT_PREFIX)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

EOF

  cat >$ROOT/$TOOLCHAIN/etc/cmake-$HOST_NAME.conf <<EOF
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)

# specify the host compiler
SET(CMAKE_C_COMPILER   $HOST_CC)
SET(CMAKE_CXX_COMPILER $HOST_CXX)

# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH  $ROOT/$TOOLCHAIN)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)

# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)

EOF
