#!/bin/sh

i=0
list=""

mkdir -p t
cd t

echo "int main (void) {" > main.c

while [ $i -le 2000 ]; do
   if [ ! -f "file_$i.c" ]; then
      echo "generating file_$i.c"
      echo "void function_$i (void) { printf (\"a\n\"); };" > file_$i.c
   fi
   echo "  function_$i ();" >> main.c
   list="$list file_$i.c"
   i=`expr $i + 1`
done

echo "}" >> main.c

(echo "SRC=$list"
echo 'OBJ=${SRC:.c=.o}'
echo 'main: ${OBJ} main.o'
echo '	gcc -o main ${OBJ} main.o'
echo '%.o: %.c'
echo '	gcc -g -c $<'
echo 'clean:'
echo '	${RM} *.o'
echo 'dist_clean:'
echo '	${RM} *.o ${SRC} main main.c Makefile'
) > Makefile

make
