universe@755: #!/bin/sh universe@755: universe@755: dir="$1" universe@755: universe@755: if [ -z "$dir" ]; then universe@755: echo "Usage: $0 " universe@755: exit 1 universe@755: fi universe@755: universe@755: if [ -d "$dir" ]; then universe@755: : universe@755: else universe@755: echo "'$dir' is not a directory" universe@755: exit 1 universe@755: fi universe@755: universe@755: if [ -z "$CC" ]; then universe@755: for cc in gcc clang ; do universe@755: if command -v "$cc" > /dev/null ; then universe@755: CC="$cc" universe@755: break universe@755: fi universe@755: done universe@755: fi universe@755: universe@755: if [ -z "$CC" ]; then universe@755: echo "No suitable compiler found to generate make rules" universe@755: exit 1 universe@755: fi universe@755: universe@755: if command -v sed > /dev/null ; then universe@755: : universe@755: else universe@755: echo "You need the 'sed' program for this script to work." universe@755: exit 1 universe@755: fi universe@755: universe@755: cd "$dir" universe@755: universe@755: mv Makefile Makefile.old universe@755: sed '/FORCE:/q' Makefile.old > Makefile universe@755: echo >> Makefile universe@755: for file in `ls *.c` ; do universe@755: "$CC" -MT "\$(build_dir)/${file/.c/\$(OBJ_EXT)}" -MM $CFLAGS "$file" universe@755: printf '\t@echo "Compiling $<"\n' universe@755: printf '\t$(CC) -o $@ $(CFLAGS) -c $<\n\n' universe@755: done >> Makefile universe@755: rm Makefile.old