Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I automatically create (and remove) a temp directory in a Makefile?

Is it possible to have make create a temp directory before it executes the first target? Maybe using some hack, some additional target etc.?

All commands in the Makefile would be able to refer to the automatically created directory as $TMPDIR, and the directory would be automatically removed when the make command ends.

like image 409
Frank Avatar asked Feb 26 '09 05:02

Frank


1 Answers

With GNU make, at least,

TMPDIR := $(shell mktemp -d)

will get you your temporary directory. I can't come up with a good way to clean it up at the end, other than the obvious rmdir "$(TMPDIR)" as part of the all target.

like image 109
derobert Avatar answered Sep 23 '22 07:09

derobert