BSD make question

Andrew Gallatin gallatin at cs.duke.edu
Thu Aug 7 11:42:36 PDT 2003


Using BSD make, how can I apply different rules based on different
directories while using only a single makefile?


Ie, the appended Makefile results in the following compilations:

    gcc -DLIB -c lib/foo.c -o lib/foo.o
    gcc -DLIB -c lib/bar.c -o lib/bar.o
    gcc -DMCP -c mcp/baz.c -o mcp/baz.o

Is it possible to do something similar with BSD make?

Drew


###################################
.SUFFIXES:
.SUFFIXES: .o .c

LIB=\
	lib/foo.c \
	lib/bar.c

MCP=\
	mcp/baz.c

all: $(LIB:.c=.o) $(MCP:.c=.o)

lib/%.o: lib/%.c
	gcc -DLIB -c $< -o $@

mcp/%.o: mcp/%.c
	gcc -DMCP -c $< -o $@

.PHONY: clean
clean:
	rm -f $(LIB:.c=.o) $(MCP:.c=.o)
###################################


More information about the freebsd-hackers mailing list