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