#!/bin/bash
#This script is used to re-create the Makefile.am using ccbuild
# and then run allt the necessary autotools. Configure.in should
# be edited separately.
#
#  This file is part of ccbuild.

#  ccbuild is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.

#  ccbuild is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.

#  You should have received a copy of the GNU General Public License
#  along with ccbuild.  If not, see <http://www.gnu.org/licenses/>.

if [ "x$1" = "xclean" ]; then
    echo Cleaning
    rm -rf CMakeFiles
    exit
fi
## Generate Makefile.am from ccbuild
PSOURCE=src/ccbuild.cc
PNAME=`basename "${PSOURCE}" .cc`
echo "Updating MD5SUMS file"
which ccbuild && (ccbuild md5 --recursive-include . "${PSOURCE}" > MD5SUMS)
SOURCES=`egrep .cc$ MD5SUMS | sed  -r 's/^[a-z0-9]+  //; s/ /\\ /' | tr '\n' ' '`
VERSION=`egrep -o 'VERSION=.+"[0-9.]+' src/ccResolutions |cut -d '"' -f 2`

#Write CMakeLists.txt
cat > CMakeLists.txt <<EOF
cmake_minimum_required (VERSION 2.6)
project (ccbuild)
add_definitions(-DVERSION="${VERSION}")
link_libraries(gomp bobcat gnutls)
add_definitions(-fopenmp)
add_executable(ccbuild ${SOURCES})
install(TARGETS ccbuild DESTINATION bin)
install(FILES doc/ccbuild/ccbuild.1 DESTINATION share/man/man1)
EOF


