This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Cygwin for Fedora?


> 
> Hello,
> 
> Was wondering if it's possible to install / emulate Cygwin on Fedora?
> 
> Basically, I want my scripts to be able to run flawlessly on both Fedora
> and
> Cygwin/Windows systems. Cygwin, I believe, can have different packages
> and/or
> different versions of programs in packages (e.g. /usr/bin/file, whose
> output for
> Microsoft documents changes with versions).
> 
> Instead of asking for access to a Cygwin/Windows PC just for the above, I
> thought it would be terrific if Cygwin could somehow be installed /
> emulated on
> a Fedora.
> 
> Regards,
> /HS
>
 
Harry -

I understand what you are asking for and it is a special case of wanting to
have the same shell scripts run in a Windows (e.g. Cygwin) and other UNIX
environments:  e.g. Linux, Solaris, HP/UX and AIX to name a few.    
As you point out many commands with the same name actually have different
behaviors in different environments.  There are many ways this can be
handled and at the risk of starting a debate as to what is the best way, I
will give you one alternative that I have used successfully many times.

I create a file named common.sh which contains functions common to all my
scripts and functions which abstract out the differences between platforms.
This file is read into all my scripts using something like the following.

$BINDIR=`dirname` $0`  
. "$BINDIR"/common.sh

This assumes that all your scripts are in the same directory, but if not you
get the idea.

One key function in common.sh is:

setplat () {
        # Set the location of UNIX commands and the
        # names of some UNIX command.  And some common
        # common parameters.

        # Set default name of awk command
        AWK_CMD=awk

        # Set the OS specific parameters
        set `uname -a`
        OSVERSION=$1$3
        case $OSVERSION in
                SunOS*) PATH=/usr/bin
                        AWK_CMD=nawk
                        PLATFORM=SunOS
                        HOSTNAME=`hostname`
                        # Solaris hostname is a FQDN! Strip DN.
                        HOSTNAME=${HOSTNAME%%[.]*}
                        ;;


                Linux*) PATH=/bin:/usr/bin
                        PLATFORM=Linux
                        HOSTNAME=`hostname -s`
                        ;;
                CYG*)
                        PLATFORM=WINNT
                        ;;

                 # Other platforms removed for clarity.
        esac
}

# Now determine where we are executing.
setplat

The above is by no means complete, as I have stripped out some stuff to make
it clearer.  Note that in the above the path is set to a restricted set of
directories.  This may not be what you want, but this example, is for a
build system and the construction environment is set elsewhere and refers to
absolute path names to commands used.  This ensures there are no mistakes
that might be made because of similar commands being installed by other
packages.

Now here is an example what you might do.  If running in a Windows
environment, some commands might yield a windows path name which should not
be passed into a Cygwin command.  So you define a function get_path which
always returns a POSIX style path.

get_path () {
        case $OSVERSION in
                CYG*)  `cygpath "$1"` ;;
                *)      echo "$1" ;;
        esac
}

And you do things like 

SOURCE_ROOT=`get_path "$SOURCE_ROOT"`

Where you need to be sure you have a POSIX style path

Here's an example of a function that gets the value of the nth field from
standard input.  It deals with the problem of DOS line endings that might
occur in non-Cygwin environments. 

field () {
        # Careful. The stuff in brackets is space tab.
        sed "s/[ 	][ 	]*/|/g" | cut -d"|" -f$1 | sed s/$'\r'//
}

Now the nice thing about this approach is that all the platform differences
can be isolated / migrated to one place and tuned as you need.

HTH 

Andy Hall














--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]