I have been trying to write a Makefile to build the modules for a library in parallel. What I have works for a single threaded make, and for parallel builds of the full library, but parallel makes (make -j2) fail to update changed modules in the library (though the source IS compiled to an object file). Any suggestions as to what I am doing wrong in the following example?
Code:
# Small Makefile to demonstrate a difference between normal and
# parallel makes. Needs 2 .c files, create them using
# echo "int a() { return 'a'; }" >a.c
# echo "int b() { return 'b'; }" >b.c
# Build the library using "make", then observe that
# touch a.c; make # Correctly updates the library
# touch a.c; make -j2 # Fails to update the library
LIB= libtest.a
OBJ= a.o b.o
$(LIB): $(LIB)($(OBJ))
ar cru $(LIB) $(.OODATE)
ranlib $(LIB)
rm $(.OODATE)