Move some static makefile variables to rules.mk.
[ira/wip.git] / source / build / smb_build / makefile.pm
1 # Samba Build System
2 # - create output for Makefile
3 #
4 #  Copyright (C) Stefan (metze) Metzmacher 2004
5 #  Copyright (C) Jelmer Vernooij 2005
6 #  Released under the GNU GPL
7
8 package smb_build::makefile;
9 use smb_build::env;
10 use smb_build::output;
11 use File::Basename;
12 use strict;
13
14 use base 'smb_build::env';
15 use Cwd 'abs_path';
16
17 sub new($$$)
18 {
19         my ($myname, $config, $mkfile) = @_;
20         my $self = new smb_build::env($config);
21         
22         bless($self, $myname);
23
24         $self->{manpages} = [];
25         $self->{sbin_progs} = [];
26         $self->{bin_progs} = [];
27         $self->{torture_progs} = [];
28         $self->{static_libs} = [];
29         $self->{python_dsos} = [];
30         $self->{python_pys} = [];
31         $self->{shared_libs} = [];
32         $self->{installable_shared_libs} = [];
33         $self->{headers} = [];
34         $self->{shared_modules} = [];
35         $self->{plugins} = [];
36         $self->{install_plugins} = "";
37         $self->{uninstall_plugins} = "";
38         $self->{pc_files} = [];
39         $self->{proto_headers} = [];
40         $self->{output} = "";
41
42         $self->{mkfile} = $mkfile;
43
44         $self->output("#!gmake\n");
45         $self->output("################################################\n");
46         $self->output("# Autogenerated by build/smb_build/makefile.pm #\n");
47         $self->output("################################################\n");
48         $self->output("\n");
49
50         $self->output("default: all\n\n");
51
52         $self->_prepare_path_vars();
53         $self->_prepare_suffix_rules();
54         $self->_prepare_compiler_linker();
55
56         if (!$self->{automatic_deps}) {
57                 $self->output("ALL_PREDEP = proto\n");
58                 $self->output(".NOTPARALLEL:\n");
59         }
60
61         return $self;
62 }
63
64 sub output($$)
65 {
66         my ($self, $text) = @_;
67
68         $self->{output} .= $text;
69 }
70
71 sub _prepare_path_vars($)
72 {
73         my ($self) = @_;
74
75         $self->output(<< "__EOD__"
76 prefix = $self->{config}->{prefix}
77 exec_prefix = $self->{config}->{exec_prefix}
78 selftest_prefix = $self->{config}->{selftest_prefix}
79
80 builddir = $self->{config}->{builddir}
81 srcdir = $self->{config}->{srcdir}
82 datarootdir = $self->{config}->{datarootdir}
83
84 VPATH = \$(builddir):\$(srcdir):heimdal_build:heimdal/lib/asn1:heimdal/lib/krb5:heimdal/lib/gssapi:heimdal/lib/hdb:heimdal/lib/roken:heimdal/lib/des
85
86 BASEDIR = $self->{config}->{prefix}
87 BINDIR = $self->{config}->{bindir}
88 SBINDIR = $self->{config}->{sbindir}
89 LIBDIR = $self->{config}->{libdir}
90 TORTUREDIR = $self->{config}->{libdir}/torture
91 MODULESDIR = $self->{config}->{modulesdir}
92 INCLUDEDIR = $self->{config}->{includedir}
93 CONFIGDIR = $self->{config}->{sysconfdir}
94 DATADIR = $self->{config}->{datadir}
95 SWATDIR = \$(DATADIR)/swat
96 JSDIR = \$(DATADIR)/js
97 SETUPDIR = \$(DATADIR)/setup
98 VARDIR = $self->{config}->{localstatedir}
99 LOGFILEBASE = $self->{config}->{logfilebase}
100 NCALRPCDIR = $self->{config}->{localstatedir}/ncalrpc
101 LOCKDIR = $self->{config}->{lockdir}
102 PIDDIR = $self->{config}->{piddir}
103 MANDIR = $self->{config}->{mandir}
104 PRIVATEDIR = $self->{config}->{privatedir}
105 WINBINDD_SOCKET_DIR = $self->{config}->{winbindd_socket_dir}
106
107 __EOD__
108 );
109 }
110
111 sub _prepare_suffix_rules($)
112 {
113         my ($self) = @_;
114         my $first_prereq = '$*.c';
115
116         if ($self->{config}->{GNU_MAKE} eq 'yes') {
117                 $first_prereq = '$<';
118         }
119
120         $self->output(<< "__EOD__"
121 FIRST_PREREQ = $first_prereq
122
123 __EOD__
124 );
125 }
126
127 sub _prepare_compiler_linker($)
128 {
129         my ($self) = @_;
130
131         my $builddir_headers = "";
132         my $libdir;
133         my $extra_link_flags = "";
134
135         if ($self->{config}->{USESHARED} eq "true") {
136                 $libdir = "\$(builddir)/bin/shared";
137                 $extra_link_flags = "-Wl,-rpath-link,\$(builddir)/bin/shared";
138         } else {
139                 $libdir = "\$(builddir)/bin/static";
140         }
141         
142         if (!(abs_path($self->{config}->{srcdir}) eq abs_path($self->{config}->{builddir}))) {
143             $builddir_headers= "-I\$(builddir)/include -I\$(builddir) -I\$(builddir)/lib ";
144         }
145
146         $self->output(<< "__EOD__"
147 SHELL=$self->{config}->{SHELL}
148
149 PERL=$self->{config}->{PERL}
150 PYTHON=$self->{config}->{PYTHON}
151 SWIG=$self->{config}->{SWIG}
152
153 CPP=$self->{config}->{CPP}
154 CPPFLAGS=$builddir_headers-I\$(srcdir)/include -I\$(srcdir) -I\$(srcdir)/lib -I\$(srcdir)/lib/replace -I\$(srcdir)/lib/talloc -D_SAMBA_BUILD_=4 -DHAVE_CONFIG_H $self->{config}->{CPPFLAGS}
155
156 CC=$self->{config}->{CC}
157 CFLAGS=$self->{config}->{CFLAGS}
158 CFLAG_NO_UNUSED_MACROS=$self->{config}->{CFLAG_NO_UNUSED_MACROS}
159 PICFLAG=$self->{config}->{PICFLAG}
160
161 INSTALL_LINK_FLAGS=$extra_link_flags
162
163 BNLD=$self->{config}->{LD} 
164 BNLD_FLAGS=$self->{config}->{LDFLAGS} -L$libdir
165
166 STLD=$self->{config}->{STLD}
167 STLD_FLAGS=$self->{config}->{STLD_FLAGS}
168
169 SHLD=$self->{config}->{SHLD}
170 SHLD_FLAGS=$self->{config}->{SHLD_FLAGS} -L\$(builddir)/bin/shared
171
172 MDLD=$self->{config}->{MDLD}
173 MDLD_FLAGS=$self->{config}->{MDLD_FLAGS} -L\$(builddir)/bin/shared
174
175 SHLIBEXT=$self->{config}->{SHLIBEXT}
176
177 HOSTCC=$self->{config}->{HOSTCC}
178 HOSTCC_FLAGS=-D_SAMBA_HOSTCC_ \$(CFLAGS)
179
180 HOSTLD=$self->{config}->{HOSTLD}
181 HOSTLD_FLAGS=$self->{config}->{LDFLAGS}
182
183 XSLTPROC=$self->{config}->{XSLTPROC}
184
185 LIB_PATH_VAR=$self->{config}->{LIB_PATH_VAR}
186
187 LEX=$self->{config}->{LEX}
188 YACC=$self->{config}->{YACC}
189 YAPP=$self->{config}->{YAPP}
190
191 GCOV=$self->{config}->{GCOV}
192
193 DEFAULT_TEST_OPTIONS=$self->{config}->{DEFAULT_TEST_OPTIONS}
194
195 __EOD__
196 );
197 }
198
199 sub _prepare_mk_files($)
200 {
201         my $self = shift;
202         my @tmp = ();
203
204         foreach (@smb_build::config_mk::parsed_files) {
205                 s/ .*$//g;
206                 push (@tmp, $_);
207         }
208
209         if ($self->{gnu_make}) {
210                 $self->output("
211 ifneq (\$(MAKECMDGOALS),clean)
212 ifneq (\$(MAKECMDGOALS),distclean)
213 ifneq (\$(MAKECMDGOALS),realdistclean)
214 ");
215         }
216
217         $self->output("MK_FILES = " . array2oneperline(\@tmp) . "\n");
218
219         if ($self->{gnu_make}) {
220                 $self->output("
221 endif
222 endif
223 endif
224 ");
225         }
226 }
227
228 sub array2oneperline($)
229 {
230         my $array = shift;
231         my $output = "";
232
233         foreach (@$array) {
234                 next unless defined($_);
235
236                 $output .= " \\\n\t\t$_";
237         }
238
239         return $output;
240 }
241
242 sub _prepare_list_ex($$$$$)
243 {
244         my ($self,$ctx,$var,$pre,$post) = @_;
245         my @tmparr = ();
246
247         push(@tmparr, $pre) if defined($pre);
248         push(@tmparr, @{$ctx->{$var}}) if defined($ctx->{$var});
249         push(@tmparr, $post) if defined($post);
250
251         my $tmplist = array2oneperline(\@tmparr);
252         return if ($tmplist eq "");
253
254         $self->output("$ctx->{TYPE}\_$ctx->{NAME}_$var =$tmplist\n");
255 }
256
257 sub _prepare_list($$$)
258 {
259         my ($self,$ctx,$var) = @_;
260
261         $self->_prepare_list_ex($ctx, $var, undef, undef);
262 }
263
264 sub Integrated($$)
265 {
266         my ($self,$ctx) = @_;
267
268         $self->_prepare_list($ctx, "OBJ_LIST");
269         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
270         $self->_prepare_list($ctx, "LINK_FLAGS");
271 }
272
273 sub SharedModule($$)
274 {
275         my ($self,$ctx) = @_;
276
277         my $init_obj = "";
278
279         my $sane_subsystem = lc($ctx->{SUBSYSTEM});
280         $sane_subsystem =~ s/^lib//;
281         
282         if ($ctx->{TYPE} eq "PYTHON") {
283                 push (@{$self->{python_dsos}}, 
284                         "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}");
285         } else {
286                 push (@{$self->{shared_modules}}, "$ctx->{TARGET_SHARED_LIBRARY}");
287                 push (@{$self->{plugins}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}");
288                 $self->{install_plugins} .= "\t\@echo Installing $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} as \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
289                 $self->{install_plugins} .= "\t\@mkdir -p \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/\n";
290                 $self->{install_plugins} .= "\t\@cp $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
291                 $self->{uninstall_plugins} .= "\t\@echo Uninstalling \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
292                 $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
293                 if (defined($ctx->{ALIASES})) {
294                         foreach (@{$ctx->{ALIASES}}) {
295                                 $self->{install_plugins} .= "\t\@rm -f \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
296                                 $self->{install_plugins} .= "\t\@ln -fs $ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
297                                 $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
298                         }
299                 }
300         }
301
302         $self->output("$ctx->{TYPE}_$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
303         $self->_prepare_list($ctx, "OBJ_LIST");
304         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
305         $self->_prepare_list($ctx, "DEPEND_LIST");
306         $self->_prepare_list($ctx, "LINK_FLAGS");
307
308         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
309
310         if (defined($ctx->{INIT_FUNCTION}) and $ctx->{TYPE} ne "PYTHON") {
311                 my $init_fn = $ctx->{INIT_FUNCTION_TYPE};
312                 $init_fn =~ s/\(\*\)/init_module/;
313                 my $proto_fn = $ctx->{INIT_FUNCTION_TYPE};
314                 $proto_fn =~ s/\(\*\)/$ctx->{INIT_FUNCTION}/;
315
316                 $self->output(<< "__EOD__"
317 bin/$ctx->{NAME}_init_module.c:
318         \@echo Creating \$\@
319         \@echo \"#include \\\"includes.h\\\"\" > \$\@
320         \@echo \"$proto_fn;\" >> \$\@
321         \@echo \"_PUBLIC_ $init_fn\" >> \$\@
322         \@echo \"{\" >> \$\@
323         \@echo \"       return $ctx->{INIT_FUNCTION}();\" >> \$\@
324         \@echo \"}\" >> \$\@
325         \@echo \"\" >> \$\@
326 __EOD__
327 );
328                 $init_obj = "bin/$ctx->{NAME}_init_module.o";
329         }
330
331         $self->output(<< "__EOD__"
332 #
333
334 $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST) $init_obj
335         \@echo Linking \$\@
336         \@mkdir -p $ctx->{SHAREDDIR}
337         \@\$(MDLD) \$(MDLD_FLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
338                 \$($ctx->{TYPE}_$ctx->{NAME}\_FULL_OBJ_LIST) $init_obj \\
339                 \$($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS)
340 __EOD__
341 );
342
343         if (defined($ctx->{ALIASES})) {
344                 foreach (@{$ctx->{ALIASES}}) {
345                         $self->output("\t\@rm -f $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n");
346                         $self->output("\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n");
347                 }
348         }
349         $self->output("\n");
350 }
351
352 sub SharedLibrary($$)
353 {
354         my ($self,$ctx) = @_;
355
356         my $has_static_lib = 0;
357
358         push (@{$self->{shared_libs}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}") if (defined($ctx->{SO_VERSION}));
359         push (@{$self->{installable_shared_libs}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}") if (defined($ctx->{SO_VERSION}));
360
361         $has_static_lib = 1 if grep(/STATIC_LIBRARY/, @{$ctx->{OUTPUT_TYPE}});
362
363         if (not $has_static_lib) {
364                 $self->output("$ctx->{TYPE}_$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
365                 $self->_prepare_list($ctx, "OBJ_LIST");
366                 $self->_prepare_list($ctx, "FULL_OBJ_LIST");
367         }
368         $self->_prepare_list($ctx, "DEPEND_LIST");
369         $self->_prepare_list($ctx, "LINK_FLAGS");
370 #       $self->_prepare_list_ex($ctx, "LINK_FLAGS", "-Wl,--whole-archive", "-Wl,--no-whole-archive");
371
372         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
373
374         my $soarg = "";
375         my $lns = "";
376         if ($self->{config}->{SONAMEFLAG} ne "#" and defined($ctx->{LIBRARY_SONAME})) {
377                 $soarg = "$self->{config}->{SONAMEFLAG}$ctx->{LIBRARY_SONAME}";
378                 if ($ctx->{LIBRARY_REALNAME} ne $ctx->{LIBRARY_SONAME}) {
379                         $lns .= "\n\t\@rm -f $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}";
380                         $lns .= "\n\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}";
381                 }
382         }
383
384         if (defined($ctx->{LIBRARY_SONAME})) {
385                 $lns .= "\n\t\@rm -f $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}";
386                 $lns .= "\n\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}";
387         }
388
389         $self->output(<< "__EOD__"
390 #
391
392 $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
393         \@echo Linking \$\@
394         \@mkdir -p $ctx->{SHAREDDIR}
395         \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
396                 \$($ctx->{TYPE}_$ctx->{NAME}\_FULL_OBJ_LIST) \\
397                 \$($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS) \\
398                 $soarg$lns
399 __EOD__
400 );
401         $self->output("\n");
402 }
403
404 sub StaticLibrary($$)
405 {
406         my ($self,$ctx) = @_;
407
408         return unless (defined($ctx->{OBJ_FILES}));
409
410         push (@{$self->{static_libs}}, $ctx->{TARGET_STATIC_LIBRARY}) if ($ctx->{TYPE} eq "LIBRARY");
411
412         $self->output("$ctx->{TYPE}_$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
413         $self->_prepare_list($ctx, "OBJ_LIST");
414         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
415
416         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
417
418         $self->output(<< "__EOD__"
419 #
420 $ctx->{TARGET_STATIC_LIBRARY}: \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
421         \@echo Linking \$@
422         \@rm -f \$@
423         \@mkdir -p $ctx->{STATICDIR}
424         \@\$(STLD) \$(STLD_FLAGS) \$@ \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
425
426 __EOD__
427 );
428 }
429
430 sub Header($$)
431 {
432         my ($self,$ctx) = @_;
433
434         foreach (@{$ctx->{PUBLIC_HEADERS}}) {
435                 push (@{$self->{headers}}, output::add_dir_str($ctx->{BASEDIR}, $_));
436         }
437 }
438
439 sub Binary($$)
440 {
441         my ($self,$ctx) = @_;
442
443         my $installdir;
444         my $extradir = "";
445
446         if (defined($ctx->{INSTALLDIR}) && $ctx->{INSTALLDIR} =~ /^TORTUREDIR/) {
447                 $extradir = "/torture" . substr($ctx->{INSTALLDIR}, length("TORTUREDIR"));
448         }
449         my $localdir = "bin$extradir";
450
451         $installdir = "bin$extradir";
452
453         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
454                 
455         unless (defined($ctx->{INSTALLDIR})) {
456         } elsif ($ctx->{INSTALLDIR} eq "SBINDIR") {
457                 push (@{$self->{sbin_progs}}, "$installdir/$ctx->{BINARY}");
458         } elsif ($ctx->{INSTALLDIR} eq "BINDIR") {
459                 push (@{$self->{bin_progs}}, "$installdir/$ctx->{BINARY}");
460         } elsif ($ctx->{INSTALLDIR} =~ /^TORTUREDIR/) {
461                 push (@{$self->{torture_progs}}, "$installdir/$ctx->{BINARY}");
462         }
463
464
465         push (@{$self->{binaries}}, "$localdir/$ctx->{BINARY}");
466
467         $self->_prepare_list($ctx, "OBJ_LIST");
468         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
469         $self->_prepare_list($ctx, "DEPEND_LIST");
470         $self->_prepare_list($ctx, "LINK_FLAGS");
471
472 $self->output(<< "__EOD__"
473 $installdir/$ctx->{BINARY}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
474         \@echo Linking \$\@
475 __EOD__
476         );
477
478         if (defined($ctx->{USE_HOSTCC}) && $ctx->{USE_HOSTCC} eq "YES") {
479                 $self->output(<< "__EOD__"
480         \@\$(HOSTLD) \$(HOSTLD_FLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
481                 \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS)
482 __EOD__
483                 );
484         } else {
485                 $self->output(<< "__EOD__"
486         \@\$(BNLD) \$(BNLD_FLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
487                 \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS) 
488
489 __EOD__
490                 );
491         }
492 }
493
494 sub PythonFiles($$)
495 {
496         my ($self,$ctx) = @_;
497
498         foreach (@{$ctx->{PYTHON_FILES}}) {
499                 my $target = "bin/python/".basename($_);
500                 my $source = output::add_dir_str($ctx->{BASEDIR}, $_);
501                 $self->output("$target: $source\n" .
502                                           "\tmkdir -p \$(builddir)/bin/python\n" .
503                               "\tcp $source \$@\n\n");
504                 push (@{$self->{python_pys}}, $target);
505         }
506 }
507
508 sub Manpage($$)
509 {
510         my ($self,$ctx) = @_;
511
512         my $path = output::add_dir_str($ctx->{BASEDIR}, $ctx->{MANPAGE});
513         push (@{$self->{manpages}}, $path);
514 }
515
516 sub ProtoHeader($$)
517 {
518         my ($self,$ctx) = @_;
519
520         my $target = "";
521         my $comment = "Creating ";
522
523         my $priv = undef;
524         my $pub = undef;
525
526         if (defined($ctx->{PRIVATE_PROTO_HEADER})) {
527                 $priv = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PRIVATE_PROTO_HEADER});
528                 $target .= $priv;
529                 $comment .= $priv;
530                 if (defined($ctx->{PUBLIC_PROTO_HEADER})) {
531                         $comment .= " and ";
532                         $target.= " ";
533                 }
534                 push (@{$self->{proto_headers}}, $priv);
535         } else {
536                 $ctx->{PRIVATE_PROTO_HEADER} = $ctx->{PUBLIC_PROTO_HEADER};
537                 $priv = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PRIVATE_PROTO_HEADER});
538         }
539
540         if (defined($ctx->{PUBLIC_PROTO_HEADER})) {
541                 $pub = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PUBLIC_PROTO_HEADER});
542                 $comment .= $pub;
543                 $target .= $pub;
544                 push (@{$self->{proto_headers}}, $pub);
545         } else {
546                 $ctx->{PUBLIC_PROTO_HEADER} = $ctx->{PRIVATE_PROTO_HEADER};
547                 $pub = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PUBLIC_PROTO_HEADER});
548         }
549
550         $self->output("$pub: $ctx->{MK_FILE} \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST:.o=.c) \$(srcdir)/script/mkproto.pl\n");
551         $self->output("\t\@echo \"$comment\"\n");
552         $self->output("\t\@\$(PERL) \$(srcdir)/script/mkproto.pl --srcdir=\$(srcdir) --builddir=\$(builddir) --private=$priv --public=$pub \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n\n");
553 }
554
555 sub write($$)
556 {
557         my ($self,$file) = @_;
558
559         $self->output("MANPAGES = ".array2oneperline($self->{manpages})."\n");
560         $self->output("BIN_PROGS = " . array2oneperline($self->{bin_progs}) . "\n");
561         $self->output("SBIN_PROGS = " . array2oneperline($self->{sbin_progs}) . "\n");
562         $self->output("TORTURE_PROGS = " . array2oneperline($self->{torture_progs}) . "\n");
563         $self->output("BINARIES = " . array2oneperline($self->{binaries}) . "\n");
564         $self->output("STATIC_LIBS = " . array2oneperline($self->{static_libs}) . "\n");
565         $self->output("SHARED_LIBS = " . array2oneperline($self->{shared_libs}) . "\n");
566         $self->output("PYTHON_DSOS = " . array2oneperline($self->{python_dsos}) . "\n");
567         $self->output("PYTHON_PYS = " . array2oneperline($self->{python_pys}) . "\n");
568         $self->output("INSTALLABLE_SHARED_LIBS = " . array2oneperline($self->{installable_shared_libs}) . "\n");
569         $self->output("PUBLIC_HEADERS = " . array2oneperline($self->{headers}) . "\n");
570         $self->output("PC_FILES = " . array2oneperline($self->{pc_files}) . "\n");
571         $self->output("ALL_OBJS = " . array2oneperline($self->{all_objs}) . "\n");
572         $self->output("PROTO_HEADERS = " . array2oneperline($self->{proto_headers}) .  "\n");
573         $self->output("SHARED_MODULES = " . array2oneperline($self->{shared_modules}) . "\n");
574         $self->output("PLUGINS = " . array2oneperline($self->{plugins}) . "\n");
575
576         $self->output("\ninstallplugins: \$(PLUGINS)\n".$self->{install_plugins}."\n");
577         $self->output("\nuninstallplugins:\n".$self->{uninstall_plugins}."\n");
578
579         $self->_prepare_mk_files();
580
581         $self->output($self->{mkfile});
582
583         if ($self->{automatic_deps}) {
584                 $self->output("
585 ifneq (\$(MAKECMDGOALS),clean)
586 ifneq (\$(MAKECMDGOALS),distclean)
587 ifneq (\$(MAKECMDGOALS),realdistclean)
588 ifneq (\$(SKIP_DEP_FILES),yes)
589 -include \$(DEP_FILES)
590 endif
591 endif
592 endif
593 endif
594
595 ifneq (\$(SKIP_DEP_FILES),yes)
596 clean::
597         \@echo Removing dependency files
598         \@find . -name '*.d' -o -name '*.hd' | xargs rm -f
599 endif
600 ");
601         } else {
602                 $self->output("include \$(srcdir)/static_deps.mk\n");
603         }
604
605         open(MAKEFILE,">$file") || die ("Can't open $file\n");
606         print MAKEFILE $self->{output};
607         close(MAKEFILE);
608
609         print __FILE__.": creating $file\n";
610 }
611
612 1;