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