dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: makefile commands to create directories, CentOS7 , GNU Make 3.82

  1. #1
    Join Date
    May 2009
    Location
    Boston
    Posts
    364

    makefile commands to create directories, CentOS7 , GNU Make 3.82

    Hello,

    My makefiles are set up to generate an environment specific build directory based on the local configuration and some values passed to make. It generally looks like,
    Code:
    # compilers, may be passed to make
    CC++ = g++
    FCOMP = gfortran
    
    # version of program, may be passed to make
    ver = debug
    
    # manually assign linux distro
    OS=CentOS-7.7
    
    # collect name information
    ARCH := $(shell uname -m)
    KERN := $(shell uname -r | cut -d. -f 1,2)
    
    # find g++ compiler version
    CMP := $(shell g++ --version | cut -d ' ' -f 3 | sed q)
    
    # create names for build directory name
    CNAME := gpp-$(CMP)
    FNAME := gfortran-$(CMP)
    
    # archdir is executed as part of all and will create the necessary
    # version specific directories if they do not exist
    archdir: ${BDIR}
    
    # create name for the build directory
    BDIR := bld_$(OS)_$(KERN).$(ARCH)_$(CNAME)_$(FNAME)_$(ver)
    
    # mkdir if the directories do not exist
    ${BDIR}:
        @mkdir -p ${BDIR}
    
    # archdir is part of all
    all archdir program_name
    When make is called with all, all runs archdir, archdir runs BDIR and the build directory gets created if it does not exist. This has generally worked well.

    Recently I wanted to create some additional directories and so attempted to implement the same method.

    I added a new directory name and instruction to make the directory. That instruction was added to archdir so that the resulting code looks like,
    Code:
    # archdir is executed as part of all and will create the necessary
    # version specific directories if they do not exist
    archdir: ${BDIR}   ${TESTDIR}
    
    # create name for the build directory
    BDIR := bld_$(OS)_$(KERN).$(ARCH)_$(CNAME)_$(FNAME)_$(ver)
    # mkdir if the directories do not exist
    ${BDIR}:
        @mkdir -p ${BDIR}
    
    # create name for test directory
    TESTDIR = ./test/(OS)_$(KERN).$(ARCH)_$(CNAME)_$(FNAME)_$(ver)
    # mkdir if the directory does not exist
    ${TESTDIR}:
        @mkdir -p ${TESTDIR}
    The directory./test/ already exists. When I run the make file with all, the build completes without error but the new directory $TESTDIR is not created.

    Any suggestions as to what I am missing here?

    LMHmedchem

  2. #2
    Join Date
    May 2009
    Location
    Boston
    Posts
    364

    Re: makefile commands to create directories, CentOS7 , GNU Make 3.82

    I fixed this by changing the order of the assignments,
    Code:
    # create name for the build directory
    BDIR := bld_$(OS)_$(KERN).$(ARCH)_$(CNAME)_$(FNAME)_$(ver)
    # mkdir if the directories do not exist
    ${BDIR}:
        @mkdir -p ${BDIR}
    
    # create name for test directory
    TESTDIR = ./test/$(OS)_$(KERN).$(ARCH)_$(CNAME)_$(FNAME)_$(ver)
    # mkdir if the directory does not exist
    ${TESTDIR}:
        @mkdir -p ${TESTDIR}
    
    # archdir is executed as part of all and will create the necessary
    # version specific directories if they do not exist
    archdir: ${BDIR} ${TESTDIR}
    Moving the assignment of archdir to after the other definitions fixed the problem. This is a more logical order by I have often found makefiles to not follow the most logical order.

    LMHmedchem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)