BSD make question

Ruslan Ermilov ru at freebsd.org
Thu Aug 7 11:49:11 PDT 2003


On Thu, Aug 07, 2003 at 02:42:30PM -0400, Andrew Gallatin wrote:
> 
> Using BSD make, how can I apply different rules based on different
> directories while using only a single makefile?
> 
There's a .CURDIR variable that can be used to conditionalize
parts of a 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?
> 
It just works "as is" with bmake.  What's your problem, Drew?  ;-)

$ make -n
cc -O -pipe -march=pentiumpro -c lib/foo.c
cc -O -pipe -march=pentiumpro -c lib/bar.c
cc -O -pipe -march=pentiumpro -c mcp/baz.c

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

-- 
Ruslan Ermilov		Sysadmin and DBA,
ru at sunbay.com		Sunbay Software Ltd,
ru at FreeBSD.org		FreeBSD committer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20030807/9358aa06/attachment.bin


More information about the freebsd-hackers mailing list