Implement conversions between dates and strings.
[wine] / programs / make_progs
1 #!/usr/bin/perl -w
2 #
3 # Update the dependencies in the programs main Makefile.in.
4 # Must be run in the programs/ directory of the Wine tree.
5 #
6 # Copyright 2003 Alexandre Julliard
7 #
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 #
22
23 use strict;
24
25 my $makefiles = `find . -name Makefile.in -print`;
26
27 my %directories = ();
28
29 # Programs that we want to install in the bin directory too
30 my %bin_install =
31 (
32   "notepad" => 1,
33   "progman" => 1,
34   "regedit" => 1,
35   "regsvr32" => 1,
36   "uninstaller" => 1,
37   "wcmd" => 1,
38   "wineboot" => 1,
39   "winecfg" => 1,
40   "wineconsole" => 1,
41   "winedbg" => 1,
42   "winefile" => 1,
43   "winemine" => 1,
44   "winepath" => 1,
45   "winhelp" => 1,
46 );
47
48 # Programs that we don't want to install at all
49 my %dont_install =
50 (
51   "cmdlgtst" => 1,
52   "view" => 1,
53 );
54
55 foreach my $i (split(/\s/,$makefiles))
56 {
57     my $module;
58
59     next if $i =~ /\/tests\/Makefile.in/;
60
61     open MAKE,$i;
62
63     $module = undef;
64     while (<MAKE>)
65     {
66         chop;
67         # hack to disable this program... the MKPROG_SKIP comment must appear
68         # at the very top of the Makefile.in
69         last if (/^\#\s*MKPROG_SKIP/);
70
71         if (/^MODULE\s*=\s*([a-zA-Z0-9_.]+)/)
72         {
73             $module = $1;
74             next if ($module eq "none");
75             ($directories{$module} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
76             last;
77         }
78         if (/^PROGRAMS\s*=((\s*[a-zA-Z0-9_.]+)+)/)
79         {
80             my @programs = split / /, $1;
81             foreach my $prog (@programs)
82             {
83                 next unless $prog =~ /\.exe$/;
84                 ($directories{$prog} = $i) =~ s/^\.\/(.*)\/[^\/]+$/$1/;
85             }
86             last;
87         }
88     }
89     close MAKE;
90 }
91
92 open NEWMAKE,">Makefile.in.new" or die "cannot create Makefile.in.new";
93
94 ################################################################
95 # makefile header
96
97 print NEWMAKE <<EOF;
98 # Automatically generated by make_progs; DO NOT EDIT!!
99
100 TOPSRCDIR = \@top_srcdir\@
101 TOPOBJDIR = ..
102 SRCDIR    = \@srcdir\@
103 VPATH     = \@srcdir\@
104
105 EOF
106
107 ################################################################
108 # output the subdirs list
109
110 # get rid of duplicates
111 my %alldirs = ();
112 foreach my $dir (sort values %directories) { $alldirs{$dir} = 1; }
113
114 print NEWMAKE "SUBDIRS =";
115 foreach my $dir (sort keys %alldirs)
116 {
117     printf NEWMAKE " \\\n\t%s", $dir;
118 }
119
120 print NEWMAKE "\n\n# Sub-directories to run make install into\nINSTALLSUBDIRS =";
121 foreach my $dir (sort keys %alldirs)
122 {
123     next if $dont_install{$dir};
124     printf NEWMAKE " \\\n\t%s", $dir;
125 }
126
127 print NEWMAKE "\n\n# Programs to install in bin directory\nINSTALLPROGS =";
128 foreach my $dir (sort keys %alldirs)
129 {
130     printf NEWMAKE " \\\n\t%s", $dir if $bin_install{$dir};
131 }
132
133 print NEWMAKE "\n\n# Symlinks to apps that we want to run from inside the source tree\nSYMLINKS =";
134 foreach my $mod (sort keys %directories)
135 {
136     printf NEWMAKE " \\\n\t%s", $mod;
137 }
138
139 ################################################################
140 # output the build and install targets
141
142 print NEWMAKE <<EOF;
143
144
145 \@MAKE_RULES\@
146
147 all: wineapploader winelauncher \$(SUBDIRS) \$(SYMLINKS:%=%\$(DLLEXT))
148
149 wineapploader: wineapploader.in
150         sed -e 's,\@bindir\\\@,\$(bindir),g' \$(SRCDIR)/wineapploader.in >\$\@ || (\$(RM) \$\@ && false)
151
152 winelauncher: winelauncher.in
153         sed -e 's,\@bindir\\\@,\$(bindir),g' -e 's,\@libdir\\\@,\$(libdir),g' -e 's,\@dlldir\\\@,\$(dlldir),g' \$(SRCDIR)/winelauncher.in >\$\@ || (\$(RM) \$\@ && false)
154
155 # Rules for installation
156
157 .PHONY: install-apploader install-progs install-progs.so \$(INSTALLPROGS:%=%/__installprog__)
158
159 install-apploader: wineapploader dummy
160         \$(MKINSTALLDIRS) \$(bindir)
161         \$(INSTALL_SCRIPT) wineapploader \$(bindir)/wineapploader
162
163 \$(INSTALLPROGS:%=%/__installprog__): install-apploader
164         \$(RM) \$(bindir)/`dirname \$\@` && \$(LN) \$(bindir)/wineapploader \$(bindir)/`dirname \$\@`
165
166 install-progs.so: \$(INSTALLPROGS:%=%/__installprog__)
167         \$(RM) \$(bindir)/wineapploader
168
169 install-progs: # nothing to do here
170
171 install:: winelauncher install-progs\$(DLLEXT)
172         \$(MKINSTALLDIRS) \$(bindir)
173         \$(INSTALL_SCRIPT) winelauncher \$(bindir)/winelauncher
174
175 uninstall::
176         \$(RM) \$(bindir)/wineapploader \$(bindir)/winelauncher \$(INSTALLPROGS:%=\$(bindir)/%)
177         -rmdir \$(dlldir)
178
179 clean::
180         \$(RM) wineapploader winelauncher \$(SYMLINKS)
181
182 # Rules for testing
183
184 check test:: \$(SUBDIRS:%=%/__test__)
185
186 EOF
187
188 ################################################################
189 # output the symlinks rules
190
191 print NEWMAKE "# Rules for symlinks\n\n";
192
193 foreach my $mod (sort keys %directories)
194 {
195     printf NEWMAKE "%s\$(DLLEXT)", $mod;
196     printf NEWMAKE ": %s/%s\$(DLLEXT)\n", $directories{$mod}, $mod;
197     printf NEWMAKE "\t\$(RM) \$@ && \$(LN_S) %s/%s\$(DLLEXT) \$@\n\n", $directories{$mod}, $mod;
198 }
199
200 foreach my $mod (sort keys %directories)
201 {
202     printf NEWMAKE "%s/%s\$(DLLEXT): %s\n", $directories{$mod}, $mod, $directories{$mod};
203 }
204
205 ################################################################
206 # makefile trailer
207
208 print NEWMAKE "\n### Dependencies:\n";
209
210 close NEWMAKE;
211 rename "Makefile.in.new", "Makefile.in";
212 printf "Successfully updated Makefile.in\n";