(GNU) Make: How does one set up a basic system?
I would like to try to establish a very small system of Makefiles. I have the following set up, but something is not quite right (this has been pieced together from reading a few SO posts about the topic, though somewhat project-specific, and some websites. I must not be catching something fundamental in having a "Makefile" call sub-makefiles.
This is even simpler than having the main Makefile call files in different subdirectories. Here are the following files I have prepared:
all: $(MAKE) -f ./make_system.mk $(MAKE) -f ./make_crc.mk
G = -g ## debug option CC = gcc ## compiler SRCS = source.c sink.c gateway.c EXES = source sink gateway OBJS = source.o sink.o gateway.o CFLG = LFLG = LIB = #-lsocket -lnsl -lpthread
%.o: %.c %.h $(CC) -c $G $(CFLG) $<
source: source.o $(CC) -o source source.o $(LIB) $(LFLG)
sink: sink.o $(CC) -o sink sink.o $(LIB) $(LFLG)
gateway: gateway.o $(CC) -o gateway gateway.o $(LIB) $(LFLG)
clean: /bin/rm -f core *.o $(EXES) *~
CC = gcc CFLAGS = -g LFLAGS = HDR = crcmode.h SRC = crcmodel.c crctest.c OBJ = crcmodel.o crctest.o EXE = crctest
%.o: %.c %.h $(CC) -c $(CLFAGS) $<
$(EXE): $(OBJ) $(CC) $(LFLAGS) $(OBJ) -o $(EXE)
clean: /bin/rm -f *.o *~ core $(EXE)
How would I set up Makefile to call the smaller sub-makefiles (of type *.mk)? This is a basic but important first step towards working with larger scale makefile systems (there is the manual to consult, though I do not think it has explicit basic examples). If someone who has done this could show me a small Makefile vignette, this would be greatly appreciated (again, this makefile system can exist within the same local directory).
Note: The individual makefiles "make_system" and "make_crc" work fine when they are themselves named "Makefile", but I want to try to call them as separate sub-makefiles with one single overall Makefile.
ADDENDUM (to solution below): Once I implemented Carl's solution shown below, I realized that you need to always include some form of "make clean" or at least enter at in the command line before calling your Makefile. Otherwise, you see the appropriate output "nothing to be done". This was something I knew before, but neglected to do this time around (easy check: just look at your directory and you will see you have executables in the environment/directory).
I you want to "forward" the target, you'll need to do it explicitly. Something like this example should work (though I can't test easily right now, sorry):
default: all %: $(MAKE) -f ./make_system.mk $@ $(MAKE) -f ./make_crc.mk $@