[comp.unix.shell] relatively simple make question

davidk@dsinet (David Karr) (05/16/91)

I have a Make question.  This should be simple, but it is giving me pain.

I have a macro definition called "SRCS".  It is a list of C shell source files.
Every file in the list has ".csh" appended to it.  For every file in the "SRCS"
list, I want to create a hard link with the ".csh" removed.  It would be
better if it would only create the links that don't exist or are "out of date",
but that isn't critical.  It should use the Bourne shell.  This is what I
have so far:

SRC = gork.csh flork.csh

$(SRC:.csh=): $(SRC)
	@echo ln $@.csh $@

It does an "echo" just to see if it would work.  It doesn't.  It does the
right thing for the first member of "SRC", but it doesn't do any more entries
in the "SRC" list.

Please enlighten me.
-- 
Digital Systems International, Inc.	David Karr
7730 177th Pl NE			dsinet!davidk
Redmond, WA   98073-0903
(206) 881-7544 ext. 547

rhartman@thestepchild.sgi.com (Robert Hartman) (05/17/91)

In article <621@elroy> davidk@dsinet (David Karr) writes:
>I have a Make question.  This should be simple, but it is giving me pain.
>
>I have a macro definition called "SRCS".  It is a list of C shell source files.
> ... For every file in the "SRCS"
>list, I want to create a hard link with the ".csh" removed.

It would be better to define a suffix rule for this.  The following makefile
does what you want:

	SCRIPTS = gork flork

	all: $(SCRIPTS)

	.SUFFIXES: .csh
	.csh:
		@echo ln $@ $<

The standard man page isn't too clear about how you go about defining
your own suffix rules (which they refer to as "inference" rules).  What
you must do to add a new suffix rule is to add the new suffixes to the
suffixes list by showing them as dependencies for the .SUFFIXES
target.  Then you must supply a target definition corresponding to the
concatenation of dependency and target suffixes.  The rule in this
target is applied to dependency files with an indicated suffix to
produce a target with another indicated suffix.

In this case, ".csh" is the dependency suffix, and the target suffix is
null.  Thus, the target name for the suffix rule is ".csh."  If I wanted
to produce a target with the suffix "foo," I'd write a rule like this:

	SCRIPTS = gorkfoo florkfoo

	all: $(SCRIPTS)

	.SUFFIXES: .csh foo
	.cshfoo:
        	@echo ln $@ $<


Order is important in the suffixes list.  But you can read the man page to
find out how to tweak the order of the suffixes list, now that you've seen
the basic idea.

-r

tif@doorstop.austin.ibm.com (Paul Chamberlain) (05/17/91)

In article <621@elroy> davidk@dsinet (David Karr) writes:
>SRC = gork.csh flork.csh
>
>$(SRC:.csh=): $(SRC)
>	@echo ln $@.csh $@

I agree that using a .SUFFIX is a good way to do it, but,
without redefining the problem, the easiest way to make
this work is just to add this after "SRC =":
	all: $(SRC:.csh=)

If you want to know another way to do it, get mmv and then do:
	mmv -l '*.csh' =1
But that has some broad assumptions.

Paul Chamberlain | I do NOT speak for IBM.          IBM VNET: PAULCC AT AUSTIN
512/838-9748     | ...!cs.utexas.edu!ibmchs!auschs!doorstop.austin.ibm.com!tif