From Roland Knall via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=9345
[metze/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
8 my %u3locs = qw(
9         $INSTDIR device
10         $INSTDIR\diameter device
11         $INSTDIR\dtds device
12         $INSTDIR\${GTK_ETC_DIR} host
13         $INSTDIR\${GTK_SCHEMAS_DIR} host
14         $INSTDIR\${GTK_ENGINES_DIR} host
15         $INSTDIR\${GTK_MODULES_DIR} host
16         $INSTDIR\etc\pango host
17         $INSTDIR\help device
18         $INSTDIR\platforms host
19         $INSTDIR\plugins\${VERSION} device
20         $INSTDIR\profiles\Bluetooth device
21         $INSTDIR\profiles\Classic device
22         $INSTDIR\radius device
23         $INSTDIR\snmp\mibs device
24         $INSTDIR\tpncp device
25         $INSTDIR\ui device
26         $INSTDIR\wimaxasncp device
27         );
28
29 my @dirs; # the directories in the manifest
30 my @defines; # stack of defines
31
32 while ($line = <>) {
33     $line =~ s/\r//g; # remove CR on Windows
34         if($line =~ /^SetOutPath (.+)$/) {
35         $outpath = $1;
36         $outpath =~ s/^'(.*)'$/$1/;
37         if($outpath ne '$PROFILE') { # ignore the PROFILE
38             push(@dirs, $outpath);
39         }
40     } elsif ($line =~ /!ifdef (.*)$/) {
41         push(@defines, $1);
42     } elsif ($line =~ /!endif/) {
43         pop(@defines);
44         if(scalar(@defines) == 0) {
45             undef @defines;
46         }
47     } elsif ($line =~/^File.*uninstall/i) {
48         next;
49     } elsif ($line =~ /^File[^\"]+\"([^\"]+)\"/) {
50         $file = $1;
51         # make things relative to the root rather than the NSIS directory
52         if($file =~ /^[^\.\$]/) { $file = "packaging\\nsis\\" . $file; }
53         $file =~ s/\.\.\\\.\.\\//; # remove ../../
54         push(@$outpath, $file);
55
56         if(defined @defines) {
57             push(@$file, "ifdef=" . $defines[-1]);
58         }
59
60         # there may be a parameter - copy it across
61         if($line =~ /\/(\S+)/) {
62             push(@$file, $1);
63         }
64     }
65 }
66
67 print "#\n# DO NOT EDIT - autogenerated from wireshark.nsi\n#\n";
68
69 foreach $dir(sort @dirs) {
70
71     if($prev ne $dir) {
72     print STDERR "looking for $dir\n";
73         $loc = $u3locs{$dir};
74
75         if(defined $loc) {
76
77             print "[". $dir . " u3loc=" . $loc . "]\n";
78
79             foreach $file(sort @$dir) {
80                 print "\t" . $file;
81
82                 foreach $param (sort(@$file)) {
83                     print " " . $param;
84                 }
85
86                 if($dir eq '$INSTDIR') { # try and find a better location
87                     if($file =~ /\.dll$|\.exe$|EXE}$|DLL}$/ && !($file =~ /WinPcap/) && !($file =~ /VCREDIST_EXE/)) {
88                         print " u3loc=host";
89                     }
90         }
91
92                 print "\n";
93             }
94         } else {
95
96             push(@ignored, $dir);
97
98         }
99     }
100     $prev = $dir;
101 }
102
103 if(defined @ignored) {
104
105     print STDERR "ERROR\nThe following directories have no known location on a U3 device:\n";
106
107     foreach $dir(sort @ignored) {
108         print STDERR "\t" . $dir . " ";
109     }
110
111     print STDERR "\n";
112
113     exit -1;
114 }