0

I am trying to compile with make. I have source in two directories, src and altsrc. I want make to look in altsrc for source files first, and then in src. I want the objects to go into directory obs. The relevant parts of my Makefile looks like: VPATH=altsrc:src:obj

$(A_OUT): $(OBS)
    $(FORTRAN) -o $(A_OUT) $(OBS) $(LFLAGS)

obs/%.o: %.f
    $(FORTRAN) $(FFLAGS) $< -o $@

This Makefile actually compiles the code OK, but it has one really obnoxious side effect: It finds each source file (and there are alot) and copies them out of altsrc or src into the directory where I am running make. This is really annoying and leads to a bunch of confusion later on. I haven't found any documentation anywhere that says this should be an effect of the VPATH macro. Can anyone tell me how to solve this? Thanks.

bob.sacamento
  • 6,283
  • 10
  • 56
  • 115
  • You haven't given us much to go on. I suggest you try `make obs/foo.o`, look at the command Make actually executes, verify that it's what you expect, then *try the same command from the command line* and see if it commits the error (i.e. copies `foo.f` into the current directory). – Beta May 09 '12 at 20:52
  • OK. Thanks for the idea. "make obs/foo.o" does everything it is supposed to -- finds the right source, compiles it, puts foo.o in obs -- and *does not* copy foo.f. Is this a good thing or a bad thing? Thanks again. – bob.sacamento May 09 '12 at 20:59
  • It increases our knowledge of the problem, which is good. Now try `make` (which should copy lots of sources into the current directory) but save the output (pipe it to a file or something). Then pick one source that was copied, say `bar.f`, and sift through the output for `bar`. See if anything unexpected happened with `bar.anything`. – Beta May 09 '12 at 21:04
  • OK, this is weird. But I bet you knew I was going to say that. Anyway, here's an example of what is happening to pretty much all the files:`pgf90 -c td.f -o obs/td.o; co src/RCS/td.f,v td.f; src/RCS/td.g,v --> td.f` So, yes, I am using RCS for version control. But I make *no reference whatsoever* to ci, co, or what have you in the Makefile at all. And if I pull a file from another directory (like altsrc) where I don't have RCS set up yet, everything works fine, no copy. So now I guess the question is why does Make feel compelled to dive into RCS? And can I stop it? – bob.sacamento May 09 '12 at 21:16
  • OK, I found this at [link](http://babbage.cs.qc.edu/courses/cs701/Handouts/using_rcs.html): "Make has an implicit rule that tells it how to use co to get files from an RCS directory. For example, if there is no Makefile in the current directory and you invoke make with no target names on the command line, make will automatically try to get a Makefile using the co command. Also, if make needs a .c or .cc file to build a .o or executable file, it will automatically try to get it using co." Well, I fell dumb, but I have never heard this before. Anyone know how to stop it? The link doesn't say. – bob.sacamento May 09 '12 at 21:40

1 Answers1

0

The trouble is that Make is RCS-savvy, and will check to see if a source file (e.g. td.f) can and should be updated from RCS. Yes, Make knows how to use co. If the source file isn't in such an archive (such as the source files in altsrc), then Make shrugs and gets on with the work.

The quickest, dirtiest solution is to use make -r. This will disable the built-in rules, which should solve the problem nicely... unless you rely on the built-in rules elsewhere.

If that won't do, you can override that particular rule with a do-nothing rule of your own, or with a rule that actually updates the sources in place, or you can touch the sources so that Make won't consider them out of date, or put the RCS files someplace where Make can't see them, or maybe two or three other options.

Beta
  • 96,650
  • 16
  • 149
  • 150
  • Thanks. The "touch" option -- or something like it -- worked fine. "make -r" makes me a little nervous. I tried writing my own blank rules, `.f,v.o:` and `.f,v.f:` but they couldn't stop make from working its magic. If you know the correct way to do that, would appreciate seeing it. Thanks very much for your help! – bob.sacamento May 09 '12 at 22:04