Slightly better basic type detection.
[sxemacs] / contrib / do_builds.sh
1 #!/bin/sh
2 #
3 # A script to do automatic builds with several different configurations
4 #
5 # (C) 2008 Nelson Ferreira
6
7 #  
8 # This program is free software; you can redistribute it and/or modify it
9 # under a BSD-like licence.
10 #
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions are met:
13 # Redistributions of source code must retain the above copyright notice, this
14 # list of conditions and the following disclaimer.
15 # Redistributions in binary form must reproduce the above copyright notice,
16 # this list of conditions and the following disclaimer in the documentation
17 # and/or other materials provided with the distribution.
18 # Neither the name of the Technical University of Berlin nor the names of its
19 # contributors may be used to endorse or promote products derived from this
20 # software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 # POSSIBILITY OF SUCH DAMAGE.
33
34 function do_log {
35     if [ -n "$LOG_FILE" ]; then
36         echo "$0 $(date): $@" >> $LOG_FILE
37     fi
38 }
39
40 if [ ! -f ./,,conf ]; then
41     cat > ./,,conf <<EOF
42 # --*-shell-script-*--
43 #
44 # The path to the SXEmacs source
45 SOURCE=/path/to/sxemacs
46 #
47 # Hammer value when doing autogen.sh [Check it for more details
48 HAMMER=""
49 #
50 # Autogen command [leave empty in order to skip it]
51 AUTOGEN="./autogen.sh"
52 #
53 # The command line arguments to pass to the make command
54 MAKE_ARGS="time-build-report"
55 #
56 # File to log progress to
57 LOG_FILE=",,build.log"
58 #
59 # Make a ++TAGS directory
60 MAKE_TAGS=""
61 #
62 # Remove the build directory when build is successful
63 # (and after reporting...) ?
64 # Yes or Y
65 REMOVE_ON_SUCCESS=""
66 #
67 # Report the build status with an email? 
68 # Yes or Y (All)
69 # Failures or F (Failures only)
70 # Success or S  (Successes only)
71 # Anything else - No reports at all
72 REPORT_STATUS="Yes"
73 #
74 # Send success email to this address instead of sxemacs-devel@sxemacs.org
75 MAIL_SUCCESS_TO=""
76 #
77 # Send failure email to this address instead of sxemacs-devel@sxemacs.org
78 MAIL_FAILURE_TO=""
79 #
80 # The email should come from this email address
81 # [ $USER@$(hostname -f  2> /dev/null || (hostname ; domainname)) will be used otherwise
82 MAIL_FROM=""
83 EOF
84     echo "Please review the generated ,,conf file and rerun."
85     exit 1
86 fi
87 source ./,,conf
88 if [ -z "${SOURCE}" -o ! -d "${SOURCE}" -o ! -f ${SOURCE}/sxemacs.pc.in ]; then
89     echo "No SXEmacs source found at ${SOURCE}"
90     exit 1
91 fi
92 if [ -z "${MAIL_FROM}" ]; then
93     MAIL_FROM="${USER}@$(hostname -f 2> /dev/null || (hostname ; domainname))"
94     echo "WARNING: No mail from defined. Will use ${MAIL_FROM} instead."
95 fi
96 STATUS=""
97 if [ -n "${AUTOGEN}"  ]; then
98     CURDIR="$(pwd)"
99     cd "${SOURCE}" 
100     PREFIX=$(pwd)
101     if [ -n "${HAMMER}" ]; then
102         echo HAMMER: ${HAMMER}
103     fi
104     (export HAMMER ; ${AUTOGEN} ) || STATUS=FAIL_AUTOGEN
105     cd "$CURDIR"
106 fi
107 if [ -n "${STATUS}" ]; then
108     do_log "Failure: ${STATUS}"
109     exit 1
110 fi
111 if [ -n "${BUILD_TAGS}" ]; then
112     # Let's build ourselfs the tags for this source tree,
113     mkdir -p ./++TAGS
114     CURDIR="$(pwd)"
115     cd ./++TAGS 
116     eval "${PREFIX}/configure" || STATUS="FAIL_CONFIGURE_$?"
117     if [ -z "${STATUS}" ]; then
118         make tags || STATUS="FAIL_TAGS_$?"
119     fi
120     cd "$CURDIR"
121 fi
122 if [ -n "${STATUS}"  ]; then
123     do_log "Failure: ${STATUS}"
124     exit 1
125 fi
126 for f in *.conf; do
127     if [ "$f" = "*.conf" ]; then
128         echo "Nothing to do - create some .conf files! "
129         exit 1
130     fi
131     STATUS=""
132     CONF_OPTS="$(cat $f)"
133     build_name="$(echo ${f} |sed 's/\.conf$//')"
134     do_log "Started building ${build_name}"
135     if [ -d "./${build_name}" ]; then
136         /bin/rm -rf "./${build_name}"
137     fi
138     mkdir -p "./${build_name}"
139     CURDIR="$(pwd)"
140     cd "./${build_name}" 
141     eval "${PREFIX}/configure ${CONF_OPTS}" || STATUS="FAIL_CONFIGURE_$?"
142     if [ "${STATUS}" = "FAIL_CONFIGURE_127" -a -f "./Installation" -a -f "./config.log" ]; then
143         if [ $(tail -1 ./config.log) = "configure: exit 0" ]; then
144             STATUS="FAIL_CONFIGURE_0"
145         fi
146     fi
147     if [ -z "${STATUS}" -o "${STATUS}" = "FAIL_CONFIGURE_0" ]; then
148         STATUS="Success"
149         make ${MAKE_ARGS} || STATUS="FAIL_MAKE_$?"
150         if [ "${STATUS}" = "FAIL_MAKE_0" ]; then
151             STATUS="Success"
152         fi
153         if egrep '^make.*:.*Error' ,,beta.out; then
154             STATUS="${STATUS}_ERROR_IN_BUILD"
155         else
156             if [ -f ,,make-check.out ]; then
157                 if [ ! "${STATUS}" = "Success" ]; then
158                     STATUS="Tests fail"
159                 elif [ -n "$(grep 'tests successful' ,,make-check.out | grep -v 100%)" ]; then
160                     STATUS="Sucess(Some tests fail)"
161                 fi
162             fi
163         fi
164     fi
165     DO_REPORT_FAILURE=""
166     REPORT_THIS="No"
167     if [ "${REPORT_STATUS}" = "Yes" -o  "${REPORT_STATUS}" = "Y" ]; then
168         REPORT_THIS="Yes"
169     elif [ "${STATUS}" = "Success" -o "${STATUS}" = "Sucess(Some tests fail)" ]; then
170         if [ "${REPORT_STATUS}" = "Success" -o  "${REPORT_STATUS}" = "S" ]; then
171             REPORT_THIS="Yes"
172         fi
173     elif [ "${REPORT_STATUS}" = "Failures" -o  "${REPORT_STATUS}" = "F" ]; then
174         REPORT_THIS="Yes"
175     fi
176     if [ "${REPORT_THIS}" = "Yes" ]; then
177         if [ "${STATUS}" = "Success" -o "${STATUS}" = "Tests fail" -o "${STATUS}" = "Sucess(Some tests fail)" ]; then
178             # First test if can actually send email from SXEmacs, otherwise just give up :-)
179             CLI=" -eval \"(unless (fboundp 'mail-send-and-exit) (kill-emacs 2))\""
180             if [ -n "${MAIL_FROM}" ]; then
181                 CLI="${CLI} -eval '(setq user-mail-address \"$MAIL_FROM\")'"
182             fi
183             if [ -n "$MAIL_SUCCESS_TO" ]; then
184                 CLI="${CLI} -eval '(setq build-rpt-email \"${MAIL_SUCCESS_TO}\")'"
185             fi
186             CLI="${CLI} -eval '(if (send-build-rpt \"${STATUS}\") (kill-emacs 0) (kill-emacs 1))'"
187             eval "src/sxemacs -batch ${CLI}" || DO_REPORT_FAILURE="YES" STATUS="${STATUS}-Build-Rpt-Failed-$?" 
188         else
189             DO_REPORT_FAILURE="YES"
190         fi
191         if [ "${DO_REPORT_FAILURE}" = "YES" ]; then
192             ${PREFIX}/contrib/report-build-failure.sh "${MAIL_FROM}" "${MAIL_FAILURE_TO}" "${STATUS}"
193         fi
194     fi
195     cd "$CURDIR"
196     if [ "${STATUS}" = "Success" ]; then
197         if [ "${REMOVE_ON_SUCCESS}" = "Yes" -o "${REMOVE_ON_SUCCESS}" = "Y" ]; then
198             /bin/rm -rf "./${build_name}"
199         fi
200     fi
201     do_log "Finished building ${build_name}: ${STATUS}"
202 done
203