xref: /freebsd/crypto/openssl/util/mkdir-p.pl (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
1#!/usr/local/bin/perl
2
3# mkdir-p.pl
4
5# On some systems, the -p option to mkdir (= also create any missing parent
6# directories) is not available.
7
8my $arg;
9
10foreach $arg (@ARGV) {
11  $arg =~ tr|\\|/|;
12  &do_mkdir_p($arg);
13}
14
15
16sub do_mkdir_p {
17  local($dir) = @_;
18
19  $dir =~ s|/*\Z(?!\n)||s;
20
21  if (-d $dir) {
22    return;
23  }
24
25  if ($dir =~ m|[^/]/|s) {
26    local($parent) = $dir;
27    $parent =~ s|[^/]*\Z(?!\n)||s;
28
29    do_mkdir_p($parent);
30  }
31
32  mkdir($dir, 0777) || die "Cannot create directory $dir: $!\n";
33  print "created directory `$dir'\n";
34}
35