File: getmachine

package info (click to toggle)
viewmol 2.4.1-13
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,212 kB
  • ctags: 2,054
  • sloc: ansic: 30,727; python: 1,849; sh: 921; awk: 433; makefile: 205
file content (448 lines) | stat: -rwxr-xr-x 15,146 bytes parent folder | download | duplicates (3)
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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#!/bin/bash
#*******************************************************************************
#                                                                              *
#                                   Viewmol                                    *
#                                                                              *
#                             G E T M A C H I N E                              *
#                                                                              *
#                 Copyright (c) Joerg-R. Hill, October 2003                    *
#                                                                              *
#*******************************************************************************
#
# $Id: getmachine,v 1.6 2003/11/07 12:53:43 jrh Exp $
# $Log: getmachine,v $
# Revision 1.6  2003/11/07 12:53:43  jrh
# Release 2.4
#
# Revision 1.5  2000/12/10 15:07:25  jrh
# Release 2.3
#
# Revision 1.4  1999/05/24 01:25:38  jrh
# Release 2.2.1
#
# Revision 1.3  1999/02/07 22:02:47  jrh
# Release 2.2
#
# Revision 1.2  1998/01/26 00:47:46  jrh
# Release 2.1
#
# Revision 1.1  1996/12/10  18:46:19  jrh
# Initial revision
#
# This shell script adapts the Makefile in dependence
# of the machine and the operating system you use.
# It is called from 'make viewmol' before the compiler
# is invoked.
#

makedir()
{
  if [ ! -d "$dir" ]
  then
    mkdir "$dir"
  fi
  cd $dir
}

givehint()
{
  if [ $hint -eq 1 ]
  then
    echo 'If you want to use environment variables in any of the following'
    echo 'paths, do it like this: $(HOME)'
    hint=0
  fi
}

findProcessor()
{
  # Try -p option first, but since this option is not always
  # available use -m option if -p option fails or return "unknown"
  processor=`uname -p 2> /dev/null`
  if [ "$processor" = "" -o "$processor" = "unknown" ]
  then
    processor=`uname -m`
  fi
  
  # for the Debian auto-build system, we identify the processor thus:
  processor=`dpkg --print-architecture`
  
  if [ "$processor" = "i386" -o "$processor" = "i686" -o "$processor" = "i586" ]
  then
    # Debian policy says ia32 (i386) binaries should be optimised 
    # for no more than i486. 
    # But this runs noticably slower on i686 (P-4 class), so I recommend you 
    # change it for your own system and recompile.
    # Note I am deliberately excluded i386 machines, by upgrading them to i486.
    # This is because `dpkg --print-architecture` always returns i386 on
    # Pentium level systems, but I want to optimise for no less than i486.
    processor=i486
    
    # need the following to flag for -malign-double, which is Intel only.
    processor_is_i386=true
  fi

  # or set the flag for true i486 too
  if [ "$processor" = "i486" ]
  then
    processor_is_i386=true
  fi
}

target=$1
os=`uname -s`

case $os in
    GNU/k*BSD | GNU)
	# GNU variants are treated like Linux
        os=Linux
    ;;
    *)
    ;;
esac

# Check, whether configuration file is up to date
if [ -f .config.$os ]
then
  grep PNGINCLUDE .config.$os > /dev/null 2> /dev/null
  ret=$?
  if [ $ret -eq 1 ]
  then
    rm -f .config.$os
  fi
fi

if [ ! -f .config.$os ]
then
  hint=1

  # TIFF library
  if [ -f /usr/lib/libtiff.a ]
  then
    libtiff="-L/usr/lib"
  elif [ -f /usr/local/lib/libtiff.a ]
  then
    libtiff="-L/usr/local/lib"
  else
    givehint
    echo -n "Please enter the name of the directory where libtiff.a can be found: "
    read libtiff
    if [ "$libtiff" != "" ]
    then
      libtiff="-L${libtiff}"
    fi
  fi
  echo "LIBTIFF = ${libtiff}" > .config.$os

  # TIFF include file
  if [ -f /usr/include/tiff.h ]
  then
    case $os in
      CYGWIN*) tiffinclude="."
               ;;
      *)       tiffinclude="/usr/include"
               ;;
    esac
  elif [ -f /usr/local/include/tiff.h ]
  then
    tiffinclude="/usr/local/include"
  else
    givehint
    echo -n "Please enter the name of the directory where the include file for libtiff can be found: "
    read tiffinclude
  fi
  echo "TIFFINCLUDE = $tiffinclude" >> .config.$os

  # PNG library
  if [ -f /usr/lib/libpng.a -o -f /usr/lib/libpng12.a ]
  then
    libpng="-L/usr/lib"
  elif [ -f /usr/local/lib/libpng.a ]
  then
    libpng="-L/usr/local/lib"
  else
    givehint
    echo -n "Please enter the name of the directory where libpng.a can be found: "
    read libpng
    if [ "$libpng" != "" ]
    then
      libpng="-L${libpng}"
    fi
  fi
  echo "LIBPNG = ${libpng}" >> .config.$os

  # PNG include file
  if [ -f /usr/include/png.h ]
  then
    pnginclude="/usr/include"
  elif [ -f /usr/include/libpng12/png.h ]
  then
    pnginclude="/usr/include/libpng12"
  elif [ -f /usr/local/include/png.h ]
  then
    pnginclude="/usr/local/include"
  else
    givehint
    echo -n "Please enter the name of the directory where the include file for libpng can be found: "
    read pnginclude
  fi
  echo "PNGINCLUDE = $pnginclude" >> .config.$os

  # Python
  list=`find /usr -name Python.h -print 2> /dev/null`
  version=`(for i in $list
            do
              dir=\`dirname $i\`
              echo \`basename $dir\`
            done) | sort | tail -1`
  if [ "$version" != "" ]
  then
    pythoninclude=`dirname \`(for i in $list
                              do
                                echo $i | grep $version
                              done)\``
    pythonversion=$version
  else
    givehint
    echo -n "Please enter the name of the directory where the include files for Python can be found: "
    read pythoninclude
    pythonversion=`basename $pythoninclude`
  fi
  echo "PYTHONVERSION = $pythonversion" >> .config.$os
  echo "PYTHONINCLUDE = $pythoninclude" >> .config.$os
  if [ "$version" != "" ]
  then
    pythonlib=`dirname \`find /usr -name "lib${version}*.a" -print 2> /dev/null | grep "$version/" | xargs echo | awk '{print $1}'\``
  else
    givehint
    echo -n "Please enter the name of the directory where the Python library can be found: "
    read pythonlib
  fi
  echo "LIBPYTHON = $pythonlib" >> .config.$os
fi

PYTHON="python2"
if [ $os = "FreeBSD" ]
then
  PYTHON="python2.2"
else
  PYTHON=`which python2 2> /dev/null`
  ret=$?
  if [ $ret -ne 0 ]
  then
    PYTHON=`which python 2> /dev/null`
    ret=$?
    if [ $ret -ne 0 ]
    then
      echo "Cannot find Python."
      exit
    fi
  fi
fi

LINKFORSHARED=`$PYTHON - <<EOF
import distutils.sysconfig
print distutils.sysconfig.get_config_var('LINKFORSHARED')
EOF
`

case $os in
#
# This is an IBM RS/6000.
#
  AIX)     if [ `uname -m | cut -c9-10` = "70" ]
           then
             dir="${os}_POWER2"
           else
             dir="${os}_POWER"
           fi
           makedir
           cat ../.config.$os > makefile
           echo 'COMPILER=cc' >> makefile
           echo 'OPT=-O2' >> makefile
           echo 'CFLAGS=-DAIX' >> makefile
           echo "LDFLAGS=$LINKFORSHARED" >> makefile
           echo 'SCANDIR=' >> makefile
           echo 'INCLUDE=/usr/lpp/OpenGL/include -I$(TIFFINCLUDE) -I$(PNGINCLUDE) -I$(PYTHONINCLUDE)' >> makefile
           echo 'LIBRARY=-L/usr/lpp/OpenGL/lib $(LIBTIFF) $(LIBPNG) -L$(LIBPYTHON)' >> makefile
           echo 'LIBS=-l${PYTHONVERSION} -ltiff -lpng -lz -lGLU -lGL -lXm -lXmu -lXi -lXext -lXt -lX11 -lm' >> makefile
           ;;
#
# This is a Silicon Graphics.
#
  IRIX*)   dir="${os}_`hinv | awk '/CPU:/ {print $3}' | cut -d/ -f2`"
           makedir
           cat ../.config.$os > makefile
           echo 'COMPILER=cc' >> makefile
           echo 'OPT=-O2' >> makefile
           if [ "$dir" = "IRIX_R4400" -o "$dir" = "IRIX_R4600" -o "$dir" = "IRIX_R5000" ]
           then
             echo 'CFLAGS=-DIRIX -n32' >> makefile
             echo "LDFLAGS=-n32 -Wl,-woff,85,-woff,134 $LINKFORSHARED" >> makefile
           elif [ "$dir" = "IRIX64_R8000" -o "$dir" = "IRIX64_R10000" -o "$dir" = "IRIX64_R12000" ]
           then
#
# uses -n32 since libtiff is not available in a 64 bit version on SGIs
#
             echo 'CFLAGS=-DIRIX -n32' >> makefile
             echo "LDFLAGS=-n32 -Wl,-woff,85,-woff,134 $LINKFORSHARED" >> makefile
           else
             echo 'CFLAGS=-DIRIX' >> makefile
             echo "LDFLAGS=-Wl,-woff,85,-woff,134 $LINKFORSHARED" >> makefile
           fi
           echo 'SCANDIR=' >> makefile
           echo 'INCLUDE=$(TIFFINCLUDE) -I$(PNGINCLUDE) -I$(PYTHONINCLUDE)' >> makefile
           echo 'LIBRARY=$(LIBTIFF) $(LIBPNG) -L$(LIBPYTHON)' >> makefile
           echo 'LIBS=-l${PYTHONVERSION} -ltiff -lpng -lz -lGLU -lGL -lXm -lXmu -lXi -lXt -lX11 -lpthread -lm -lCsup' >> makefile
           ;;
#
# This is Linux.
#
  Linux)   dir="$os"
           makedir
           cat ../.config.$os > makefile
#           use_icc=`type icc 2> /dev/null`
	    use_icc=""
	   echo "using Linux and use_icc=\"${use_icc}\""
           if [ "$use_icc" = "" ]
           then
	     findProcessor
	     if [ "$processor_is_i386" ]
	     then
	     	# -malign-double applies only to intel systems
	        machine_opts="-malign-double"
		processor_opt="-march=$processor"
	     elif [ "$processor" == "powerpc" ]
	     then
	     	# there is no -mcpu option for the more obscure
		# architectures like arm, ia64, so we have to be selective.
		# In fact, it only applies to i386 and powerpc.
	     	processor_opt="-mcpu=$processor"
	     fi
	     echo 'COMPILER=gcc' >> makefile
             echo "OPT=-O6 $processor_opt -fomit-frame-pointer -ffast-math $machine_opts" >> makefile
             echo 'CFLAGS=-Wall -I/usr/X11R6/include -DLINUX -Wno-strict-aliasing' >> makefile
             echo "LDFLAGS=$LINKFORSHARED" >> makefile
           else
	     echo 'COMPILER=icc' >> makefile
             echo 'OPT=-O2 -ipo' >> makefile
             echo 'CFLAGS=-I/opt/intel/compiler50/ia32/include -I/usr/X11R6/include -DLINUX' >> makefile
             echo "LDFLAGS=$LINKFORSHARED -ipo" >> makefile
           fi
           echo 'SCANDIR=' >> makefile
           echo 'INCLUDE=$(TIFFINCLUDE) -I$(PNGINCLUDE) -I$(PYTHONINCLUDE)' >> makefile
           echo 'LIBRARY=$(LIBTIFF) $(LIBPNG) -L$(LIBPYTHON)' >> makefile
           echo 'LIBS=-L/usr/local/lib -l${PYTHONVERSION} -ltiff -lpng -lGLU -lGL -L/usr/X11R6/lib -lXm -lXmu -lXi -lXt -lX11 -lm' >> makefile
           ;;
#
# This is FreeBSD
#
  FreeBSD) dir="$os"
           makedir
           cat ../.config.$os > makefile
	   findProcessor
	   echo 'COMPILER=cc' >> makefile
           echo "OPT=-O6 -mcpu=$processor -fomit-frame-pointer -ffast-math -malign-double" >> makefile
           echo 'CFLAGS=-Wall -I/usr/X11R6/include -DFREEBSD' >> makefile
           echo "LDFLAGS=$LINKFORSHARED" >> makefile
           echo 'SCANDIR=' >> makefile
           echo 'INCLUDE=$(TIFFINCLUDE) -I$(PNGINCLUDE) -I$(PYTHONINCLUDE)' >> makefile
           echo 'LIBRARY=$(LIBTIFF) $(LIBPNG) -L$(LIBPYTHON)' >> makefile
           echo 'LIBS=-l${PYTHONVERSION} -ltiff -lpng -lz -lGLU -lGL -L/usr/X11R6/lib -lXm -lXmu -lXi -lXext -lXt -lX11 -lutil -lm' >> makefile
           ;;
#
# This is Mac OS X
#
  Darwin)  dir="$os"
           makedir
           cat ../.config.$os > makefile
           echo 'COMPILER=gcc' >> makefile
           echo 'OPT=-O2 -fomit-frame-pointer' >> makefile
           echo 'CFLAGS=-Wall -DDARWIN -I/usr/X11R6/include' >> makefile
           echo "LDFLAGS=-bind_at_load $LINKFORSHARED" >> makefile
           echo 'SCANDIR=' >> makefile
           echo 'INCLUDE=$(TIFFINCLUDE) -I$(PNGINCLUDE) -I$(PYTHONINCLUDE)' >> makefile
           echo 'LIBRARY=$(LIBTIFF) $(LIBPNG) -L$(LIBPYTHON) -L/usr/X11R6/lib' >> makefile
           echo 'LIBS=-l${PYTHONVERSION} -ltiff -lpng -lz -lGLU -lGL -lXm -lXmu -lXi -lXext -lXt -lX11 -lm' >> makefile
           ;;
#
# This is OSF1
#
  OSF1)    dir="$os"
           makedir
           cat ../.config.$os > makefile
           echo 'COMPILER=cc' >> makefile
           echo 'OPT=-O2 -Olimit 615' >> makefile
           echo 'CFLAGS=-ieee_with_no_inexact' >> makefile
           echo "LDFLAGS=$LINKFORSHARED" >> makefile
           echo 'SCANDIR=' >> makefile
           echo 'INCLUDE=$(TIFFINCLUDE) -I$(PNGINCLUDE) -I$(PYTHONINCLUDE)' >> makefile
           echo 'LIBRARY=$(LIBTIFF) $(LIBPNG) -L$(LIBPYTHON)' >> makefile
           echo 'LIBS=-l${PYTHONVERSION} -lXm -lXmu -lXi -lXt -lGLU -lGL -lX11 -ltiff -lpng -lz -lm' >> makefile
           ;;
#
# This is HP-UX
#
  HP-UX)   dir="$os"
           makedir
           cat ../.config.$os > makefile
           echo 'COMPILER=cc' >> makefile
           echo 'OPT=-O2' >> makefile
           echo 'CFLAGS=-Aa -D_HPUX_SOURCE' >> makefile
           echo "LDFLAGS=$LINKFORSHARED" >> makefile
           echo 'SCANDIR=' >> makefile
           echo 'INCLUDE=$(TIFFINCLUDE) -I$(PNGINCLUDE) -I/usr/include/Motif1.2 -I/usr/include/X11R5 -I$(PYTHONINCLUDE)' >> makefile
           echo 'LIBRARY=$(LIBTIFF) $(LIBPNG) -L/usr/lib/Motif1.2 -L/usr/lib/X11R5 -L$(LIBPYTHON)' >> makefile
           echo 'LIBS=-l${PYTHONVERSION} -lXm -lXmu -lXi -lXt -lGLU -lGL -lX11 -ltiff -lpng -lz -lm' >> makefile
           ;;
#
# This is SunOS
#
  SunOS)   dir="$os"
           makedir
           cat ../.config.$os > makefile
           use_gcc=`type gcc 2> /dev/null`
           if [ "$use_gcc" = "" ]
           then
             echo 'COMPILER=cc' >> makefile
             echo 'OPT=-xO4 -native' >> makefile
             echo 'CFLAGS= -DSunOS -xlibmil' >> makefile
             echo "LDFLAGS=-L/usr/dt/lib $LINKFORSHARED" >> makefile
	   else
	     echo 'COMPILER=gcc' >> makefile
             echo "OPT=-O6 -fomit-frame-pointer -ffast-math" >> makefile
             echo 'CFLAGS=-Wall -I/usr/X11R6/include' >> makefile
             echo "LDFLAGS=$LINKFORSHARED" >> makefile
	   fi
           echo 'SCANDIR=scandir.o' >> makefile
           echo 'INCLUDE=$(TIFFINCLUDE) -I$(PNGINCLUDE) -I$(PYTHONINCLUDE)' >> makefile
           echo 'LIBRARY=$(LIBTIFF) $(LIBPNG) -L$(LIBPYTHON)' >> makefile
           echo 'LIBS=-l${PYTHONVERSION} -lXm -lXmu -lXi -lXt -lGLU -lGL -lX11 -lm -Bstatic -ltiff -lpng -lz -Bdynamic ' >> makefile
           ;;
#
# This is Windows with Cygwin
#
   CYGWIN*) dir="$os"
            makedir
            cat ../.config.$os > makefile
	    findProcessor
	    echo 'COMPILER=cc' >> makefile
            echo "OPT=-mcpu=$processor -fomit-frame-pointer -ffast-math -malign-double" >> makefile
            echo 'CFLAGS=-DSYS_NMLN=20 -Wall -I/usr/X11R6/include -DLINUX' >> makefile
            echo "LDFLAGS=-L/usr/local/lib/w32api/ $LINKFORSHARED" >> makefile
            echo 'SCANDIR=' >> makefile
            echo 'INCLUDE=$(TIFFINCLUDE) -I$(PNGINCLUDE) -I$(PYTHONINCLUDE)' >> makefile
            echo 'LIBRARY=$(LIBTIFF) $(LIBPNG) -L$(LIBPYTHON)' >> makefile
            echo 'LIBS=-L/usr/local/BerkeleyDB.4.0/lib -L/usr/local/lib -l${PYTHONVERSION} -ltiff -lpng12 -lz -lGLU -lGL -L/usr/X11R6/lib -lXmu -lXm -lXp -lXi -lXext -lXt -lX11 -lpthread -lm -lSM -lICE' >> makefile
            ;;
#
# This is a (not yet) known operating system.
#
  *)       echo "Sorry, I don't know the operating system '$os'."
           echo "Edit 'getmachine' to include the required options."
           exit 1
           ;;
esac
cat ../Makefile >> makefile
make ${target}_
rm -f makefile