A script to generate a generic manifest file from the nsis/wireshark.nsi.
[obnox/wireshark/wip.git] / packaging / ws-manifest.pl
1 #
2 # ws-manifest.pl - create a generic manifest file (including u3 information) from the wireshark.nsi 
3 # $Id$
4 #
5
6 # These are the known directories in the distribution and where they should live on a U3 device
7 my %u3locs = qw($INSTDIR device
8                 $INSTDIR\plugins\${VERSION} device
9                 $INSTDIR\help device
10                 $INSTDIR\snmp\mibs device
11                 $INSTDIR\diameter device
12                 $INSTDIR\dtds device
13                 $INSTDIR\radius device
14                 $INSTDIR\wimaxasncp device
15                 $INSTDIR\tpncp device
16                 $INSTDIR\${GTK_WIMP_RCDST_DIR} host
17                 $INSTDIR\etc\gtk-2.0 host
18                 $INSTDIR\etc\pango host
19                 $INSTDIR\lib\gtk-2.0\${GTK2_LIB_DIR}\immodules host
20                 $INSTDIR\${GTK_WIMP_DLLDST_DIR} host);
21
22 my @dirs; # the directories in the manifest
23 my @defines; # stack of defines
24
25 while ($line = <>) {
26     if($line =~ /^SetOutPath (.+)$/) {
27         $outpath = $1;
28         if($outpath ne '$PROFILE') { # ignore the PROFILE
29             push(@dirs, $outpath);
30         }
31     } elsif ($line =~ /!ifdef (.*)$/) {
32         push(@defines, $1);
33     } elsif ($line =~ /!endif/) {
34         pop(@defines);
35         if(scalar(@defines) == 0) {
36             undef @defines;
37         }
38     } elsif ($line =~ /^File[^\"]+\"([^\"]+)\"/) {
39         $file = $1;
40         # make things relative to the root rather than the NSIS directory
41         if($file =~ /^[^\.\$]/) { $file = "packaging\\nsis\\" . $file; }
42         $file =~ s/\.\.\\\.\.\\//; # remove ../../
43         push(@$outpath, $file);
44
45         if(defined @defines) {
46             push(@$file, "ifdef=" . $defines[-1]);
47         }
48
49         # there may be a parameter - copy it across
50         if($line =~ /\/(\S+)/) {
51             push(@$file, $1);
52         }
53     }
54 }
55
56 print "#\n# DO NOT EDIT - autogenerated from wireshark.nsi\n#\n";
57
58 foreach $dir(sort @dirs) {
59
60     if($prev ne $dir) {
61         $loc = $u3locs{$dir};
62
63         if(defined $loc) { 
64             
65             print "[". $dir . " u3loc=" . $loc . "]\n";
66
67             foreach $file(sort @$dir) {
68                 print "\t" . $file;
69
70                 foreach $param (sort(@$file)) {
71                     print " " . $param;
72                 }
73
74                 if($dir eq '$INSTDIR') { # try and find a better location
75                     if($file =~ /\.dll$|\.exe$|EXE}$|DLL}$/) {
76                         print " u3loc=host";
77                     }
78                 } 
79
80                 print "\n";
81             }
82         } else {
83             
84             push(@ignored, $dir);
85             
86         }
87     }
88     $prev = $dir;
89 }
90
91 if(defined @ignored) {
92
93     print STDERR "ERROR\nThe following directories have no known location on a U3 device:\n";
94
95     foreach $dir(sort @ignored) {
96         print STDERR "\t" . $dir . " ";
97     }
98     
99     print STDERR "\n";
100
101     exit -1;
102 }