Using NMAKE batch-mode with tree of directories


  • I'd like to utilise NMAKE batch-mode feature and use /MP (Build with Multiple Processes) option to speed up a library building

    Source files of a library are scattered across directories. There is a single makefile with list of .obj files specified using paths relative to root directory of library source tree:

    OBJ = na\a.obj nb\b.obj nc\c.obj
    CC = cl.exe
    CFLAGS = /MP
    .cpp.obj: $(CC)
        $(CFLAGS) /c $*.cpp /Fo$@ 

    This way, all .obj files are generated in sub-directories corresponding to .cpp source files. So, they are linked this way:

    LINK = link.exe
    my.lib: $(OBJ)
        $(LINK) /lib /out:$(LIBNAME) $(OBJ) 

    Now, I'd like switch to batch-mode

        $(CC) $(CFLAGS) -c $< 

    Compilation works, but .obj files are generated in root directory of the source tree and linker can not find them, because OBJ list uses relative paths to directories.

    On StackOverflow, there is similar question related to my problem, Change older makefile system to take advantage of parallel compiles. So, I followed the ideas and tried to specify batch rule per directory according to the Search Paths in Rules page:

        $(CC) $(CFLAGS) -c $< 

    but without luck. The object files are still generated in the root folder, next to makefile.

    How to get the NMAKE batch-mode working with single makefile and tree of directories?

    FYI, I asked similar question on StackOverflow, but haven't received any answers so far

    Mateusz Loskot

    • Edited by mloskot Friday, August 24, 2012 11:11 AM Link
    Friday, August 24, 2012 11:07 AM

All replies

  • I think the parameter of $(LIBNAME) doesn't work.

    Tuesday, August 28, 2012 9:58 AM
  • Why not try to utilize MsBuild utility? This utility can build native Visual Studio solution and project files including all customs steps if any. 


    Tuesday, August 28, 2012 11:58 AM
  • Adolf,

    I think, the $(LIBNAME) parameter is not really relevant here. I could have removed it and it would not change my question.

    Mateusz Loskot

    Wednesday, August 29, 2012 10:38 AM
  • Sergey,

    It would mean changing the build toolset and configuration for my project. Unfortunately, it's not feasible option at this moment. I have to stick to NMAKE makefiles.

    Mateusz Loskot

    Wednesday, August 29, 2012 10:40 AM