(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:

Makefile:

all:
    $(MAKE) -f ./make_system.mk
    $(MAKE) -f ./make_crc.mk

make_system.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

all: $(EXES)

%.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) *~

make_crc.mk:

CC     = gcc
CFLAGS = -g
LFLAGS =
HDR    = crcmode.h
SRC    = crcmodel.c crctest.c
OBJ    = crcmodel.o crctest.o
EXE    = crctest

all: $(EXE)

%.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).

Answers


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 $@

Need Your Help

Initilize some test data with YAML on Play Framework

java playframework yaml

I have creating a learning application with play framework and i want to use test data which is loaded from yaml. But my data's are just null in mysql, for example

How to get QComboBox Item data

python qt pyqt qcombobox

Instead of using .addItem("Item Name", "My Data") to populate the QComboBox

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.