5799d89c5701ca620fccb2688dbed4c16bfe11a8
[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
115         $self->output(<< "__EOD__"
116 FIRST_PREREQ = $self->{config}->{FIRST_PREREQ}
117
118 __EOD__
119 );
120 }
121
122 sub _prepare_compiler_linker($)
123 {
124         my ($self) = @_;
125
126         my $builddir_headers = "";
127         my $libdir;
128         my $extra_link_flags = "";
129
130         if ($self->{config}->{USESHARED} eq "true") {
131                 $libdir = "\$(builddir)/bin/shared";
132                 $extra_link_flags = "-Wl,-rpath-link,\$(builddir)/bin/shared";
133         } else {
134                 $libdir = "\$(builddir)/bin/static";
135         }
136         
137         if (!(abs_path($self->{config}->{srcdir}) eq abs_path($self->{config}->{builddir}))) {
138             $builddir_headers= "-I\$(builddir)/include -I\$(builddir) -I\$(builddir)/lib ";
139         }
140
141         $self->output(<< "__EOD__"
142 SHELL=$self->{config}->{SHELL}
143
144 PERL=$self->{config}->{PERL}
145 PYTHON=$self->{config}->{PYTHON}
146 SWIG=$self->{config}->{SWIG}
147
148 CPP=$self->{config}->{CPP}
149 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}
150
151 CC=$self->{config}->{CC}
152 CFLAGS=$self->{config}->{CFLAGS}
153 CFLAG_NO_UNUSED_MACROS=$self->{config}->{CFLAG_NO_UNUSED_MACROS}
154 PICFLAG=$self->{config}->{PICFLAG}
155
156 INSTALL_LINK_FLAGS=$extra_link_flags
157
158 BNLD=$self->{config}->{LD} 
159 BNLD_FLAGS=$self->{config}->{LDFLAGS} -L$libdir
160
161 STLD=$self->{config}->{STLD}
162 STLD_FLAGS=$self->{config}->{STLD_FLAGS}
163
164 SHLD=$self->{config}->{SHLD}
165 SHLD_FLAGS=$self->{config}->{SHLD_FLAGS} -L\$(builddir)/bin/shared
166
167 MDLD=$self->{config}->{MDLD}
168 MDLD_FLAGS=$self->{config}->{MDLD_FLAGS} -L\$(builddir)/bin/shared
169
170 SHLIBEXT=$self->{config}->{SHLIBEXT}
171
172 HOSTCC=$self->{config}->{HOSTCC}
173 HOSTCC_FLAGS=-D_SAMBA_HOSTCC_ \$(CFLAGS)
174
175 HOSTLD=$self->{config}->{HOSTLD}
176 HOSTLD_FLAGS=$self->{config}->{LDFLAGS}
177
178 XSLTPROC=$self->{config}->{XSLTPROC}
179
180 LIB_PATH_VAR=$self->{config}->{LIB_PATH_VAR}
181
182 LEX=$self->{config}->{LEX}
183 YACC=$self->{config}->{YACC}
184 YAPP=$self->{config}->{YAPP}
185
186 GCOV=$self->{config}->{GCOV}
187
188 DEFAULT_TEST_OPTIONS=$self->{config}->{DEFAULT_TEST_OPTIONS}
189
190 __EOD__
191 );
192 }
193
194 sub _prepare_mk_files($)
195 {
196         my $self = shift;
197         my @tmp = ();
198
199         foreach (@smb_build::config_mk::parsed_files) {
200                 s/ .*$//g;
201                 push (@tmp, $_);
202         }
203
204         if ($self->{gnu_make}) {
205                 $self->output("
206 ifneq (\$(MAKECMDGOALS),clean)
207 ifneq (\$(MAKECMDGOALS),distclean)
208 ifneq (\$(MAKECMDGOALS),realdistclean)
209 ");
210         }
211
212         $self->output("MK_FILES = " . array2oneperline(\@tmp) . "\n");
213
214         if ($self->{gnu_make}) {
215                 $self->output("
216 endif
217 endif
218 endif
219 ");
220         }
221 }
222
223 sub array2oneperline($)
224 {
225         my $array = shift;
226         my $output = "";
227
228         foreach (@$array) {
229                 next unless defined($_);
230
231                 $output .= " \\\n\t\t$_";
232         }
233
234         return $output;
235 }
236
237 sub _prepare_list_ex($$$$$)
238 {
239         my ($self,$ctx,$var,$pre,$post) = @_;
240         my @tmparr = ();
241
242         push(@tmparr, $pre) if defined($pre);
243         push(@tmparr, @{$ctx->{$var}}) if defined($ctx->{$var});
244         push(@tmparr, $post) if defined($post);
245
246         my $tmplist = array2oneperline(\@tmparr);
247         return if ($tmplist eq "");
248
249         $self->output("$ctx->{TYPE}\_$ctx->{NAME}_$var =$tmplist\n");
250 }
251
252 sub _prepare_list($$$)
253 {
254         my ($self,$ctx,$var) = @_;
255
256         $self->_prepare_list_ex($ctx, $var, undef, undef);
257 }
258
259 sub Integrated($$)
260 {
261         my ($self,$ctx) = @_;
262
263         $self->_prepare_list($ctx, "OBJ_LIST");
264         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
265         $self->_prepare_list($ctx, "LINK_FLAGS");
266 }
267
268 sub SharedModule($$)
269 {
270         my ($self,$ctx) = @_;
271
272         my $init_obj = "";
273
274         my $sane_subsystem = lc($ctx->{SUBSYSTEM});
275         $sane_subsystem =~ s/^lib//;
276         
277         if ($ctx->{TYPE} eq "PYTHON") {
278                 push (@{$self->{python_dsos}}, 
279                         "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}");
280         } else {
281                 push (@{$self->{shared_modules}}, "$ctx->{TARGET_SHARED_LIBRARY}");
282                 push (@{$self->{plugins}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}");
283                 $self->{install_plugins} .= "\t\@echo Installing $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} as \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
284                 $self->{install_plugins} .= "\t\@mkdir -p \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/\n";
285                 $self->{install_plugins} .= "\t\@cp $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
286                 $self->{uninstall_plugins} .= "\t\@echo Uninstalling \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
287                 $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$ctx->{LIBRARY_REALNAME}\n";
288                 if (defined($ctx->{ALIASES})) {
289                         foreach (@{$ctx->{ALIASES}}) {
290                                 $self->{install_plugins} .= "\t\@rm -f \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
291                                 $self->{install_plugins} .= "\t\@ln -fs $ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
292                                 $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(MODULESDIR)/$sane_subsystem/$_.\$(SHLIBEXT)\n";
293                         }
294                 }
295         }
296
297         $self->output("$ctx->{TYPE}_$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
298         $self->_prepare_list($ctx, "OBJ_LIST");
299         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
300         $self->_prepare_list($ctx, "DEPEND_LIST");
301         $self->_prepare_list($ctx, "LINK_FLAGS");
302
303         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
304
305         if (defined($ctx->{INIT_FUNCTION}) and $ctx->{TYPE} ne "PYTHON") {
306                 my $init_fn = $ctx->{INIT_FUNCTION_TYPE};
307                 $init_fn =~ s/\(\*\)/init_module/;
308                 my $proto_fn = $ctx->{INIT_FUNCTION_TYPE};
309                 $proto_fn =~ s/\(\*\)/$ctx->{INIT_FUNCTION}/;
310
311                 $self->output(<< "__EOD__"
312 bin/$ctx->{NAME}_init_module.c:
313         \@echo Creating \$\@
314         \@echo \"#include \\\"includes.h\\\"\" > \$\@
315         \@echo \"$proto_fn;\" >> \$\@
316         \@echo \"_PUBLIC_ $init_fn\" >> \$\@
317         \@echo \"{\" >> \$\@
318         \@echo \"       return $ctx->{INIT_FUNCTION}();\" >> \$\@
319         \@echo \"}\" >> \$\@
320         \@echo \"\" >> \$\@
321 __EOD__
322 );
323                 $init_obj = "bin/$ctx->{NAME}_init_module.o";
324         }
325
326         $self->output(<< "__EOD__"
327 #
328
329 $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST) $init_obj
330         \@echo Linking \$\@
331         \@mkdir -p $ctx->{SHAREDDIR}
332         \@\$(MDLD) \$(MDLD_FLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
333                 \$($ctx->{TYPE}_$ctx->{NAME}\_FULL_OBJ_LIST) $init_obj \\
334                 \$($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS)
335 __EOD__
336 );
337
338         if (defined($ctx->{ALIASES})) {
339                 foreach (@{$ctx->{ALIASES}}) {
340                         $self->output("\t\@rm -f $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n");
341                         $self->output("\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n");
342                 }
343         }
344         $self->output("\n");
345 }
346
347 sub SharedLibrary($$)
348 {
349         my ($self,$ctx) = @_;
350
351         my $has_static_lib = 0;
352
353         push (@{$self->{shared_libs}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}") if (defined($ctx->{SO_VERSION}));
354         push (@{$self->{installable_shared_libs}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}") if (defined($ctx->{SO_VERSION}));
355
356         $has_static_lib = 1 if grep(/STATIC_LIBRARY/, @{$ctx->{OUTPUT_TYPE}});
357
358         if (not $has_static_lib) {
359                 $self->output("$ctx->{TYPE}_$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
360                 $self->_prepare_list($ctx, "OBJ_LIST");
361                 $self->_prepare_list($ctx, "FULL_OBJ_LIST");
362         }
363         $self->_prepare_list($ctx, "DEPEND_LIST");
364         $self->_prepare_list($ctx, "LINK_FLAGS");
365 #       $self->_prepare_list_ex($ctx, "LINK_FLAGS", "-Wl,--whole-archive", "-Wl,--no-whole-archive");
366
367         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
368
369         my $soarg = "";
370         my $lns = "";
371         if ($self->{config}->{SONAMEFLAG} ne "#" and defined($ctx->{LIBRARY_SONAME})) {
372                 $soarg = "$self->{config}->{SONAMEFLAG}$ctx->{LIBRARY_SONAME}";
373                 if ($ctx->{LIBRARY_REALNAME} ne $ctx->{LIBRARY_SONAME}) {
374                         $lns .= "\n\t\@rm -f $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}";
375                         $lns .= "\n\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}";
376                 }
377         }
378
379         if (defined($ctx->{LIBRARY_SONAME})) {
380                 $lns .= "\n\t\@rm -f $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}";
381                 $lns .= "\n\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}";
382         }
383
384         $self->output(<< "__EOD__"
385 #
386
387 $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
388         \@echo Linking \$\@
389         \@mkdir -p $ctx->{SHAREDDIR}
390         \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
391                 \$($ctx->{TYPE}_$ctx->{NAME}\_FULL_OBJ_LIST) \\
392                 \$($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS) \\
393                 $soarg$lns
394 __EOD__
395 );
396         $self->output("\n");
397 }
398
399 sub StaticLibrary($$)
400 {
401         my ($self,$ctx) = @_;
402
403         return unless (defined($ctx->{OBJ_FILES}));
404
405         push (@{$self->{static_libs}}, $ctx->{TARGET_STATIC_LIBRARY}) if ($ctx->{TYPE} eq "LIBRARY");
406
407         $self->output("$ctx->{TYPE}_$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
408         $self->_prepare_list($ctx, "OBJ_LIST");
409         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
410
411         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
412
413         $self->output(<< "__EOD__"
414 #
415 $ctx->{TARGET_STATIC_LIBRARY}: \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
416         \@echo Linking \$@
417         \@rm -f \$@
418         \@mkdir -p $ctx->{STATICDIR}
419         \@\$(STLD) \$(STLD_FLAGS) \$@ \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
420
421 __EOD__
422 );
423 }
424
425 sub Header($$)
426 {
427         my ($self,$ctx) = @_;
428
429         foreach (@{$ctx->{PUBLIC_HEADERS}}) {
430                 push (@{$self->{headers}}, output::add_dir_str($ctx->{BASEDIR}, $_));
431         }
432 }
433
434 sub Binary($$)
435 {
436         my ($self,$ctx) = @_;
437
438         my $installdir;
439         my $extradir = "";
440
441         if (defined($ctx->{INSTALLDIR}) && $ctx->{INSTALLDIR} =~ /^TORTUREDIR/) {
442                 $extradir = "/torture" . substr($ctx->{INSTALLDIR}, length("TORTUREDIR"));
443         }
444         my $localdir = "bin$extradir";
445
446         $installdir = "bin$extradir";
447
448         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
449                 
450         unless (defined($ctx->{INSTALLDIR})) {
451         } elsif ($ctx->{INSTALLDIR} eq "SBINDIR") {
452                 push (@{$self->{sbin_progs}}, "$installdir/$ctx->{BINARY}");
453         } elsif ($ctx->{INSTALLDIR} eq "BINDIR") {
454                 push (@{$self->{bin_progs}}, "$installdir/$ctx->{BINARY}");
455         } elsif ($ctx->{INSTALLDIR} =~ /^TORTUREDIR/) {
456                 push (@{$self->{torture_progs}}, "$installdir/$ctx->{BINARY}");
457         }
458
459         push (@{$self->{binaries}}, "$localdir/$ctx->{BINARY}");
460
461         $self->_prepare_list($ctx, "OBJ_LIST");
462         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
463         $self->_prepare_list($ctx, "DEPEND_LIST");
464         $self->_prepare_list($ctx, "LINK_FLAGS");
465
466 $self->output(<< "__EOD__"
467 $installdir/$ctx->{BINARY}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
468         \@echo Linking \$\@
469 __EOD__
470         );
471
472         if (defined($ctx->{USE_HOSTCC}) && $ctx->{USE_HOSTCC} eq "YES") {
473                 $self->output(<< "__EOD__"
474         \@\$(HOSTLD) \$(HOSTLD_FLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
475                 \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS)
476 __EOD__
477                 );
478         } else {
479                 $self->output(<< "__EOD__"
480         \@\$(BNLD) \$(BNLD_FLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
481                 \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS) 
482
483 __EOD__
484                 );
485         }
486 }
487
488 sub PythonFiles($$)
489 {
490         my ($self,$ctx) = @_;
491
492         foreach (@{$ctx->{PYTHON_FILES}}) {
493                 my $target = "bin/python/".basename($_);
494                 my $source = output::add_dir_str($ctx->{BASEDIR}, $_);
495                 $self->output("$target: $source\n" .
496                                           "\tmkdir -p \$(builddir)/bin/python\n" .
497                               "\tcp $source \$@\n\n");
498                 push (@{$self->{python_pys}}, $target);
499         }
500 }
501
502 sub Manpage($$)
503 {
504         my ($self,$ctx) = @_;
505
506         my $path = output::add_dir_str($ctx->{BASEDIR}, $ctx->{MANPAGE});
507         push (@{$self->{manpages}}, $path);
508 }
509
510 sub ProtoHeader($$)
511 {
512         my ($self,$ctx) = @_;
513
514         my $target = "";
515         my $comment = "Creating ";
516
517         my $priv = undef;
518         my $pub = undef;
519
520         if (defined($ctx->{PRIVATE_PROTO_HEADER})) {
521                 $priv = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PRIVATE_PROTO_HEADER});
522                 $target .= $priv;
523                 $comment .= $priv;
524                 if (defined($ctx->{PUBLIC_PROTO_HEADER})) {
525                         $comment .= " and ";
526                         $target.= " ";
527                 }
528                 push (@{$self->{proto_headers}}, $priv);
529         } else {
530                 $ctx->{PRIVATE_PROTO_HEADER} = $ctx->{PUBLIC_PROTO_HEADER};
531                 $priv = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PRIVATE_PROTO_HEADER});
532         }
533
534         if (defined($ctx->{PUBLIC_PROTO_HEADER})) {
535                 $pub = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PUBLIC_PROTO_HEADER});
536                 $comment .= $pub;
537                 $target .= $pub;
538                 push (@{$self->{proto_headers}}, $pub);
539         } else {
540                 $ctx->{PUBLIC_PROTO_HEADER} = $ctx->{PRIVATE_PROTO_HEADER};
541                 $pub = output::add_dir_str($ctx->{BASEDIR}, $ctx->{PUBLIC_PROTO_HEADER});
542         }
543
544         $self->output("$pub: $ctx->{MK_FILE} \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST:.o=.c) \$(srcdir)/script/mkproto.pl\n");
545         $self->output("\t\@echo \"$comment\"\n");
546         $self->output("\t\@\$(PERL) \$(srcdir)/script/mkproto.pl --srcdir=\$(srcdir) --builddir=\$(builddir) --private=$priv --public=$pub \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n\n");
547 }
548
549 sub write($$)
550 {
551         my ($self,$file) = @_;
552
553         $self->output("MANPAGES = ".array2oneperline($self->{manpages})."\n");
554         $self->output("BIN_PROGS = " . array2oneperline($self->{bin_progs}) . "\n");
555         $self->output("SBIN_PROGS = " . array2oneperline($self->{sbin_progs}) . "\n");
556         $self->output("TORTURE_PROGS = " . array2oneperline($self->{torture_progs}) . "\n");
557         $self->output("BINARIES = " . array2oneperline($self->{binaries}) . "\n");
558         $self->output("STATIC_LIBS = " . array2oneperline($self->{static_libs}) . "\n");
559         $self->output("SHARED_LIBS = " . array2oneperline($self->{shared_libs}) . "\n");
560         $self->output("PYTHON_DSOS = " . array2oneperline($self->{python_dsos}) . "\n");
561         $self->output("PYTHON_PYS = " . array2oneperline($self->{python_pys}) . "\n");
562         $self->output("INSTALLABLE_SHARED_LIBS = " . array2oneperline($self->{installable_shared_libs}) . "\n");
563         $self->output("PUBLIC_HEADERS = " . array2oneperline($self->{headers}) . "\n");
564         $self->output("PC_FILES = " . array2oneperline($self->{pc_files}) . "\n");
565         $self->output("ALL_OBJS = " . array2oneperline($self->{all_objs}) . "\n");
566         $self->output("PROTO_HEADERS = " . array2oneperline($self->{proto_headers}) .  "\n");
567         $self->output("SHARED_MODULES = " . array2oneperline($self->{shared_modules}) . "\n");
568         $self->output("PLUGINS = " . array2oneperline($self->{plugins}) . "\n");
569
570         $self->output("\ninstallplugins: \$(PLUGINS)\n".$self->{install_plugins}."\n");
571         $self->output("\nuninstallplugins:\n".$self->{uninstall_plugins}."\n");
572
573         $self->_prepare_mk_files();
574
575         $self->output($self->{mkfile});
576
577         if ($self->{automatic_deps}) {
578                 $self->output("
579 ifneq (\$(MAKECMDGOALS),clean)
580 ifneq (\$(MAKECMDGOALS),distclean)
581 ifneq (\$(MAKECMDGOALS),realdistclean)
582 ifneq (\$(SKIP_DEP_FILES),yes)
583 -include \$(DEP_FILES)
584 endif
585 endif
586 endif
587 endif
588
589 ifneq (\$(SKIP_DEP_FILES),yes)
590 clean::
591         \@echo Removing dependency files
592         \@find . -name '*.d' -o -name '*.hd' | xargs rm -f
593 endif
594 ");
595         } else {
596                 $self->output("include \$(srcdir)/static_deps.mk\n");
597         }
598
599         open(MAKEFILE,">$file") || die ("Can't open $file\n");
600         print MAKEFILE $self->{output};
601         close(MAKEFILE);
602
603         print __FILE__.": creating $file\n";
604 }
605
606 1;