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