#!/bin/sh
# Helper tool to fix/create Makefiles
# Copyright (C) 2005,2006,2006 Juergen Sawinski
# 
# This program 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 2 of the License, or
# (at your option) any later version.
# 
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

usage() {
    cat <<EOF
[]/cf/cf [options]
Copyright (C) 2005,2006,2006 Juergen Sawinski
Licensed und GPL v2 or any later version.

Create or fix Makefile structure.
This file must be called with the relative path to the file
so that the top directory can be derived.

Options (no options is equal to --fix):
    -h,--help                 This.
    -c,--create               Create a default Makefile
    -f,--fix                  Fix makefile (including subdirectories)

"create" specific options:
    -none yet-
EOF
}

method=fix

while [ $# -gt 0 ]; do
    case "$1" in
    -h|--help)
	usage
	exit
	;;
    -c|--create)
	method=create
	shift
	;;
    -f|--fix)
	method=fix
	shift
	;;
    esac
done

# get "topdir"
topdir=`dirname $0` ; topdir=`dirname $topdir`

#check if topdir is relativ
case "$topdir" in
    /*)
	echo "Must be called with a relative path."
	echo "Exiting."
	exit -1
	;;
esac

method_fix() {
    :
}

method_create() {
    (
	echo "topdir  = $topdir"
	echo "subdirs ="
	echo

	# program,archive,library

	echo "include \$(topdir)/cf/Rules.pre"
	echo 

	# variable additions (DEFS,CFLAGS,INCLUDES etc.)

	echo "all: subdirs"
	echo

	# extra make targets

	echo "include \$(topdir)/cf/Rules"
	echo 

	#

	echo "include \$(topdir)/cf/Rules.post"
    ) > Makefile
}

case "$method" in
    fix)    method_fix . ;;
    create) method_create ;;
esac
