siping@cathedral.cerc.wvu.wvnet.edu (Siping Liu) (08/31/90)
I'd like to run my make file in one directory (also generate the object files and executable file in this directory) but the source files are stored in another directory. I do not know how to specify this situation in my makefile. I tried to put the path with every file names in the makefile but it didn't work. The guy who works with me said make can not handle this. Can you help me to solve this or confirm that it is impossible? Thanks a lot. siping@cerc.wvu.wvnet.edu
nieters@copernicus.crd.ge.com (coolbean) (09/01/90)
Hi We do what you are talking about. There is a project/src directory and we make files in a project/debug directory that depend on files in ../src. Here's an example of the 'important' parts of the Makefile to achieve this: -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= To make a target in debug called "foo" which depends on foo.c in debug and bar.c in ../src # some definitions # standard message about linking LINK_MSG = @echo Linking $@ # normal link command. LIBS is conditionally defined for each a.out file. LINK_CMD = $(LINK.c) -o $@ $(LIBS) # a sample target FOO_SRCS = foo.c bar.c FOO_OBJS = $(FOO_SRCS:.c=.o) foo := LIBS = $(FOO_OBJS) foo : $(FOO_OBJS) $(LINK_MSG) $(LINK_CMD) # # how to make things in ../src %.c : ../src/%.c -@ln -s $< 2>/dev/null # vanilla object files (assume Unix) %.o : %.c $(COMPILE.c) -o $@ $< -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= We run this using Sun's make but I don't think there is anything particularly exotic to this example that won't work on "normal" make. --ed -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Ed Nieters INTERnet: nieters@crd.ge.com GE Corporate R&D UUCPnet: uunet!crd.ge.com!nieters Schenectady, NY 12301 BELLnet: (518) 387-5187
siping@cathedral.cerc.wvu.wvnet.edu (Siping Liu) (09/01/90)
Thanks to the rapid replies -- it didn't take much longer than turn around to ask my fellow workers here. ****************************************************************** From filipski@cs.Buffalo.EDU Fri Aug 31 12:53:16 1990 Return-Path: <filipski@cs.Buffalo.EDU> Received: from sybil.cs.Buffalo.EDU by cerc.wvu.wvnet.edu (4.1/SMI-4.0:RAL-041790) id AA03288; Fri, 31 Aug 90 12:53:14 EDT Received: by sybil.cs.Buffalo.EDU (4.0/1.01) id AA23193; Fri, 31 Aug 90 12:48:39 EDT Date: Fri, 31 Aug 90 12:48:39 EDT From: filipski@cs.Buffalo.EDU (Paul Filipski) Message-Id: <9008311648.AA23193@sybil.cs.Buffalo.EDU> To: siping Subject: Re: **** make file in another dir -- help !! **** Newsgroups: comp.unix.questions In-Reply-To: <730@babcock.cerc.wvu.wvnet.edu> Organization: State University of New York at Buffalo/Comp Sci Cc: Status: R In article <730@babcock.cerc.wvu.wvnet.edu> you write: >I'd like to run my make file in one directory (also generate the object >files and executable file in this directory) but the source files are >stored in another directory. I do not know how to specify this situation >in my makefile. I tried to put the path with every file names in the >makefile but it didn't work. The guy who works with me said make can >not handle this. After extensive searching, I've yet to find anything that make can't handle. It's extremely robust. Some things get awfully tricky, though. >Can you help me to solve this or confirm that it is impossible? Depending on your version of make, you should have the '%'-matching-mechanism (for lack of a better name). This would allow you to write a new default rule in the following way. Assume that you want objects and executables in the ~/obj directory, and C sources are in ~/src. Also, you're Makefile would be in ~/obj. %.o : ~/src/%.c cc -c -o $@ $(CFLAGS) $< Which make interprets (roughly) as : If I want foo.o and I've got ~/src/foo.c then I can cc ~/src/foo.c and put my output here! You'll probably want to check the man page for more information. >Thanks a lot. You're welcome. >siping@cerc.wvu.wvnet.edu Enjoy, Paul -- Paul Filipski State University of New York at Buffalo filipski@cs.buffalo.edu Dept of Computer Science UUCP: ...!{watmath,boulder,decvax,rutgers}!sunybcs!filipski M-52 M-x yow From preston@src.umd.edu Fri Aug 31 13:47:32 1990 Return-Path: <preston@src.umd.edu> Received: from src9.src.umd.edu by cerc.wvu.wvnet.edu (4.1/SMI-4.0:RAL-041790) id AA03526; Fri, 31 Aug 90 13:47:30 EDT Received: from gauss.src.umd.edu by src9.src.umd.edu (4.1/UMDENG-0.1/02-20-90) id AA08730; Fri, 31 Aug 90 13:42:51 EDT Message-Id: <9008311742.AA08730@src9.src.umd.edu> Date: Fri, 31 Aug 90 13:42:30 EDT From: preston@src.umd.edu (James Preston) To: siping@cerc.wvu.wvnet.edu Status: R makefile in another dir Set the variable VPATH in the makefile to the path to the .c files i.e VPATH = ../../other_dir/sources:.
merlyn@iwarp.intel.com (Randal Schwartz) (09/01/90)
In article <NIETERS.90Aug31132201@copernicus.crd.ge.com>, nieters@copernicus (coolbean) writes: [example using templates deleted] | We run this using Sun's make but I don't think there is anything particularly | exotic to this example that won't work on "normal" make. Normal least-common-denominator V7 Make had nothing of the sort (just default extensions). Your solution is therefore most unportable, but if it works, it works great. (Sys V Make has that too, I think, but Sys V is not Unix. Sigh.) Luckily, GNU Make has similar facilities, so there is a way to implement your solution for just a little effort and time on nearly any box. Just another old-time Unix hacker, -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/