1. Since make has builtin suffix rules, the Makefile could be simplified to:
CXX=g++
hello: main.o factorial.o hello.o
clean:
rm -rf *o hello
2. Shameless plug: he didn't mention redo [1], which is simpler than make and more reliable.
The comparable redo scripts to the Makefile would be:
cat <<EOF > @all.do
redo hello
EOF
cat <<EOF > hello.do
o='main.o factorial.o hello.o'
redo-ifchange $o
g++ $o -o $3
EOF
cat <<EOF > default.o.do
redo-ifchange $2.cpp
g++ -c $1 -o $3
EOF
cat <<EOF > @clean.do
rm -rf *o hello
EOF
[Edit: Note that these are heredoc examples showing how to create the do scripts.]
These are just shell scripts and can be extended as much as necesary.
For instance, one can create a dependency on the compiler flags with these changes:
cat <<EOF | install -m 0755 /dev/stdin cc
#!/bin/sh
g++ -c "\$@"
EOF
# sed -i 's/^\(redo-ifchange.\+\)/\1 cc/' *.do
# sed -i 's}g++ -c}./cc}' *.do
sed calls could be combined; separated here for readablility.
[1] https://github.com/gyepisam/redux
These are just shell scripts and can be extended as much as necesary. For instance, one can create a dependency on the compiler flags with these changes:
sed calls could be combined; separated here for readablility.[1] https://github.com/gyepisam/redux