views:

111

answers:

2

We are using recursive make in our project. We also use a commercial embedded compiler (diab) with a FlexLM license.

We are currently adding license-borrowing as a dependency on the top-level targets in each directory.

Like this:

.PHONY: target
target: borrow_compiler $(TARGETLIB)
    $(RETURN_COMPILER)

.PHONY : borrow_compiler
borrow_compiler:
    @$(BORROW_COMPILER) 300

where BORROW_COMPILER and RETURN_COMPILER are scripts that acquires the license.

Our problem is that it takes a long time to build after a small change due to the communication with the license server for each recursive sub-directory.

Is there a better way to do this?

A: 

How about instead of doing it in the makefile, write a make program wrapper that first borrow the license, then calls make with arguments, and after make returns returns the license? You could check in the makefile that some special environment variable is set if you want to enforce that the make wrapper is used.

hlovdal
But I want to run make without borrowing the license, and then only borrow the license if a c/c++-file needs to be compiled. The license should furthermore not be returned until all c/c++-files have been compiled.Hmm.. Maybe it's possible to detect if make is called recursively? Then only the top makefile should do the borrowing.
Pär Bohrarper
You could also consider not running make recursively, see "Recursive Make Considered Harmful", http://miller.emu.id.au/pmiller/books/rmch/.
hlovdal
+1  A: 

The solution was to look at MAKELEVEL. Now the license is only borrowed in the top level make. This is included by all levels of makefiles:

ifeq ($(MAKELEVEL),0)
    BORROW_COMPILER = python $(relativeToolPath)scripts/borrowCompilerLicence.py
    RETURN_COMPILER = python $(relativeToolPath)scripts/returnCompilerLicence.py
else
    # true does nothing
    BORROW_COMPILER = true
    RETURN_COMPILER = 
endif
Pär Bohrarper