Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / bin / smake
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         smake
5 # Description:  Salira make: Builds on the build server
6 # Author:       Andrew@DeFaria.com
7 # Created:      Fri Dec  7 18:45:20  2001
8 # Language:     bash
9 #
10 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved.
11 #
12 ################################################################################
13 # Set me to command name
14 me=$(basename $0)
15
16 # Source /etc/site_parms
17 if [ -f /etc/site_parms ]; then
18   . /etc/site_parms
19 else
20   echo "$me: WARNING: /etc/site_parms does not exist!"
21 fi
22
23 # Set adm_base
24 adm_base="$SITE_TOOLS_PATH/adm"
25
26 # Set adm_fpath
27 adm_fpath=${adm_fpath:-$adm_base/functions}
28
29 # Source functions
30 . $adm_fpath/common
31
32 # Define the build_server
33 build_server=$SITE_BUILD_SERVER
34
35 # Get my host's name
36 myhost=$(hostname | tr [:upper:] [:lower:])
37
38 # Some simple checks. First are we in a build directory?
39 parent_dir=$(echo ${PWD%/*})
40 parent_parent_dir=$(echo ${PWD%/*/*})
41 parent_parent_parent_dir=$(echo ${PWD%/*/*/*})
42 current_dir=$(basename $PWD)
43
44 if [ ! -z "$parent_dir" ]; then
45   parent_dir=$(basename $parent_dir)
46 else
47   parent_dir=.
48 fi
49
50 if [ ! -z "$parent_parent_dir" ]; then
51   parent_parent_dir=$(basename $parent_parent_dir)
52 else
53   parent_parent_dir=.
54 fi
55
56 if [ ! -z "$parent_parent_parent_dir" ]; then
57   parent_parent_parent_dir=$(basename $parent_parent_parent_dir)
58 else
59   parent_parent_parent_dir=.
60 fi
61
62 if [  $parent_dir != "build" -a $parent_parent_dir != "build" -a $current_dir != "build" -a $parent_parent_parent_dir != "build" ]; then
63   echo "$me: Error: You are not currently in a build/target directory!"
64   echo "       Current working directory is $PWD"
65   exit 1
66 fi
67
68 # Now let's check to see that this directory is visible on the $build_server
69 #rsh $build_server ls -d $PWD > /dev/null 2>&1
70
71 #if [ $? -ne 0 ]; then
72 #  echo "$me: Error: I cannot see $PWD from $build_server"
73 #  echo "       This might be because your view is local"
74 #fi
75
76 # Now let's check to see if this file system is local
77 filesystem=$(df . 2>/dev/null | grep -v ^Filesystem | /bin/head -1 | cut -f1 -d' ' | tr '\\' '/')
78
79 if [ "$filesystem" = "${filesystem#//*}" -a $myhost != $build_server ]; then
80   echo "$me: Warning: You're on a local file system!"
81   echo "Build server: $myhost View: $(cleartool pwv -short) [local]"
82   echo "User: $USER Dir: $PWD"
83   echo "Performing build locally on $myhost"
84   echo "$myhost:make $@"
85   if [ $myhost = "sons-clearcase" ]; then
86     export TOOLS_ROOT=E:/Tools && nice make -e "$@"
87   elif [ $myhost = "sons-cc" -o $myhost = "sonsbld1" ]; then
88     export TOOLS_ROOT=C:/Tools && nice make -e "$@"
89   else
90     nice make "$@"
91   fi
92 else
93   if [ $myhost = $build_server ]; then
94     # No need to rsh!
95     echo "Build server: $myhost View: $(cleartool pwv -short) [local]"
96     echo "User: $USER Dir: $PWD"
97     echo "Performing build locally on $myhost"
98     echo "$myhost:make $@"
99     if [ $myhost = "sons-clearcase" ]; then
100       export TOOLS_ROOT=E:/Tools && nice make -e "$@"
101     elif [ $myhost = "sons-cc" -o $myhost = "sonsbld1" ]; then
102       export TOOLS_ROOT=C:/Tools && nice make -e "$@"
103     else
104       nice make "$@"
105     fi
106   else
107     echo "Build machine: $build_server View: $(cleartool pwv -short) [remote]"
108     echo "Launched from: $myhost by $USER"
109     echo "Dir: $PWD"
110     echo "$build_server:make $@"
111     if [ $build_server = "sonsbld1" ]; then
112       rsh -n $build_server "cd $(pwd) && export TOOLS_ROOT=C:/Tools && nice make -e $@"
113     else
114       rsh -n $build_server "cd $(pwd) && export TOOLS_ROOT=E:/Tools && nice make -e $@"
115     fi
116   fi
117 fi