2 Replies - 309 Views - Last Post: 18 April 2012 - 07:50 AM Rate Topic: -----

#1 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 763
  • Joined: 06-January 09

Recursively calling "make" in a Makefile

Posted 17 April 2012 - 04:39 PM

Hi all,
I have a Makefile with the following targets:

all: test1 test2
test1:
cd myDir; make myLibrary;
${LINK} ${OTHERFILES} libMyLibrary
test2:
cd myDir; make myLibrary;
${LINK} ${OTHERFILES} libMyLibrary

Where two targets depend on a particular library being built, and each call to make this library when called separately. The problem occurs when "all" is called; the same library is linked together twice, when it already exists from being built by the first target.

I understand why this is happening; it's not considered up-to-date. But, does anyone know of any Makefile tricks that would allow it to be built only when it hasn't been built before? The way things go right now is technically fine; things would just look a bit cleaner if I could get rid of the extraneous build step.

Thanks,
Zel2008

Is This A Good Question/Topic? 0
  • +

Replies To: Recursively calling "make" in a Makefile

#2 GWatt  Icon User is offline

  • member icon

Reputation: 262
  • View blog
  • Posts: 3,054
  • Joined: 01-December 05

Re: Recursively calling "make" in a Makefile

Posted 17 April 2012 - 05:01 PM

Since make will treat files as targets/dependencies the easiest way to get make to not perform every step every time is to incrementally build and link your source. If your makefile is already configured to do that then maybe considering posting more of your makefile. Please use code tags if you post more of your makefile.
Was This Post Helpful? 0
  • +
  • -

#3 Zel2008  Icon User is offline

  • D.I.C Addict

Reputation: 14
  • View blog
  • Posts: 763
  • Joined: 06-January 09

Re: Recursively calling "make" in a Makefile

Posted 18 April 2012 - 07:50 AM

Thanks GWatt,
I can't post more of the Makefile, but I can post an example that does essentially the same thing. Another way I was considering creating the Makefile was like this (and thanks for the reminder about code tags, thought I put them in before and must have forgotten):

all: test1 test2

exe/myLibrary:
    cd myLibraryDir; make myLibrary

test1: ${OTHERFILES} exe/myLibrary
    ${LINK} ${OTHERFILES} exe/myLibrary

test2: ${OTHERFILES} exe/myLibrary
    ${LINK} ${OTHERFILES} exe/myLibrary



This setup works, where there's an explicit rule to create the library, and the library is used as a dependency. But, I have a lot of libraries and targets to handle, so having a separate target for every library gets a bit tedious and tough to maintain.

Is there maybe a smoother way to incrementally build that I'm not aware of?

Thanks,
Zel2008

This post has been edited by Zel2008: 18 April 2012 - 07:51 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1