Make: Compiling source code from a different directory.

andre andre at targon.UUCP
Thu Dec 7 19:05:24 AEST 1989


In article <404 at massey.ac.nz> K.Spagnolo at massey.ac.nz (Ken Spagnolo) writes:
]We have several machines that all need to run the same code.  Rather
]than keep the source on each and worry about keeping them up to date,
]I set up the makefile on our Sun 386i to access the source kept on
]our Pyramid.  This wasn't too difficult.  I have an obj directory that
]contains the makefile, and on the same level, a src directory that is
]a symbolic link to the other machine.  So the makefile defines SRCDIR
]as ../src and uses the following rule to find everything:
]
]%.o: $(SRCDIR)/%.c
]       $(CC) $(CFLAGS) -c $<
]
]It works fine on the Sun, but when I tried it on our new DECstation 3100,
]it didn't work.  Does anyone know of another way to achieve this?  No
]matter what I try, I get "Don't know how to make target".  Thanx a lot.

I have no direct solution, but you if you can live with make getting the
sources into the destination directory you can always try (works on
all makes I saw until now)

OBJ=a.o b.o c.o
SRC=$(OBJ:.o=.c)
SRCDIR=../src

$(SRC): $(SRCDIR)/$$@
	cp $? .

You need the $$@ to postpone expansion until runtime not readtime.
PS. The $$@ seems to be added later, things like $$(@:.o=.c) or $$*.c
wil not work.

	hope this helps,

-- 
The mail|    AAA         DDDD  It's not the kill, but the thrill of the chase.
demon...|   AA AAvv   vvDD  DD        Ketchup is a vegetable.
hits!.@&|  AAAAAAAvv vvDD  DD                    {nixbur|nixtor}!adalen.via
--more--| AAA   AAAvvvDDDDDD    Andre van Dalen, uunet!hp4nl!targon!andre



More information about the Comp.unix.questions mailing list