Make the compiler/configure script idempotent.
authorTaylor R Campbell <campbell@mumble.net>
Mon, 2 Nov 2009 16:29:03 +0000 (11:29 -0500)
committerTaylor R Campbell <campbell@mumble.net>
Mon, 2 Nov 2009 16:29:03 +0000 (11:29 -0500)
src/compiler/configure

index e7f57d02393f6e6865a7c0a12e7cd2e214b5f9cd..c4e9ac5d6e1eac4c3a56d96e43eed72aff8c422a 100755 (executable)
@@ -42,11 +42,23 @@ while test $# -gt 0; do
 done
 MACHINE=`./choose-machine.sh "${MACHINE}"`
 
-CMD="rm -f machine"
-echo "${CMD}"; eval "${CMD}"
+make_link ()
+{
+    local target link
+    target="${1}"
+    link="${2}"
+    if [ -e "${link}" -a ! -L "${link}" ]; then
+       cat <<EOF >&2
+${link} is not a symbolic link; refusing to clobber it.
+EOF
+       exit 1
+    else
+       CMDS="rm -f ${link} && ln -s ${target} ${link}"
+       echo "${CMDS}"; eval "${CMDS}"
+    fi
+}
 
-CMD="ln -s machines/${MACHINE} machine"
-echo "${CMD}"; eval "${CMD}"
+make_link "machines/${MACHINE}" machine
 
 LINKS="compiler.cbf compiler.pkg compiler.sf make.com"
 if test "${MACHINE}" = C; then
@@ -54,8 +66,5 @@ if test "${MACHINE}" = C; then
 fi
 
 for FN in ${LINKS}; do
-    if [ ! -f "${FN}" ]; then
-       CMD="ln -s machine/${FN} ."
-       echo "${CMD}"; eval "${CMD}"
-    fi
+    make_link "machine/${FN}" "${FN}"
 done