euglug.org

[Eug-lug] How to program GNU “make”?

작성자

카테고리:



Bob MillerMon Dec 27 13:47:19 PST 2004

Allen Brown wrote:

> I'm having trouble expressing a rule using GNU make.
> This is what I want:
> 
> file1_t file2_t:		$(@:_t=_t.o) $(@:_t=.o)
> 			rules to compile and test file*_t
> 
> The problem is that $(@) type constructs don't seem to work in
> the dependency list.  For instance
> 
> file:				$(@).o
> 
> causes make to try to create ".o" from ".c".  So evidently
> in the dependency list $(@) is a null string.
> 
> What is the right way to express this?

Take a look at Pattern Rules in the info pages.  Your example
should look like this.

	%_t:	%_t.o %.o
		@echo linking $^ into $@
		$(CC) -o $@ $^
	
	default: file1_t file2_t ;

-- 
Bob Miller                              K<bob>
kbobsoft software consulting
http://kbobsoft.com                     kbob at jogger-egg.com