#!/bin/sh
# -*- shell-script -*- 	
# 
# The following files must be built:
#
#   - bin/$group.group-all-programs
#   - bin/$group.group-all-modules
#   - bin/%.program-all-flags
#   - bin/%.program-ld-flags
#   - bin/baby_%.d
#

. sh/verbose.sh 

group="$1"

if [ -z "$group" ]
then
    echo "***"
    exit 1
fi

#
# editables
#
echo 
echo '#'
echo '# The settings in the following lines can be changed'
echo '#'
echo 
echo "gcc=$gcc"
echo '# the compiler'
echo 
echo "CXXFLAGS=$R_CXXFLAGS \`gtk-config --cflags\`"
echo '# the default compiling flags'
echo 
echo "LDFLAGS=$LDFLAGS"
echo '# the default linking flags'
echo 
echo 'install_dir=/usr'
echo '# the installation prefix.  Can be set to your home directory' 
echo
echo 'skip_home=t'
echo '# set to empty when installing in home directory.'
echo

#echo export gcc CXXFLAGS LDFLAGS
#echo 
echo '#'
echo '# The remaining lines should not be edited'
echo '#'
echo 
echo all:
echo 

#
# Per program
#

for program in `cat bin/$group.group-all-programs` 
do
  echo >&4 Program:  $program
  echo "all:  bin/baby_$program"
  echo "bin/baby_$program:  `cat bin/baby_$program.d | tr '
' ' ' `"
  echo '	'\$\(gcc\) \$\(CXXFLAGS\) -idirafter bin bin/$program.program.cc \
       `cat bin/$program.program-all-flags` `cat bin/$program.program-ld-flags` \
       \$\(LDFLAGS\) -o bin/baby_$program 
done

#
# Per module 
#
for module in `cat bin/$group.group-all-modules`
do
  echo >&4 Module: $module
  if [ -r macro/$module.sh ]
  then
      echo bin/$module.config.hh:  macro/$module.sh
#      echo '	gcc=$(gcc)'
#      echo '	export gcc'
      echo '	gcc=$(gcc) ; export gcc ; . macro/'$module'.sh>$@'
  fi
done

#
# Phonies
#

echo 'clean:'
echo '	sh/clean'

echo 'install:'
echo '	groups='$group' install_dir=$(install_dir) skip_home=$(skip_home) sh/install'

