build.template

changeset 2
edeb8e8e02b6
parent 1
05a8e80e577e
child 3
9273d04a4d89
equal deleted inserted replaced
1:05a8e80e577e 2:edeb8e8e02b6
1 #!/bin/sh 1 #!/bin/sh
2 2
3 pwd 3 # some utility functions
4 isplatform()
5 {
6 for p in $PLATFORM
7 do
8 if [ "$p" = "$1" ]; then
9 return 0
10 fi
11 done
12 return 1
13 }
14 notisplatform()
15 {
16 for p in $PLATFORM
17 do
18 if [ "$p" = "$1" ]; then
19 return 1
20 fi
21 done
22 return 0
23 }
4 24
5 echo {{ .Path }} 25 # Simple uname based platform detection
6 echo TODO 26 # $PLATFORM is used for platform dependent dependency selection
27 OS=`uname -s`
28 OS_VERSION=`uname -r`
29 ARCH=`uname -m`
30 printf "detect platform... "
31 if [ "$OS" = "SunOS" ]; then
32 PLATFORM="solaris sunos unix svr4"
33 elif [ "$OS" = "Linux" ]; then
34 PLATFORM="linux unix"
35 elif [ "$OS" = "FreeBSD" ]; then
36 PLATFORM="freebsd bsd unix"
37 elif [ "$OS" = "OpenBSD" ]; then
38 PLATFORM="openbsd bsd unix"
39 elif [ "$OS" = "NetBSD" ]; then
40 PLATFORM="netbsd bsd unix"
41 elif [ "$OS" = "Darwin" ]; then
42 PLATFORM="macos osx bsd unix"
43 elif echo "$OS" | grep -i "MINGW" > /dev/null; then
44 PLATFORM="windows mingw"
45 fi
46 : ${PLATFORM:="unix"}
7 47
48 PLATFORM_NAME=`echo "$PLATFORM" | cut -f1 -d' ' -`
49 echo "$PLATFORM_NAME"
50
51 mkdir result
52 result_dir=`pwd`/result
53
54 configure_log=configure.log
55 compile_log=compile.log
56 check_log=check.log
57
58 result_file=`pwd`/result.json
59
60
61 echo "[" > $result_file
62
63 # repo source is always expected to be in src/
64 cd src
65 {{ $nbuild := len .Build }}
66 {{ range $i, $build := .Build}}
67 # Build isplatform="{{ .IsPlatform }}" not="{{ .NotPlatform }}"
68 while true
69 do
70 log_dir=$result_dir/build{{$i}}
71 mkdir -p $log_dir
72 if [ $? -ne 0 ]; then
73 echo "failed to create log dir $log_dir"
74 echo "abort"
75 exit 1
76 fi
77
78 {{- if .IsPlatform}}
79 if notisplatform "{{ $build.IsPlatform }}"; then
80 break
81 fi
82 {{- end}}
83 {{- range $build.NotList}}
84 if isplatform "{{.}}"; then
85 break
86 fi
87 {{- end}}
88
89 # configure
90 configure=
91 {{- if $build.Configure}}
92 {{ $build.Configure }} > $log_dir/$configure_log 2>&1
93 configure=$?
94 {{- end}}
95
96 # compile
97 compile=
98 {{- if $build.Compile}}
99 {{ $build.Compile }} > $log_dir/$compile_log 2>&1
100 compile=$?
101 {{- end}}
102
103 # check
104 check=
105 {{- if $build.Check}}
106 {{ $build.Check }} > $log_dir/$check_log 2>&1
107 check=$?
108 {{- end}}
109
110 # write result
111 echo "write result to $result_file"
112 echo "{ \"build\":\"{{$i}}\", " >> $result_file
113 if [ -n "$configure" ]; then
114 echo " \"configure\":\"$configure\"," >> $result_file
115 fi
116 if [ -n "compile" ]; then
117 echo " \"compile\":\"$compile\"," >> $result_file
118 fi
119 if [ -n "check" ]; then
120 echo " \"check\":\"$check\"" >> $result_file
121 fi
122 {{- if eq $i (sub $nbuild 1) }}
123 echo '}' >> $result_file
124 {{ else }}
125 echo '},' >> $result_file
126 {{- end }}
127 break
128 done
129 # End Build
130 {{ end}}
131
132 echo "]" >> $result_file
133

mercurial