Make: Compiling source code from a different directory.

Nick Bender nick at bischeops.UUCP
Thu Nov 30 03:22:55 AEST 1989


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

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 at uunet.uu.net



More information about the Comp.unix.questions mailing list