#
# Function to build a loadable module from a class source and header file 
#
function brat-module { 
    if [ $# -lt 1 ] ; then 
	echo "root-module need exactly one argument"
	return 1
    fi 
    name=`basename $1 .cxx`
    name=`basename $name .h` 
    g++ `root-config --cflags` -c -g -Wall $name.cxx -o $name.o 
    if [ $? -gt 0 ] ; then 
	echo "Compilation failed"
	return 1
    fi
    rootcint -f ${name}Dict.cxx -c $name.h 
    if [ $? -gt 0 ] ; then 
	echo "Dictionary generation failed"
        return 1	
    fi
    g++ `root-config --cflags` -c -g -Wall ${name}Dict.cxx -o ${name}Dict.o 
    if [ $? -gt 0 ] ; then 
	echo "Compilation of dictionary failed"
	return 1
    fi
    g++ -shared -Wl,-soname,$name.so -o $name.so ${name}Dict.o $name.o 
    if [ $? -gt 0 ] ; then 
	echo "Linking failed"
	return 1
    fi
    rm -f ${name}Dict.{h,cxx,o} ${name}.o 
}
    

#
# Function to build a single file into a program 
#
function root-compile {
    if [ $# -lt 1 ] ; then 
	echo "root-compile need exactly one argument"
	return 1
    fi
    lpath=`root-config --libs | sed -e 's,-[^L][^[:space:]]*,,g' -e 's,-L,,'`
    name=`basename $1 .cxx` 
    g++ -Wall -g $name.cxx -o $name `root-config --cflags --glibs` \
	-Wl,-rpath,$lpath
}

	

