[comp.unix.questions] Make: Compiling source code from a different directory.

KSpagnol@massey.ac.nz (Ken Spagnolo) (11/27/89)

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.

-- 
Ken Spagnolo - Systems Programmer, Postmaster, Usenet Administrator, etc.
   Computer Centre, Massey University, Palmerston North, New Zealand
K.Spagnolo@massey.ac.nz  Phone: +64-63-69099 x8587  New Zealand = GMT+12

erikb@cs.vu.nl (Erik Baalbergen) (11/29/89)

In article <404@massey.ac.nz> K.Spagnolo@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.
->
->-- 
->Ken Spagnolo - Systems Programmer, Postmaster, Usenet Administrator, etc.
->   Computer Centre, Massey University, Palmerston North, New Zealand
->K.Spagnolo@massey.ac.nz  Phone: +64-63-69099 x8587  New Zealand = GMT+12

This meta-rule construct is not present in all makes, especially
older makes.  You may consider meta rules as a non-standard make feature.
Try to use VPATH (also non-standard), if present in the make on
your DECstation (see man page).  Otherwise you could write explicit
dependencies; a dull job, but resulting in a standard, "portable" makefile :-)

Erik Baalbargen
-- 
Erik H. Baalbergen				    <erikb@cs.vu.nl>
Vrije Universiteit / Dept. of Maths. & Comp. Sc.
De Boelelaan 1081
1081 HV Amsterdam / The Netherlands		tel. +31 20 548 8080

nick@bischeops.UUCP (Nick Bender) (11/30/89)

In article <404@massey.ac.nz>, KSpagnol@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.....

I use a slightly different approach. I keep source in one directory with
subdirectories for each object type eg:

# ls
HP/        Makefile   PYRAMID/   SUN/       main.c
#

I have a makefile, a source file, and three platform-specific directories.
The makefile contains the following:

# cat Makefile
SRCS = main.c
OBJS = main.o

hello: $(OBJS)
        $(CC) -o $@ $(CFLAGS) $(OBJS) $(LIBS)

$(SRCS):
        ln -s ../$@ .
#

Each subdir gets a munged version of this makefile which defines various
flags and things (see below) so that it looks like:

# ls SUN
Makefile
#

Then when I do make I get:

# cd SUN
# make
        ln -s ../main.c .
        cc -O -c main.c
        cc -o hello -O main.o 
# ls
Makefile   hello*     main.c@    main.o
#

Whenever editing takes place in the parent directory the make dependencies
still work through the link (at least on our Suns, HPs, and pyramid).

The platform specific makefiles are generated using a shell script and
pre-defined prepend and append makefile fragments.

-Nick

...!uunet!bischeops!nick		nick%bischeops@uunet.uu.net

brad@optilink.UUCP (Brad Yearwood) (11/30/89)

From article <4652@cogito.cs.vu.nl>, by erikb@cs.vu.nl (Erik Baalbergen):
# In article <404@massey.ac.nz> K.Spagnolo@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,
# ->...
# ->%.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.
# ->
# This meta-rule construct is not present in all makes, especially
# older makes.  You may consider meta rules as a non-standard make feature.
# Try to use VPATH (also non-standard), if present in the make on
# your DECstation (see man page).  Otherwise you could write explicit
# ...

GNU Make has VPATH, meta-rules, nice extensions to meta-rules, nice file
and pathname manipulation functions, and complete source code in case you
need something not already provided.  GNU Make, with a couple of local hacks
to provide selective VPATH expansion functions, is an essential item in our
project toolbox here.  I also find the documentation for GNU Make to be much
more readable and complete than other Make documentation.  If your project
moves to a different machine or site, having source code for Make relieves
you from reliance upon non-standard features which might be available on
one system but not on another.

McGrath and Stallman have a real winner in GNU Make.

Brad Yearwood
Optilink Corp.  {pyramid, tekbspa, pixar}!optilink!brad
Petaluma, California

merlyn@iwarp.intel.com (Randal Schwartz) (12/01/89)

In article <404@massey.ac.nz>, KSpagnol@massey (Ken Spagnolo) writes:
[...cannot get make to grok '%' templates...]
| 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.

Good old V7 make (probably what's on your DECstation), doesn't grok
'%' templates.  Get GNU Make (for free!) and use that instead.

Just another make hacker,
-- 
/== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\
| on contract to Intel's iWarp project, Hillsboro, Oregon, USA, Sol III  |
| merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn	         |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/

andre@targon.UUCP (andre) (12/07/89)

In article <404@massey.ac.nz> K.Spagnolo@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