Imported Upstream version 3.13.6
[platform/upstream/nss.git] / mozilla / security / coreconf / jniregen.pl
1 #!/usr/local/bin/perl
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 #
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
10 #
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
15 #
16 # The Original Code is the Netscape security libraries.
17 #
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1994-2000
21 # the Initial Developer. All Rights Reserved.
22 #
23 # Contributor(s):
24 #
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
36 #
37 # ***** END LICENSE BLOCK *****
38
39 # Input: -d dir -j javahcmd foo1 foo2 . . .
40 #        Compares generated "_jni/foo1.h" file with "foo1.class", and
41 #        generated "_jni/foo2.h" file with "foo2.class", etc.
42 #        (NOTE:  unlike its closely related cousin, outofdate.pl,
43 #                the "-d dir" must always be specified)
44 #        Runs the javahcmd on all files that are different.
45 #
46 # Returns: list of headers which are OLDER than corresponding class
47 #          files (non-existent class files are considered to be real old :-)
48
49 my $javah = "";
50 my $classdir = "";
51
52 while(1) {
53     if ($ARGV[0] eq '-d') {
54         $classdir = $ARGV[1];
55         $classdir .= "/";
56         shift;
57         shift;
58     } elsif($ARGV[0] eq '-j') {
59         $javah = $ARGV[1];
60         shift;
61         shift;
62     } else {
63         last;
64     }
65 }
66
67 if( $javah  eq "") {
68     die "Must specify -j <javah command>";
69 }
70 if( $classdir eq "") {
71     die "Must specify -d <classdir>";
72 }
73
74 foreach $filename (@ARGV)
75 {
76     $headerfilename = "_jni/";
77     $headerfilename .= $filename;
78     $headerfilename =~ s/\./_/g;
79     $headerfilename .= ".h";
80
81     $classfilename = $filename;
82     $classfilename =~ s|\.|/|g;
83     $classfilename .= ".class";
84
85     $classfilename = $classdir . $classfilename;
86
87
88     ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $headermtime,
89       $ctime, $blksize, $blocks ) = stat( $headerfilename );
90
91     ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $classmtime,
92       $ctime, $blksize, $blocks ) = stat( $classfilename );
93
94     if( $headermtime < $classmtime )
95     {
96         # NOTE:  Since this is used by "javah", and "javah" refuses to overwrite
97         #        an existing file, we force an unlink from this script, since
98         #        we actually want to regenerate the header file at this time.
99         unlink $headerfilename;
100         push @filelist, $filename;
101     }
102 }
103
104 if( @filelist ) {
105     $cmd = "$javah " . join(" ",@filelist);
106     $cmd =~ s/\'/\"/g;  # because windows doesn't understand single quote
107     print "$cmd\n";
108     exit (system($cmd) >> 8);
109 } else {
110     print "All JNI header files up to date.\n"
111 }