#!/bin/sh

#some files dont have any #ifdef HUB|LEAF
#but they do have a header included which DOES
#this can potentially cause major problems with sizeof(struct) etc...
#temporary solution: MAKE CLEAN 

other=""

if [ $1 = "hub" ]; then
 other="leaf"
fi

if [ $1 = "leaf" ]; then
 other="hub"
fi


if test ! -f stamp.$1 && test -f stamp.$other
then
  flist="`find src -name \*.c`"
#  cfiles="`grep -l \"def [H|L][U|E][B|A]\" $flist`"
  echo "[*] Cleaning up files for $1 build"
#  for s in $cfiles 
  for s in $flist
  do
    bleh="`echo $s | cut -d / -f 2`";
    if [ $bleh = "mod" ]; then
      mod="`echo $s | cut -d / -f 3`";
      os="`echo src/mod/$mod | sed s/\\\.mod/\\\.o/g`";
      rm -f $os
    else
      os="`echo $s | sed s/\\\.c/\\\.o/g`";
      if test -f $os
      then
        if test "`file $os | grep ELF`"
        then
  	  rm -f $os
        else
          if test "`file $os | grep object`"
          then
    	    rm -f $os
          fi
        fi
      fi
    fi
  done
fi
rm -f stamp.*
touch stamp.$1
