Browse code

configure: improve temp file creation and cleanup

Originally committed as revision 17752 to svn://svn.ffmpeg.org/ffmpeg/trunk

Måns Rullgård authored on 2009/03/03 17:53:55
Showing 1 changed files
... ...
@@ -257,7 +257,6 @@ Include the log file "$logfile" produced by configure as this will help
257 257
 solving the problem.
258 258
 EOF
259 259
     fi
260
-    rm -f $TMPC $TMPE $TMPH $TMPO $TMPS $TMPSH
261 260
     exit 1
262 261
 }
263 262
 
... ...
@@ -1342,12 +1341,33 @@ esac
1342 1342
 : ${TMPDIR:=$TMP}
1343 1343
 : ${TMPDIR:=/tmp}
1344 1344
 
1345
-TMPC="${TMPDIR}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.c"
1346
-TMPE="${TMPDIR}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}${EXESUF}"
1347
-TMPH="${TMPDIR}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.h"
1348
-TMPO="${TMPDIR}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.o"
1349
-TMPS="${TMPDIR}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.S"
1350
-TMPSH="${TMPDIR}/ffmpeg-conf-${RANDOM}-$$-${RANDOM}.sh"
1345
+if ! check_cmd type mktemp; then
1346
+    # simple replacement for missing mktemp
1347
+    # NOT SAFE FOR GENERAL USE
1348
+    mktemp(){
1349
+        echo "${2%XXX*}.${HOSTNAME}.${UID}.$$"
1350
+    }
1351
+fi
1352
+
1353
+tmpfile(){
1354
+    tmp=$(mktemp -u "${TMPDIR}/ffconf.XXXXXXXX")$2 &&
1355
+        (set -C; exec > $tmp) 2>/dev/null ||
1356
+        die "Unable to create temoporary file in $TMPDIR."
1357
+    append TMPFILES $tmp
1358
+    eval $1=$tmp
1359
+}
1360
+
1361
+trap 'rm -f -- $TMPFILES' EXIT
1362
+trap exit HUP INT TERM
1363
+
1364
+tmpfile TMPC  .c
1365
+tmpfile TMPE  $EXESUF
1366
+tmpfile TMPH  .h
1367
+tmpfile TMPO  .o
1368
+tmpfile TMPS  .S
1369
+tmpfile TMPSH .sh
1370
+
1371
+unset -f mktemp
1351 1372
 
1352 1373
 # make sure we can execute files in $TMPDIR
1353 1374
 cat > $TMPSH 2>> $logfile <<EOF
... ...
@@ -1361,7 +1381,6 @@ variable to another directory and make sure that it is not mounted noexec.
1361 1361
 EOF
1362 1362
     die "Sanity test failed."
1363 1363
 fi
1364
-rm $TMPSH
1365 1364
 
1366 1365
 if   $cc --version 2>/dev/null | grep -qi gcc; then
1367 1366
     cc_type=gcc
... ...
@@ -2484,8 +2503,6 @@ cmp -s $TMPH config.h &&
2484 2484
     echo "config.h is unchanged" ||
2485 2485
     mv -f $TMPH config.h
2486 2486
 
2487
-rm -f $TMPC $TMPE $TMPH $TMPO $TMPS $TMPSH
2488
-
2489 2487
 # build tree in object directory if source path is different from current one
2490 2488
 if enabled source_path_used; then
2491 2489
     DIRS="\