#!/bin/sh

# scc - Simple usage of gcc
#
# David Edwards <davidbtdt@gmail.com> 1/16/2010

if [ $# = 0 ]; then
  echo ""
  echo "Simple usage of gcc for compiling one or more C source files into a program."
  echo ""
  echo "Usage: ${0##/*/} fname1[.c] [fname2[.c] ... fnameN[.c]]"
  echo ""
  echo " Where <fname1[.c]> is a C source file name."
  echo "       The source file must have a '.c' extension, but it does not"
  echo "       have to be given on the command line."
  echo ""
  echo " The output program name will be <fname1>."
  echo ""
  echo ""
  echo " <fname2[.c] ... fnameN[.c]> are optional additional C source"
  echo " modules to be compiled into fname1."
  echo ""
  echo " The option first argument <-ggdb> includes additional debugging"
  echo " information in fname1"
  echo ""
  echo "Example:"
  echo ""
  echo " The command:  scc -ggdb cat /tmp/fsck.ext2 input output.c"
  echo ""
  echo " Will execute: gcc -ggdb -o cat cat.c /tmp/fsck.ext2.c input.c output.c"
  echo ""
  exit 1
fi


if [ $1 = -ggdb ]; then
  GGDB="-ggdb"
  shift
fi

pname=${1%.c}

for name in $@
do
    base=${name%.c}         # Get the file name witout any extension
    Clst="$Clst $base.c"
done

echo "Compiling: gcc $GGDB -o $pname $Clst"

gcc $GGDB -o $pname $Clst