would like to use make -j 3

I have a simple Makefile that works fine with serial make (make) but not when I try to add some parallelling (make -j 3). Is there a way to make it work? Below are the particulars. This is on Centos 6.7 i386. Thanks!
The Makefile:
ICEPATH = /usr/bin ICEINCLUDE = -I. -I/usr/include CC = g++ CLDFLAGS = -g -pthread CFLAGS = -ffast-math -Wall -O2 $(CLDFLAGS) OBJS = IIFServer.o Factory.o libiif.a: $(OBJS) ar rv [email protected] $(OBJS) ranlib [email protected] IIFServer.o: IIFServer.ice $(ICEPATH)/slice2cpp IIFServer.ice $(CC) $(ICEINCLUDE) $(CFLAGS) -c IIFServer.cpp -o [email protected] Factory.o: Factory.ice $(ICEPATH)/slice2cpp Factory.ice $(CC) $(ICEINCLUDE) $(CFLAGS) -c Factory.cpp -o [email protected] clean: touch x.o rm -f *.o libiif.a IIFServer.cpp IIFServer.h Factory.cpp Factory.h
Runs fine normally:
# make /usr/bin/slice2cpp IIFServer.ice g++ -I. -I/usr/include -ffast-math -Wall -O2 -g -pthread -c IIFServer.cpp -o IIFServer.o /usr/bin/slice2cpp Factory.ice g++ -I. -I/usr/include -ffast-math -Wall -O2 -g -pthread -c Factory.cpp -o Factory.o ar rv libiif.a IIFServer.o Factory.o ar: creating libiif.a a - IIFServer.o a - Factory.o ranlib libiif.a #
But gets all confused with -j 3:
# make -j 3 /usr/bin/slice2cpp IIFServer.ice /usr/bin/slice2cpp Factory.ice g++ -I. -I/usr/include -ffast-math -Wall -O2 -g -pthread -c Factory.cpp -o Factory.o In file included from ./Factory.h:38, from Factory.cpp:21: ./IIFServer.h:21:1: error: unterminated #ifndef g++ -I. -I/usr/include -ffast-math -Wall -O2 -g -pthread -c IIFServer.cpp -o IIFServer.o In file included from Factory.cpp:21: ./Factory.h:53: error: expected unqualified-id before 'namespace' Factory.cpp:1750: error: expected '}' at end of input In file included from ./Factory.h:38, from Factory.cpp:21: ./IIFServer.h:6894: error: expected unqualified-id at end of input ./IIFServer.h:6894: error: expected '}' at end of input ./IIFServer.h:6894: error: expected '}' at end of input make: *** [Factory.o] Error 1 make: *** Waiting for unfinished jobs.... #
Answers
Hi,
Your Makefile dependency graph is incomplete, make needs a complete dependency graph in order to figure what targets can be build in parallel.
slice2cpp has a --depend option that outputs Makefile style dependencies and is handy to get the Slice file dependencies.
Here is a sample Makefile that works with parallel make:
I should mention that this sample doesn't handle C++ source dependencies, you should look into that if you want your builds to work correctly.