[comp.unix.questions] Help with Makefile

wrd3156@fedeva.UUCP (Bill Daniels) (08/11/88)

I am having trouble creating a reasonable Makefile for a system with sources
and executables in separate directories.  The current Makefile resides in the 
bin directory, easily recognizing the executable dependencies. A preprocessor
required by UNIFY seems to need to be run from the source directory
seemingly forcing the ".o" dependency to chdir to the src directory before
executing (ucc for those of you familiar with UNIFY).  Here's a cut of the
current entry:

DEFS=../def
DIR1=../src
INC=/usr/include
UNINC=/unify/include
LOCINC=../src/include
UCC=/unify/bin/ucc -c -R -O
ULD=/unify/bin/uld

init_db: $(DIR1)/init_db.o
	/bin/sh $(ULD) init_db \
	    $(DIR1)/init_db.o

$(DIR1)/init_db.o: $(DIR1)/init_db.c $(DEFS)/file.h \
		   $(LOCINC)/cr.h $(LOCINC)/input.h
	cd $(DIR1); $(UCC) init_db.c


This works ok!  My problems have appeared with the decision to install the
sources in sccs.  The augmented make does all the wonderfully proper things
about "get -p"ing if necessary but leaves ugly ".c"s around after the 
compilation has completed.  Moving the Makefile into the src directory
leaves my executables in the source directory, which we would like to avoid.
HELP!!!
-- 
bill daniels
federal express, memphis, tn
{hplabs!csun,gatech!emcard,mit-eddie!premise}!fedeva!wrd3156

rick@vsi1.UUCP (Rick Schneider) (08/11/88)

From article <370@fedeva.UUCP>, by wrd3156@fedeva.UUCP (Bill Daniels):
> 
> ... but leaves ugly ".c"s around after the 
> compilation has completed.

< init_db: $(DIR1)/init_db.o
<  	/bin/sh $(ULD) init_db \
<  	    $(DIR1)/init_db.o
<  
< $(DIR1)/init_db.o: $(DIR1)/init_db.c $(DEFS)/file.h \
<  		   $(LOCINC)/cr.h $(LOCINC)/input.h
<  	cd $(DIR1); $(UCC) init_db.c
        rm -f init_db.c
        ^^^^^^^^^^^^^^^

or add a new directive:

clean:	rm -f $(DIR1)/*.c

and when you want to remove the source files type:

make clean



 

micky@cunixc.cc.columbia.edu (Micky Liu) (08/02/89)

I am trying to build a Makefile for sources that have to be built
for different architectures.  So let's say I have my sources at
the root and I want to place the objects in their subdirectories
under the root like:

/src

/src/vax

/src/sun3

/src/sun4

But I only want to keep one Makefile in the my /src directory.
I have already made a method to determine the architecture and
then it invokes itself with the proper flags.  The problem is
that I cannot seem to get the implicit rules to work anymore.

Let's say I'm on the vax, and I type make.  It figures out that
I'm on the vax and then IT does something like:

make CCFLAGS=-DVAX

but when it actually gets to a target it says that it doesn't know
how to make vax/hello.o, or omething like that.  I ended up making
explicit rules for each source file, but would really like to be
able to use the implicit rules...

Any clues, or other methods of maintaining a single source tree for
different architectures?

Thanx!

Micky Liu

  arpa: micky@cunixc.cc.columbia.edu
  uucp: ...!rutgers!columbia!cunixc!micky
bitnet: malua@cuvmc

Kemp@DOCKMASTER.NCSC.MIL (08/04/89)

micky@cunixc.cc.columbia.edu (Micky Liu) writes:
 > I am trying to build a Makefile for sources that have to be built
 > for different architectures.  So let's say I have my sources at
 > the root and I want to place the objects in their subdirectories
 > under the root like:
 >
 > /src
 > /src/vax
 > /src/sun3
 > /src/sun4
 > [ ... ]
 > Let's say I'm on the vax, and I type make.  It figures out that
 > I'm on the vax and then IT does something like:
 >
 > make CCFLAGS=-DVAX
 >

  I recently got a GREAT suggestion from a Sun employee on how to do
just that, which I posted to sun-spots.  Basically you define variables
(oops - make calls them macros) for each architecture and then select
the macro you need using a nested macro.  For example:

  CFLAGS= $(CFLAGS$(TARGET_ARCH))
  CFLAGS-vax= -Dvax
  CFLAGS-sun3= -f68881

The macro $(TARGET_ARCH) is replaced by a string such as "-sun3", which
is then used as the name of the macro you are using for the particular
architecture.  There is no need for make to invoke itself recursively to
achieve this substitution.

      Dave Kemp <Kemp@dockmaster.ncsc.mil>

 Quote:  "Pave the Bay"   --- bumper sticker on a J-24 at Hampton Yacht Club

rbj@dsys.ncsl.nist.gov (Root Boy Jim) (09/01/89)

? From: Micky Liu <micky@cunixc.cc.columbia.edu>

? I am trying to build a Makefile for sources that have to be built
? for different architectures.  So let's say I have my sources at
? the root and I want to place the objects in their subdirectories
? under the root like:

? /src

? /src/vax

? /src/sun3

? /src/sun4

? But I only want to keep one Makefile in the my /src directory.
? I have already made a method to determine the architecture and
? then it invokes itself with the proper flags.  The problem is
? that I cannot seem to get the implicit rules to work anymore.

? Let's say I'm on the vax, and I type make.  It figures out that
? I'm on the vax and then IT does something like:

? make CCFLAGS=-DVAX

? but when it actually gets to a target it says that it doesn't know
? how to make vax/hello.o, or omething like that.  I ended up making
? explicit rules for each source file, but would really like to be
? able to use the implicit rules...

? Any clues, or other methods of maintaining a single source tree for
? different architectures?

This is just a WAG, I haven't tried it. Code you Makefile as if you were
in the subdirectory. Then add the following entry at the beginning:

vax sun3 sun4 whatever:
	(cd $@; make -f ../Makefile all)

Where the target `all' builds your program. Just type `make vax' to
build the program for the vax. The targets for clean and install are
more complex.

Another way to do it is by using the `arch' command.

all clean install:
	(cd `arch`; make -f ../Makefile ARCH=-D`arch | tr a-z A-Z` real$@)

Of course, there is also the VPATH variable, which may or may not work.

? Thanx!

? Micky Liu

?   arpa: micky@cunixc.cc.columbia.edu
?   uucp: ...!rutgers!columbia!cunixc!micky
? bitnet: malua@cuvmc

	Root Boy Jim and
	the GNU Bohemians

guy@auspex.auspex.com (Guy Harris) (09/06/89)

>Another way to do it is by using the `arch' command.

If you have it - it's in SunOS, but it's not in vanilla 4.xBSD or S5.

vrm@cerc.wvu.wvnet.edu (Vasile R. Montan) (09/07/89)

From: Micky Liu <micky@cunixc.cc.columbia.edu>
> 
> I am trying to build a Makefile for sources that have to be built
> for different architectures.  So let's say I have my sources at
> the root and I want to place the objects in their subdirectories
> under the root like:
> /src
> /src/vax
> /src/sun3
> /src/sun4
> 
> But I only want to keep one Makefile in the my /src directory.
> I have already made a method to determine the architecture and
> then it invokes itself with the proper flags.  The problem is
> that I cannot seem to get the implicit rules to work anymore.
> 
   On the SUN machines, you can use a pattern matching rule:

$(DEST)/%.o: %.c
        $(COMPILE.c)  -o $@ $<

where DEST is somehow set to the appropriate directory (ex. sun4) and
COMPILE.c is as defined in /usr/include/make/default.mk.

The rule to create your program would be:

$(PROGRAM):     $(OBJS:%=$(DEST)/%) $(LIBS)

   However, this does not work on any of the versions of make on the
other platforms we are working on.

PS:
Micky,
  I would be interested in any email feedback that you may have
gotten from your query.  Also your method for determining what
architecture you are compiling on would be interesting.  I tried to
send you email, but it bounced back.

-- Vasile

bph@buengc.BU.EDU (Blair P. Houghton) (09/07/89)

In article <2414@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes:
>>Another way to do it is by using the `arch' command.
>
>If you have it - it's in SunOS, but it's not in vanilla 4.xBSD or S5.

Try this:

	#! /bin/sh
	#
	#  Now it's arch nobody has...
	#

	while read arrrrg
	do
	    exec $* arrrrg
	done

Well, it worked fine as xargs...


:-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) :-) 

				--Blair
				  ":-)"