johns4ta johns4ta - 2 months ago 8
C Question

Creating Makefile that compiles multiple C files for use in Minix

I am trying to create a Makefile that compiles multiple C files for use in Minix. How would I change the Makefile so that it compiles multiple files at the same time? Below is the current state of my Makefile.

CFLAGS = -D_POSIX_SOURCE
LDFLAGS =
CC = cc
LD = cc

PROG = test

OBJS = test.o

$(PROG): $(OBJS)
$(LD) $(LDFLAGS) $(OBJS) -o $(PROG)

clean:
rm -rf $(PROG) $(OBJS)


I thought I could just list the other programs after PROG and OBJS such as

PROG = test test2

OBJS = test.o test2.o


but that didn't work. Any ideas? Thanks in advance.

Answer

Split it up this way:

PROG1 = test 
PROG2 = test2
OBJ1 = test.o
OBJ2 = test2.o


$(PROG1): $(OBJ1) 
          $(LD) $(LDFLAGS) $(OBJ1) -o $(PROG1)
$(PROG2): $(OBJ2) 
          $(LD) $(LDFLAGS) $(OBJ2) -o $(PROG2)

etc

Comments