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