Thu, 23 Nov 2023 23:33:09 +0100
add update-rules script
universe@755 | 1 | #!/bin/sh |
universe@755 | 2 | |
universe@755 | 3 | dir="$1" |
universe@755 | 4 | |
universe@755 | 5 | if [ -z "$dir" ]; then |
universe@755 | 6 | echo "Usage: $0 <src_dir>" |
universe@755 | 7 | exit 1 |
universe@755 | 8 | fi |
universe@755 | 9 | |
universe@755 | 10 | if [ -d "$dir" ]; then |
universe@755 | 11 | : |
universe@755 | 12 | else |
universe@755 | 13 | echo "'$dir' is not a directory" |
universe@755 | 14 | exit 1 |
universe@755 | 15 | fi |
universe@755 | 16 | |
universe@755 | 17 | if [ -z "$CC" ]; then |
universe@755 | 18 | for cc in gcc clang ; do |
universe@755 | 19 | if command -v "$cc" > /dev/null ; then |
universe@755 | 20 | CC="$cc" |
universe@755 | 21 | break |
universe@755 | 22 | fi |
universe@755 | 23 | done |
universe@755 | 24 | fi |
universe@755 | 25 | |
universe@755 | 26 | if [ -z "$CC" ]; then |
universe@755 | 27 | echo "No suitable compiler found to generate make rules" |
universe@755 | 28 | exit 1 |
universe@755 | 29 | fi |
universe@755 | 30 | |
universe@755 | 31 | if command -v sed > /dev/null ; then |
universe@755 | 32 | : |
universe@755 | 33 | else |
universe@755 | 34 | echo "You need the 'sed' program for this script to work." |
universe@755 | 35 | exit 1 |
universe@755 | 36 | fi |
universe@755 | 37 | |
universe@755 | 38 | cd "$dir" |
universe@755 | 39 | |
universe@755 | 40 | mv Makefile Makefile.old |
universe@755 | 41 | sed '/FORCE:/q' Makefile.old > Makefile |
universe@755 | 42 | echo >> Makefile |
universe@755 | 43 | for file in `ls *.c` ; do |
universe@755 | 44 | "$CC" -MT "\$(build_dir)/${file/.c/\$(OBJ_EXT)}" -MM $CFLAGS "$file" |
universe@755 | 45 | printf '\t@echo "Compiling $<"\n' |
universe@755 | 46 | printf '\t$(CC) -o $@ $(CFLAGS) -c $<\n\n' |
universe@755 | 47 | done >> Makefile |
universe@755 | 48 | rm Makefile.old |