bash command in makefile (cygwin)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting bash command in makefile (cygwin)
# 1  
Old 03-20-2011
bash command in makefile (cygwin)

Hello,

In my make file (make 3.81), I use a combination of shell commands to automatically create the name of my build directory.
Code:
OS   := $(shell uname -s)
ARCH := $(shell uname -m)
KERN := $(shell uname -r | cut -d. -f 1,2)
BDIR := $(OS)_$(KERN).$(ARCH)

When I boot into different OSs, I build from the same shared directory. This code creates and assigns a different build dir based on whatever OS I am booted into. In Linux, the following command creates the dir if it doesn't exist.

Code:
# create build directory if it doesn't exist
archdir: ${BDIR}
${BDIR}:
    @mkdir -p ${BDIR}

This doesn't work under cygwin, and I'm not sure what the issue is. For now, I have to create the dir by hand when I boot into a windows OS.

Any ideas as to what the issue may be here?

I would also like to add the name of the linux distro, like fedora, debian, etc. Is there a shell command the will give that to me. If I do uname -s, I just get "Linux".

Thanks for the help,

LMHmedchem
# 2  
Old 03-20-2011
Seems to work fine for me:

Code:
$ ls
Makefile
$ cat Makefile
OS   := $(shell uname -s)
ARCH := $(shell uname -m)
KERN := $(shell uname -r | cut -d. -f 1,2)
BDIR := $(OS)_$(KERN).$(ARCH)
 
archdir: ${BDIR}
${BDIR}:
        @mkdir -p ${BDIR}
$ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i686-pc-cygwin
$ make
$ ls
CYGWIN_NT-5.1_1.7.i686  Makefile


Last edited by Chubler_XL; 03-20-2011 at 08:17 PM..
# 3  
Old 03-20-2011
Thanks for trying it for me. I wonder what the issue is here, I will look again and see if I just did something dumb.

Any suggestions about how to get the OS distro from bash?

LMHmedchem
# 4  
Old 03-20-2011
For linux distro how about a script something like this (based on this article):

Code:
#!/bin/sh
# Detects which OS and if it is Linux then it will detect which Linux Distribution.
OS=`uname -s`
REV=`uname -r| cut -d. -f 1,2`
MACH=`uname -m`
 
if [ "${OS}" = "SunOS" ] ; then
        OS=Solaris
        ARCH=`uname -p`
        OSSTR="${OS} ${REV}(${ARCH} `uname -v`)"
elif [ "${OS}" = "AIX" ] ; then
        OSSTR="${OS} `oslevel` (`oslevel -r`)"
elif [ "${OS}" = "Linux" ] ; then
        KERNEL=`uname -r`
        if [ -f /etc/redhat-release ] ; then
                DIST='RedHat'
                PSUEDONAME=`cat /etc/redhat-release | sed s/.*\(// | sed s/\)//`
                REV=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
        elif [ -f /etc/SUSE-release ] ; then
                DIST=`cat /etc/SUSE-release | tr "\n" ' '| sed s/VERSION.*//`
                REV=`cat /etc/SUSE-release | tr "\n" ' ' | sed s/.*=\ //`
        elif [ -f /etc/mandrake-release ] ; then
                DIST='Mandrake'
                PSUEDONAME=`cat /etc/mandrake-release | sed s/.*\(// | sed s/\)//`
                REV=`cat /etc/mandrake-release | sed s/.*release\ // | sed s/\ .*//`
        elif [ -f /etc/debian_version ] ; then
                DIST="Debian `cat /etc/debian_version`"
                REV=""
        fi
        if [ -f /etc/UnitedLinux-release ] ; then
                DIST="${DIST}[`cat /etc/UnitedLinux-release | tr "\n" ' ' | sed s/VERSION.*//`]"
        fi
        OSSTR="${OS} ${DIST} ${REV}(${PSUEDONAME} ${KERNEL} ${MACH})"
else
    OSSTR="${OS} ${REV} ${ARCH}"
fi
 
echo ${OSSTR} | tr ' ' '_'

This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 03-21-2011
Thanks a ton, that is exactly what I was looking for.

LMHmedchem

---------- Post updated 03-21-11 at 02:08 PM ---------- Previous update was 03-20-11 at 07:21 PM ----------

Conditional syntax in make is a bit different than bash. Any suggestions on how to convert this to make compatible code? I know that you can run shell command from make, but I don't remember how. I don't think that make has extened if, elseif, elseif, etc. I think it just has if and else.

I also don't know the make equivalent of,
if [ -f /etc/redhat-release ] ; meaning how to test if a file exists. I don't know if I can do something like,

ifneq "$(shell -f /etc/redhat-release)" ''"

I'm not sure what to do here.

LMHmedchem
# 6  
Old 03-21-2011
Yes, make isn't the tool for this sort of thing, that is why most tarballs come with a configure.sh script that determines what is needed and then genereates the Makefile required.
# 7  
Old 03-21-2011
So I guess I'm back to manually creating my build directory names, or can I call the bash script from make and have it return something useful? Is there an easy way to execute bash commands from make using shell, or something like that?

LMHmedchem
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Using BATCH to call a BASH script on CygWin

I am trying to use a batch file to automatically execute a bash script with no luck this far. The batch script looks like this: C:\Cygwin64\bin\bash test.sh I have also tried this: C:\Cygwin64\bin\bash "C:\Cygwin64\bin\test.sh" Needless to say that the windows box has Cygwin... (7 Replies)
Discussion started by: Xterra
7 Replies

2. Shell Programming and Scripting

Bash Script (tar + md) on Cygwin

Hi everybody, First, I'm sorry for my bad english! I have the following situation: I have a Windows 2012 R2 with Cygwin installed. The Windows Server is used as a backup Server with Dell AppAssure installed. At the moment, AppAssure saves Backup Targets to a repository on his D. The... (9 Replies)
Discussion started by: fibra3000
9 Replies

3. UNIX for Dummies Questions & Answers

Bash on CygWin

I am using CygWin to run a bash file but I am getting weird results. #!/bin/bash mkdir CLEANDATA mv *FASTA CLEANDATA cd CLEANDATA ls echo "COMPLETE" And this is what I get $ ./Pipe.txt ./Pipe.txt: line 5: $'ls\r': command not found COMPLETE Moreover, the new folder is... (1 Reply)
Discussion started by: Xterra
1 Replies

4. Shell Programming and Scripting

Help with bash scripting in cygwin

Hi, I am trying to write a bash script, to open firefox and then open a local webpage in a tab. This is a shell of what I have #! /bin/sh alias firefox='/cygdrive/c/Program\ Files/Mozilla\ Firefox/firefox.exe' $URL='/cygdrive/d/Playback.html' firefox & sleep 1 for i in 1 2 3 4 5 #6 7 8 9... (1 Reply)
Discussion started by: jamie_123
1 Replies

5. Shell Programming and Scripting

redirect time command output to file (cygwin bash)

I have set up a bash script to run a long list of things that I need to time. I would like to redirect the output of time to a file. I have set it up like, echo "Runtimes for servlet 4, 100K structures" > test_times.txt echo "" >> test_times.txt echo "runs where N=10" >> test_times.txt echo... (7 Replies)
Discussion started by: LMHmedchem
7 Replies

6. Shell Programming and Scripting

[Bash/Makefile] Concatenated string of filenames?

How would I go about storing a list of files in a sub-directory into a variable for argument passing? (2 Replies)
Discussion started by: ChazZeromus
2 Replies

7. Shell Programming and Scripting

Strange suppression of output with bash and cygwin

Hi, although I am not expert in bash, so please forgive me if this is silly, I think that this is strange: I have this command: find . -type f -print0 |xargs -0 grep -i -e 'some rexp' and it works fine. But when I create a bash script (on cygwin) to run this command, there is no output !!!... (3 Replies)
Discussion started by: Niki999
3 Replies

8. UNIX for Dummies Questions & Answers

Cygwin bash script and read command

Hello everyone, I am struggling a bit with a batch script that I need to run in cygwin. I work in winXP and I had to write some awk scripts to do some file manipulation, and now I would like to automate the process by just running a batch file so that my colleagues can use it easily. Now, the... (2 Replies)
Discussion started by: Teroc
2 Replies

9. UNIX for Dummies Questions & Answers

cygwin bash startup command weirdness (part 1)

I am running (I believe) the latest stable version of cygwin CYGWIN_NT-5.1 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin on a win xp sp2 laptop. Suppose, to make things simple for now (but I may do a part 2 posting...), that I am in a dos shell, and I want to create a bash shell and have it... (1 Reply)
Discussion started by: fabulous2
1 Replies

10. UNIX for Dummies Questions & Answers

How to use cygwin to run bash script

Hi, all, I try to run a quite simple bash script mytest.sh in cygwin, it's content is: #!/bin/bash echo "It is my first bash shell" there are three lines in the script. The second line is blank line. When I run it use command: bash c:/mytest.sh, ... (6 Replies)
Discussion started by: Jenny.palmy
6 Replies
Login or Register to Ask a Question