File: build

package info (click to toggle)
mctools-lite 970129-14
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,680 kB
  • ctags: 1,659
  • sloc: ansic: 16,036; sh: 167; makefile: 69
file content (254 lines) | stat: -rwxr-xr-x 5,730 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/sh

###############################################################################
#
# How it works
#

usage() {
  echo "Usage:"
  echo "  $myname makefiles       - Create all Makefiles"
  echo "  $myname makefile <dir>  - Create Makefile in directory <dir>"
  echo "  $myname all             - Compile everything"
  echo "  $myname <dir>           - Compile everything in directory <dir>"
  echo "  $myname install         - Install everything"
  echo "  $myname install <dir>   - Install everything in directory <dir>"
}

###############################################################################
#
# Init
#
myname=`basename $0`

while :; do
  case "$1" in
   -h|-\?|--help)	usage
			exit 1
			;;

   -*)			echo "$myname: Illegal option -- $1"
			echo "Try \`$myname --help' for more information."
			exit 1
			;;

   *)			break
			 ;;
  esac
  shift
done

if [ ! -f McTools/McApp.c ]; then
  echo "$myname: You must be in the top directory of the McTools software to build it."
  exit 1
fi

if [ ! -f config.h ]; then
 echo "$myname: No config.h! Please copy config-dist.h to config.h and edit it."
 exit 1
fi

###############################################################################
#
# Check if directory exists and contains a makefile.
#
check_makefile() {
  if [ ! -d $1 ]; then
    echo "$myname: $1 not present or not a directory.";
    return 1
  fi

  if [ "$2" ]; then chk_makefile=$2; else chk_makefile=Makefile; fi
  if [ ! -f $1/$chk_makefile ]; then
    [ "$2" ] && echo "$myname: No $chk_makefile in $1."
    return 1;
  fi

  return 0;
}

###############################################################################
#
# Creating a makefile
#
make_makefile() {
  check_makefile $1 Imakefile || return 1
  echo "------------------------------------------------------------------------------"
  echo "$myname: Making Makefile in $1"
  (cd $1 && xmkmf && make depend)
}

###############################################################################
#
# Install one app
#
do_install() {
  check_makefile $1 || make_makefile $1 || exit 1

  echo "------------------------------------------------------------------------------"
  echo "$myname: Installing in $1"
  APP=`echo $1 | awk '{ print tolower($0); }'`
  rm -f $1/$APP
  (cd $1 && make $make_args install DESTDIR=../debian/tmp) || return 1;
#  Don't bother if make install.man fails... Who needs documentation anyway? ;)
  (cd $1 && make $make_args install.man DESTDIR=../debian/tmp) || true;
}

###############################################################################
#
# Compile one app
#
compile() {
  check_makefile $1 || make_makefile $1 || exit 1

  echo "------------------------------------------------------------------------------"
  echo "$myname: Building in $1"
  APP=`echo $1 | awk '{ print tolower($0); }'`
  rm -f $1/$APP
  (cd $1 && make $make_args);
}

###############################################################################
#
# Clean up...
#
do_clean() {
  if [ -d $1 ] && [ -f $1/Imakefile ]; then
    echo "------------------------------------------------------------------------------"
    echo "Cleaning up in $1"
    ( cd $1
      if [ ! -f Makefile ]; then
        xmkmf
      fi
      make clean
      (set -x; rm -f Makefile .depend)
    )
  fi
}

###############################################################################
#
# Cool...
#
wemadeit() {
  echo "------------------------------------------------------------------------------"
  exit 0;
}

###############################################################################
#
# Build makefile(s)
#
if [ "$1" = "makefiles" ]; then

  for file in [[:upper:]]*; do
    if [ -d $file ] && [ $file != "CVS" ] && [ -f $file/Imakefile ]; then
      make_makefile $file || exit 1
    fi
  done

  wemadeit
fi

if [ "$1" = "makefile" ]; then
  shift
  while [ "$1" ]; do
    make_makefile $1 || exit 1
    shift
  done
  wemadeit
fi


###############################################################################
#
# Build everything
#
if [ "$1" = "all" ]; then

  compile McTools || exit 1

  for file in [[:upper:]]*; do
    if [ -d $file ] && [ $file != "CVS" ] && [ ! $file = McTools ]; then
      compile $file || exit 1
    fi
  done
  wemadeit
fi

###############################################################################
#
# install
#
if [ "$1" = "install" ]; then
  if [ -z $2 ]; then
    do_install McTools || exit 1
    for file in [[:upper:]]*; do
      if [ -d $file ] && [ $file != "CVS" ] && [ ! $file = McTools ]; then
        do_install $file || exit 1
      fi
    done
    wemadeit;
  fi

  shift
  while [ "$1" ]; do
    check_makefile $1 || make_makefile $1 || exit 1
    if [ -z "$mctools_installed" ]; then
      do_install McTools || exit 1
      mctools_installed=1
    fi
    do_install $1 || exit 1
    shift
  done
  wemadeit
fi

###############################################################################
#
# clean up
#
if [ "$1" = "clean" ]; then
  if [ -z $2 ]; then
    for file in [[:upper:]]*; do
      if [ $file != "CVS" ]; then
         do_clean $file
      fi
    done
    wemadeit;
  fi

  shift
  while [ "$1" ]; do
    check_makefile $1 Imakefile || exit 1
    do_clean $1
    shift
  done
  wemadeit;
fi

###############################################################################
#
# build a program
#
if [ "$1" ]; then
  mctools_compiled=""
  while [ "$1" ]; do
    check_makefile $1 Imakefile || exit 1
    if [ -z "$mctools_compiled" ]; then
      compile McTools || exit 1
      mctools_compiled=1
    fi
    compile $1 || exit 1
    shift
  done
  wemadeit
fi

###############################################################################
#
# Unknown argument
#

usage
exit 1