May 18th, 2013, 06:38 PM
calling a script from a makefile
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.
OS := $(shell ./script_name)
May 19th, 2013, 06:50 PM
Re: calling a script from a makefile
Well I was able to get this working,
in bash script find_OS_NAME.sh,
The OS_NAME value is used to create an OS specific build directory.
# script to find the OS distribution and version
# get the general OS type
# for windows cygwin versions
if [ $TYPE_NAME = "CYGWIN_NT-5.1" ]
# for linux versions
if [ $TYPE_NAME = "Linux" ]
# 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)
# output name and version found
ARCH := $(shell uname -m)
KERN := $(shell uname -r | cut -d. -f 1,2)
# 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?
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!