calling a script from a makefile
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: calling a script from a makefile

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

    calling a script from a makefile

    Hello,

    As advertized, I would like to call a script from a makfile to glean some information about the OS. What I more or less need is the OS name and version (CentOS-5.9, OPENSUSE-12.2, Cygwin, etc). I think I can get the rest of what I need from uname. The OS name and version doesn't seem to reside in any consistent place over the various Linux flavors. I also need to get the version of the gnu c compiler, since I think that may also require a bit more involved scripting than I would like to try out of make.

    The main question is weather I can call a script out of make and have it return a value for a variable.

    Something like,

    OS := $(shell ./script_name)

    Thanks,

    LMHmedchem

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

    Re: calling a script from a makefile

    Well I was able to get this working,

    in makefile,

    OS_NAME:=$(shell ./find_OS_NAME.sh)

    in bash script find_OS_NAME.sh,
    Code:
    # script to find the OS distribution and version
    # get the general OS type
    TYPE_NAME=$(uname -s)
    
    # for windows cygwin versions
    if [ $TYPE_NAME = "CYGWIN_NT-5.1" ]
    then
       OS_NAME=$TYPE_NAME
    fi
    
    
    # for linux versions
    if [ $TYPE_NAME = "Linux" ]
    then
       # this works for CentOS but will need to be tested for other OS versions
       OS_DIST=$(cat /etc/*-release | cut -d ' ' -f 1)
       OS_VER=$(cat /etc/*-release | cut -d ' ' -f 3)
       OS_NAME=$OS_DIST'_'$OS_VER
    fi
    
    # output name and version found
    echo $OS_NAME
    The OS_NAME value is used to create an OS specific build directory.

    ARCH := $(shell uname -m)
    KERN := $(shell uname -r | cut -d. -f 1,2)
    OS_NAME:=$(shell ./find_OS_NAME.sh)

    # create a build directory name based on the local environment
    BDIR := bld_$(OS_NAME)_$(KERN)_$(ARCH)_$(FCOMP)_$(CC)_$(ver)
    $(shell mkdir -p $(BDIR))

    Does anyone see anything blatantly wrong with the approach?

    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

This is a CodeGuru survey question.


Featured


HTML5 Development Center