summaryrefslogtreecommitdiff
path: root/bin/create_ace_build
blob: 415bcb5155db653e37afc3328809ce5eb5ebb912 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# $Id$
#
# Creates an ACE build tree in directory "build/<build name>" below the current
# directory, which must be an ACE "top level" directory (such as
# $ACE_ROOT).  The build tree directory structure mirrors that of the ACE
# top level directory structure, except that instead of containing any plain
# files, it contains only symlinks to the files in the ACE top level structure.
#
# This program has a similar purpose to "clone", but in addition to
# only creating symlinks (clone creates hard links, by default), this
# script:
# 1) uses relative rather than absolute symlinks,
# 2) tries not to put junk files into the build tree,
# 3) only creates a new tree in a build/ directory below the current,
#    top level ACE directory (it's a feature :-), but it does enforce
#    consistency).
#
# This program can be re-run on a build tree at any time in order to
# update it.  It will only add new symlinks, it won't remove any that
# are no longer valid.  If you want to do that, it's easiest just to
# remove the build completely and start from scratch.
#
# If the <build name> starts with "build/", that part will be removed
# from it.
#
# The first three lines above let this script run without specifying the
# full path to perl, as long as it is in the user's PATH.
# Taken from perlrun man page.

$usage = "usage: $0 -? | [-a] [-d <directory mode>] [-v] <build name>\n";
$directory_mode = 042755;   #### fine on Suns, but maybe not all Unix platforms
$verbose = 0;

$source='.';
$absolute= 0;

require Cwd;

####
#### process command line args
####
while ( $#ARGV >= 0  &&  $ARGV[0] =~ /^-/ ) {
    if ( $ARGV[0] eq '-v' ) {
        $verbose = 1;
    } elsif ( $ARGV[0] eq '-d' ) {
        if ( $ARGV[1] =~ /^\d+$/ ) {
            $directory_mode = $ARGV[1]; shift;
        } else {
            warn "$0:  must provide argument for -d option\n";
            die $usage;
        }
    } elsif ($ARGV[0] eq '-a' ) {
	$source = Cwd::getcwd();
	$absolute = 1;
    } elsif ( $ARGV[0] eq '-?' ) {
        print "$usage";
        exit;
    } else {
        warn "$0:  unknown option $ARGV[0]\n";
        die $usage;
    }
    shift;
}

die $usage unless $#ARGV == 0;
$build = $ARGV[0];
$build =~ s%^build/%%;        #### remove leading "build/", if any
$build = "build/$build";

####
#### check that we're in an ACE "top level" directory
####
( -d 'ace' && -d 'examples' && -d 'netsvcs' )  ||
    die "$0:  must be in an ACE top level (ACE_ROOT) directory!\n";

####
#### Create build directories, if needed.
####
-d 'build'  ||  mkdir 'build', $directory_mode;
-d "$build"  ||  mkdir "$build", $directory_mode;

####
#### Get all ACE plain file and directory names.
####
@files = ( `/usr/bin/find . -name CVS -prune \\\
	-o -name build -prune -o \\\
    -name '.*obj' -prune -o -name Templates.DB -prune -o \\\
    \\( ! -type l ! -name core ! -name '*.state' ! -name '*.so' \\\
    ! -name '*.[oa]' ! -name '*~' ! -name '.' ! -name '.#*' \\\
    ! -name '*.log' \\) \\\
    -print` );

####
#### Create directories and symlinks to files.
####
foreach $file ( @files ) {
   chop $file;         #### remove trailing newline (from find command above)
   $file =~ s%^./%%g;  #### excise leading ./ directory component

   if ( -d $file ) {
        unless ( -d "$build/$file" ) {
            print "mkdir $build/$file, $directory_mode\n" if $verbose;
            mkdir "$build/$file", $directory_mode;
        }
    } else {
        unless ( -e "$build/$file" ) {
	    if (!$absolute) {
		$up = '../..';
		while ( $file =~ m%/%g ) { $up .= '/..'; }
		
		print "symlink $up/$file $build/$file\n" if $verbose;
		symlink "$up/$file", "$build/$file"  ||
                die "$0 symlink to $build/$file failed\n";
	    } else {
		$path = $source . '/' . $file;
		print "symlink $path $build/$file\n" if $verbose;
		symlink "$path", "$build/$file"
		    || die "$0 symlink to $build/$file failed\n";
	    }
        }
    }
}

####
#### Done: print message.
####
print "\nCompleted creation of $build/.\n";

unless ( -e "$build/ace/config.h"  &&
         -e "$build/include/makeinclude/platform_macros.GNU" ) {
    print "Be sure to setup $build/ace/config.h and\n" .
          "$build/include/makeinclude/platform_macros.GNU symlinks.\n";
}

#### EOF