Revision 1397 trunk/scripts/admb/adlink

adlink (revision 1397)
1 1
#!/bin/bash
2
shopt -s expand_aliases
3
alias help='echo -e "Usage: adlink [-d] [-g] [-r] [-s] model\n
4
Link AD Model Builder object code to executable.\n
5
  -d     Create DLL
6
  -g     Insert debugging symbols
7
  -r     Create ADMB-RE
8
  -s     Enforce safe bounds
9
  model  Filename prefix, e.g. simple\n"'
10
if [[ "$1" == "" ]]; then help; exit; fi
11
if [[ "$1" == "-help" ]]; then help; exit; fi
12
if [[ "$1" == "--help" ]]; then help; exit; fi
13

  
14
if [ -f "$ADMB_HOME/bin/admb-cfg.sh" ]; then
15
  source "$ADMB_HOME/bin/admb-cfg.sh"
16
  CXX=$ADMB_CFG_CXX
17
  LDFLAGS="$LDFLAGS $ADMB_CFG_LDFLAGS"
18
else
19
  CXX=c++
20
fi
21

  
22
if [ "$CXX" == "openCC" ]; then
23
  sym=-O2
24
else
25
  sym=-O3
26
fi
27

  
28
unset shared
29
opt=
30
while getopts "dgrso" A; do
31
  case $A in
32
    d) shared=-shared;;
33
    g) sym=-g;;
34
    r) ;;
35
    s) ;;
36
    o) opt=o;;
37
  esac
38
done
39
shift $((OPTIND-1))
40

  
41
#if [[ "`uname -s`" == "Darwin" ]]; then unset sym; fi
42

  
43
model="${1%.*}"
44

  
45
objects=
46
for file in $*
2
#
3
# Copyright (c) 2013 ADMB Foundation
4
#
5
args=
6
for arg in $*
47 7
do
48
  extension="${file#*.}"
49
  if [ "$extension" = "$file" ]; then
50
    objects="${file%.*}.o $objects"
51
  elif [ "$extension" = "obj" -o "$extension" = "o" ]; then
52
    objects="$objects $file"
53
  fi 
8
  extension="${arg#*.}"
9
  if [ "-" = "${arg:0:1}" ]; then
10
    args="$args $arg"
11
  elif [ "$extension" = "$arg" ]; then
12
    args="$args ${arg}.obj
13
  else
14
    args="$args $arg"
15
  fi
54 16
done
55

  
56
LDFLAGS="$LDFLAGS"
57
if [ ! -z "$sym" ]; then
58
  LDFLAGS="$LDFLAGS $sym"
59
fi
60
if [ ! -z "$shared" ]; then
61
  LDFLAGS="$LDFLAGS $shared -o $model.so"
62
else
63
  LDFLAGS="$LDFLAGS -o $model"
64
fi
65

  
66
if [ "$CXX" == "adcomp-x86_64-w64-mingw32" ]; then
67
  LDFLAGS="--static $LDFLAGS"
68
fi
69

  
70
CMD="$CXX $LDFLAGS $objects \"$ADMB_HOME\"/contrib/lib/libcontrib$opt.a \"$ADMB_HOME\"/lib/libadmb$opt.a"
71
echo $CMD
72
eval $CMD
73

  
74
if [ $? -ne 0 ]; then
75
  exit 1
76
fi
77

  
78
exit 0
79

  
80
### r259 [2012-02-29] arnima  logged revision history
81
### r 42 [2011-06-22] arnima  improved handling of LDFLAGS
82
### r 39 [2011-06-22] johnoel improved handling of LDFLAGS
83
### r982 [2010-02-16] arnima  rewrite, updated OPTIND structure, removed -O3,
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff