r23631: when linking shared libraries we need to make shure the linker doesn't
[jelmer/samba4-debian.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 strict;
11
12 use base 'smb_build::env';
13 use Cwd 'abs_path';
14
15 sub new($$$)
16 {
17         my ($myname, $config, $mkfile) = @_;
18         my $self = new smb_build::env($config);
19         
20         bless($self, $myname);
21
22         $self->{manpages} = [];
23         $self->{sbin_progs} = [];
24         $self->{bin_progs} = [];
25         $self->{torture_progs} = [];
26         $self->{static_libs} = [];
27         $self->{shared_libs} = [];
28         $self->{installable_shared_libs} = [];
29         $self->{headers} = [];
30         $self->{shared_modules} = [];
31         $self->{plugins} = [];
32         $self->{install_plugins} = "";
33         $self->{uninstall_plugins} = "";
34         $self->{pc_files} = [];
35         $self->{proto_headers} = [];
36         $self->{output} = "";
37
38         $self->{mkfile} = $mkfile;
39
40         $self->output("#!gmake\n");
41         $self->output("################################################\n");
42         $self->output("# Autogenerated by build/smb_build/makefile.pm #\n");
43         $self->output("################################################\n");
44         $self->output("\n");
45
46         $self->output("default: all\n\n");
47
48         $self->_prepare_path_vars();
49         $self->_prepare_suffix_rules();
50         $self->_prepare_compiler_linker();
51
52         if (!$self->{automatic_deps}) {
53                 $self->output("ALL_PREDEP = proto\n");
54                 $self->output(".NOTPARALLEL:\n");
55         }
56
57         return $self;
58 }
59
60 sub output($$)
61 {
62         my ($self, $text) = @_;
63
64         $self->{output} .= $text;
65 }
66
67 sub _prepare_path_vars($)
68 {
69         my ($self) = @_;
70
71         $self->output(<< "__EOD__"
72 prefix = $self->{config}->{prefix}
73 exec_prefix = $self->{config}->{exec_prefix}
74 selftest_prefix = $self->{config}->{selftest_prefix}
75
76 builddir = $self->{config}->{builddir}
77 srcdir = $self->{config}->{srcdir}
78 datarootdir = $self->{config}->{datarootdir}
79
80 VPATH = \$(builddir):\$(srcdir):heimdal_build:heimdal/lib/asn1:heimdal/lib/krb5:heimdal/lib/gssapi:heimdal/lib/hdb:heimdal/lib/roken:heimdal/lib/des
81
82 BASEDIR = $self->{config}->{prefix}
83 BINDIR = $self->{config}->{bindir}
84 SBINDIR = $self->{config}->{sbindir}
85 LIBDIR = $self->{config}->{libdir}
86 TORTUREDIR = $self->{config}->{libdir}/torture
87 MODULESDIR = $self->{config}->{modulesdir}
88 INCLUDEDIR = $self->{config}->{includedir}
89 CONFIGDIR = $self->{config}->{sysconfdir}
90 DATADIR = $self->{config}->{datadir}
91 WEBAPPSDIR = \$(DATADIR)/webapps
92 SERVICESDIR = \$(DATADIR)/services
93 JSDIR = \$(DATADIR)/js
94 SETUPDIR = \$(DATADIR)/setup
95 VARDIR = $self->{config}->{localstatedir}
96 LOGFILEBASE = $self->{config}->{logfilebase}
97 NCALRPCDIR = $self->{config}->{localstatedir}/ncalrpc
98 LOCKDIR = $self->{config}->{lockdir}
99 PIDDIR = $self->{config}->{piddir}
100 MANDIR = $self->{config}->{mandir}
101 PRIVATEDIR = $self->{config}->{privatedir}
102 WINBINDD_SOCKET_DIR = $self->{config}->{winbindd_socket_dir}
103
104 __EOD__
105 );
106 }
107
108 sub _prepare_suffix_rules($)
109 {
110         my ($self) = @_;
111         my $first_prereq = '$*.c';
112
113         if ($self->{config}->{GNU_MAKE} eq 'yes') {
114                 $first_prereq = '$<';
115         }
116
117         $self->output(<< "__EOD__"
118 # Dependencies command
119 DEPENDS = \$(CC) -M -MG -MP -MT \$(<:.c=.o) -MT \$@ \\
120     `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
121     \$(CFLAGS) $first_prereq -o \$@
122 # Dependencies for host objects
123 HDEPENDS = \$(CC) -M -MG -MP -MT \$(<:.c=.ho) -MT \$@ \\
124     `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
125     \$(HOSTCC_CFLAGS) $first_prereq -o \$@
126 # Dependencies for precompiled headers
127 PCHDEPENDS = \$(CC) -M -MG -MT include/includes.h.gch -MT \$@ \\
128     \$(CFLAGS) $first_prereq -o \$@
129
130 # \$< is broken in older BSD versions:
131 # when \$@ is foo/bar.o, \$< could be torture/foo/bar.c
132 # if it also exists. So better use \$* which is foo/bar
133 # and append .c manually to get foo/bar.c
134 #
135 # If we have GNU Make, it is safe to use \$<, which also lets
136 # building with \$srcdir != \$builddir work.
137
138 # Run a static analysis checker
139 CHECK = \$(CC_CHECKER) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
140     \$(CFLAGS) \$(PICFLAG) -c $first_prereq -o \$@
141
142 # Run the configured compiler
143 COMPILE = \$(CC) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
144     \$(CFLAGS) \$(PICFLAG) -c $first_prereq -o \$@
145
146 # Run the compiler for the build host
147 HCOMPILE = \$(HOSTCC) `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
148     \$(HOSTCC_CFLAGS) -c $first_prereq -o \$@
149
150 # Precompile headers
151 PCHCOMPILE = @\$(CC) -Ilib/replace \\
152     `\$(PERL) \$(srcdir)/script/cflags.pl \$@` \\
153     \$(CFLAGS) \$(PICFLAG) -c $first_prereq -o \$@
154
155 __EOD__
156 );
157 }
158
159 sub _prepare_compiler_linker($)
160 {
161         my ($self) = @_;
162
163         my $builddir_headers = "";
164         my $libdir;
165         my $extra_link_flags = "";
166
167         if ($self->{config}->{USESHARED} eq "true") {
168                 $libdir = "\$(builddir)/bin/shared";
169                 $extra_link_flags = "-Wl,-rpath-link,\$(builddir)/bin/shared";
170         } else {
171                 $libdir = "\$(builddir)/bin/static";
172         }
173         
174         if (!(abs_path($self->{config}->{srcdir}) eq abs_path($self->{config}->{builddir}))) {
175             $builddir_headers= "-I\$(builddir)/include -I\$(builddir) -I\$(builddir)/lib ";
176         }
177
178         $self->output(<< "__EOD__"
179 SHELL=$self->{config}->{SHELL}
180
181 PERL=$self->{config}->{PERL}
182
183 CPP=$self->{config}->{CPP}
184 CPPFLAGS=$builddir_headers-I\$(srcdir)/include -I\$(srcdir) -I\$(srcdir)/lib -I\$(srcdir)/lib/replace -D_SAMBA_BUILD_=4 -DHAVE_CONFIG_H $self->{config}->{CPPFLAGS}
185
186 CC=$self->{config}->{CC}
187 CFLAGS=$self->{config}->{CFLAGS} \$(CPPFLAGS)
188 PICFLAG=$self->{config}->{PICFLAG}
189
190 HOSTCC=$self->{config}->{HOSTCC}
191 HOSTCC_CFLAGS=-D_SAMBA_HOSTCC_ $self->{config}->{CFLAGS} \$(CPPFLAGS)
192
193 INSTALL_LINK_FLAGS=$extra_link_flags
194
195 LD=$self->{config}->{LD} 
196 LDFLAGS=$self->{config}->{LDFLAGS} -L$libdir
197
198 HOSTLD=$self->{config}->{HOSTLD}
199 # It's possible that we ought to have HOSTLD_LDFLAGS as well
200
201 STLD=$self->{config}->{STLD}
202 STLD_FLAGS=$self->{config}->{STLD_FLAGS}
203
204 SHLD=$self->{config}->{SHLD}
205 SHLD_FLAGS=$self->{config}->{SHLD_FLAGS} -L\$(builddir)/bin/shared
206 SHLD_UNDEF_FLAGS=$self->{config}->{SHLD_UNDEF_FLAGS}
207 SHLIBEXT=$self->{config}->{SHLIBEXT}
208
209 XSLTPROC=$self->{config}->{XSLTPROC}
210
211 LEX=$self->{config}->{LEX}
212 YACC=$self->{config}->{YACC}
213 YAPP=$self->{config}->{YAPP}
214
215 GCOV=$self->{config}->{GCOV}
216
217 DEFAULT_TEST_OPTIONS=$self->{config}->{DEFAULT_TEST_OPTIONS}
218
219 __EOD__
220 );
221 }
222
223 sub _prepare_mk_files($)
224 {
225         my $self = shift;
226         my @tmp = ();
227
228         foreach (@smb_build::config_mk::parsed_files) {
229                 s/ .*$//g;
230                 push (@tmp, $_);
231         }
232
233         $self->output("MK_FILES = " . array2oneperline(\@tmp) . "\n");
234 }
235
236 sub array2oneperline($)
237 {
238         my $array = shift;
239         my $output = "";
240
241         foreach (@$array) {
242                 next unless defined($_);
243
244                 $output .= " \\\n\t\t$_";
245         }
246
247         return $output;
248 }
249
250 sub _prepare_list_ex($$$$$)
251 {
252         my ($self,$ctx,$var,$pre,$post) = @_;
253         my @tmparr = ();
254
255         push(@tmparr, $pre) if defined($pre);
256         push(@tmparr, @{$ctx->{$var}}) if defined($ctx->{$var});
257         push(@tmparr, $post) if defined($post);
258
259         my $tmplist = array2oneperline(\@tmparr);
260         return if ($tmplist eq "");
261
262         $self->output("$ctx->{TYPE}\_$ctx->{NAME}_$var =$tmplist\n");
263 }
264
265 sub _prepare_list($$$)
266 {
267         my ($self,$ctx,$var) = @_;
268
269         $self->_prepare_list_ex($ctx, $var, undef, undef);
270 }
271
272 sub Integrated($$)
273 {
274         my ($self,$ctx) = @_;
275
276         $self->_prepare_list($ctx, "OBJ_LIST");
277         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
278         $self->_prepare_list($ctx, "LINK_FLAGS");
279 }
280
281 sub SharedLibrary($$)
282 {
283         my ($self,$ctx) = @_;
284
285         my $init_obj = "";
286         my $has_static_lib = 0;
287         
288         if ($ctx->{TYPE} eq "LIBRARY") {
289                 push (@{$self->{shared_libs}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}") if (defined($ctx->{SO_VERSION}));
290                 push (@{$self->{installable_shared_libs}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}") if (defined($ctx->{SO_VERSION}));
291         } elsif ($ctx->{TYPE} eq "MODULE") {
292                 push (@{$self->{shared_modules}}, "$ctx->{TARGET_SHARED_LIBRARY}");
293                 push (@{$self->{plugins}}, "$ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}");
294
295                 $self->{install_plugins} .= "\t\@echo Installing $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} as \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$ctx->{LIBRARY_REALNAME}\n";
296                 $self->{install_plugins} .= "\t\@mkdir -p \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/\n";
297                 $self->{install_plugins} .= "\t\@cp $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$ctx->{LIBRARY_REALNAME}\n";
298                 $self->{uninstall_plugins} .= "\t\@echo Uninstalling \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$ctx->{LIBRARY_REALNAME}\n";
299                 $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$ctx->{LIBRARY_REALNAME}\n";
300                 if (defined($ctx->{ALIASES})) {
301                         foreach (@{$ctx->{ALIASES}}) {
302                                 $self->{install_plugins} .= "\t\@rm -f \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$_.\$(SHLIBEXT)\n";
303                                 $self->{install_plugins} .= "\t\@ln -fs $ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$_.\$(SHLIBEXT)\n";
304                                 $self->{uninstall_plugins} .= "\t\@-rm \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$_.\$(SHLIBEXT)\n";
305                         }
306                 }
307         }
308
309         $has_static_lib = 1 if grep(/STATIC_LIBRARY/, @{$ctx->{OUTPUT_TYPE}});
310
311         if (not $has_static_lib) {
312                 $self->output("$ctx->{TYPE}_$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
313                 $self->_prepare_list($ctx, "OBJ_LIST");
314                 $self->_prepare_list($ctx, "FULL_OBJ_LIST");
315         }
316         $self->_prepare_list($ctx, "DEPEND_LIST");
317         $self->_prepare_list_ex($ctx, "LINK_FLAGS", "-Wl,--whole-archive", "-Wl,--no-whole-archive");
318
319         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
320
321         my $extraflags = "";
322         if ($ctx->{TYPE} eq "MODULE" and defined($ctx->{INIT_FUNCTION})) {
323                 my $init_fn = $ctx->{INIT_FUNCTION_TYPE};
324                 $init_fn =~ s/\(\*\)/init_module/;
325                 my $proto_fn = $ctx->{INIT_FUNCTION_TYPE};
326                 $proto_fn =~ s/\(\*\)/$ctx->{INIT_FUNCTION}/;
327                 $extraflags = "\$(SHLD_UNDEF_FLAGS)";
328
329                 $self->output(<< "__EOD__"
330 bin/$ctx->{NAME}_init_module.c:
331         \@echo Creating \$\@
332         \@echo \"#include \\\"includes.h\\\"\" > \$\@
333         \@echo \"$proto_fn;\" >> \$\@
334         \@echo -e \"_PUBLIC_ $init_fn \\n{\\n\\treturn $ctx->{INIT_FUNCTION}();\\n}\\n\" >> \$\@
335 __EOD__
336 );
337                 $init_obj = "bin/$ctx->{NAME}_init_module.o";
338         }
339
340         my $soarg = "";
341         my $lns = "";
342         if ($self->{config}->{SONAMEFLAG} ne "" and defined($ctx->{LIBRARY_SONAME})) {
343                 $soarg = "$self->{config}->{SONAMEFLAG}$ctx->{LIBRARY_SONAME} ";
344                 if ($ctx->{LIBRARY_REALNAME} ne $ctx->{LIBRARY_SONAME}) {
345                         $lns .= "\n\t\@rm -f $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}";
346                         $lns .= "\n\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}";
347                 }
348         }
349
350         if ($self->{config}->{SONAMEFLAG} ne "" and 
351                 defined($ctx->{LIBRARY_SONAME}) and 
352                 $ctx->{LIBRARY_REALNAME} ne $ctx->{LIBRARY_SONAME}) {
353                 $lns .= "\n\t\@rm -f $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}";
354                 $lns .= "\n\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_SONAME}";
355         }
356
357         if (defined($ctx->{LIBRARY_SONAME})) {
358                 $lns .= "\n\t\@rm -f $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}";
359                 $lns .= "\n\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$ctx->{LIBRARY_DEBUGNAME}";
360         }
361
362         $self->output(<< "__EOD__"
363 #
364
365 $ctx->{SHAREDDIR}/$ctx->{LIBRARY_REALNAME}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST) $init_obj
366         \@echo Linking \$\@
367         \@mkdir -p $ctx->{SHAREDDIR}
368         \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
369                 \$($ctx->{TYPE}_$ctx->{NAME}\_FULL_OBJ_LIST) \\
370                 \$($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS) $extraflags \\
371                  $soarg \\
372                 $init_obj $lns
373 __EOD__
374 );
375
376         if (defined($ctx->{ALIASES})) {
377                 foreach (@{$ctx->{ALIASES}}) {
378                         $self->output("\t\@rm -f $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n");
379                         $self->output("\t\@ln -fs $ctx->{LIBRARY_REALNAME} $ctx->{SHAREDDIR}/$_.\$(SHLIBEXT)\n");
380                 }
381         }
382         $self->output("\n");
383 }
384
385 sub StaticLibrary($$)
386 {
387         my ($self,$ctx) = @_;
388
389         return unless (defined($ctx->{OBJ_FILES}));
390
391         push (@{$self->{static_libs}}, $ctx->{TARGET_STATIC_LIBRARY}) if ($ctx->{TYPE} eq "LIBRARY");
392
393         $self->output("$ctx->{TYPE}_$ctx->{NAME}_OUTPUT = $ctx->{OUTPUT}\n");
394         $self->_prepare_list($ctx, "OBJ_LIST");
395         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
396
397         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
398
399         $self->output(<< "__EOD__"
400 #
401 $ctx->{TARGET_STATIC_LIBRARY}: \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
402         \@echo Linking \$@
403         \@rm -f \$@
404         \@mkdir -p $ctx->{STATICDIR}
405         \@\$(STLD) \$(STLD_FLAGS) \$@ \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
406
407 __EOD__
408 );
409 }
410
411 sub Header($$)
412 {
413         my ($self,$ctx) = @_;
414
415         my $dir = $ctx->{BASEDIR};
416
417         $dir =~ s/^\.\///g;
418
419         foreach (@{$ctx->{PUBLIC_HEADERS}}) {
420                 push (@{$self->{headers}}, "$dir/$_");
421         }
422 }
423
424 sub Binary($$)
425 {
426         my ($self,$ctx) = @_;
427
428         my $installdir;
429         my $extradir = "";
430
431         if (defined($ctx->{INSTALLDIR}) && $ctx->{INSTALLDIR} =~ /^TORTUREDIR/) {
432                 $extradir = "/torture" . substr($ctx->{INSTALLDIR}, length("TORTUREDIR"));
433         }
434         my $localdir = "bin$extradir";
435
436         $installdir = "bin$extradir";
437
438         push(@{$self->{all_objs}}, "\$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)");
439                 
440         unless (defined($ctx->{INSTALLDIR})) {
441         } elsif ($ctx->{INSTALLDIR} eq "SBINDIR") {
442                 push (@{$self->{sbin_progs}}, "$installdir/$ctx->{BINARY}");
443         } elsif ($ctx->{INSTALLDIR} eq "BINDIR") {
444                 push (@{$self->{bin_progs}}, "$installdir/$ctx->{BINARY}");
445         } elsif ($ctx->{INSTALLDIR} =~ /^TORTUREDIR/) {
446                 push (@{$self->{torture_progs}}, "$installdir/$ctx->{BINARY}");
447         }
448
449
450         push (@{$self->{binaries}}, "$localdir/$ctx->{BINARY}");
451
452         $self->_prepare_list($ctx, "OBJ_LIST");
453         $self->_prepare_list($ctx, "FULL_OBJ_LIST");
454         $self->_prepare_list($ctx, "DEPEND_LIST");
455         $self->_prepare_list($ctx, "LINK_FLAGS");
456
457 $self->output(<< "__EOD__"
458 $installdir/$ctx->{BINARY}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_FULL_OBJ_LIST)
459         \@echo Linking \$\@
460 __EOD__
461         );
462
463         if (defined($ctx->{USE_HOSTCC}) && $ctx->{USE_HOSTCC} eq "YES") {
464                 $self->output(<< "__EOD__"
465         \@\$(HOSTLD) \$(LDFLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
466                 \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS)
467 __EOD__
468                 );
469         } else {
470                 $self->output(<< "__EOD__"
471         \@\$(LD) \$(LDFLAGS) -o \$\@ \$(INSTALL_LINK_FLAGS) \\
472                 \$\($ctx->{TYPE}_$ctx->{NAME}_LINK_FLAGS) 
473
474 __EOD__
475                 );
476         }
477 }
478
479 sub Manpage($$)
480 {
481         my ($self,$ctx) = @_;
482
483         my $dir = $ctx->{BASEDIR};
484         
485         $dir =~ s/^\.\///g;
486
487         push (@{$self->{manpages}}, "$dir/$ctx->{MANPAGE}");
488 }
489
490 sub PkgConfig($$$)
491 {
492         my ($self,$ctx,$other) = @_;
493         
494         my $link_name = $ctx->{NAME};
495
496         $link_name =~ s/^LIB//g;
497         $link_name = lc($link_name);
498
499         return if (not defined($ctx->{DESCRIPTION}));
500
501         my $path = "$ctx->{BASEDIR}/$link_name.pc";
502
503         push (@{$self->{pc_files}}, $path);
504
505         my $pubs;
506         my $privs;
507         my $privlibs;
508
509         if (defined($ctx->{PUBLIC_DEPENDENCIES})) {
510                 foreach (@{$ctx->{PUBLIC_DEPENDENCIES}}) {
511                         next if ($other->{$_}->{ENABLE} eq "NO");
512                         if ($other->{$_}->{TYPE} eq "LIBRARY") {
513                                 s/^LIB//g;
514                                 $_ = lc($_);
515
516                                 $pubs .= "$_ ";
517                         } else {
518                                 s/^LIB//g;
519                                 $_ = lc($_);
520
521                                 $privlibs .= "-l$_ ";
522                         }
523                 }
524         }
525
526         if (defined($ctx->{PRIVATE_DEPENDENCIES})) {
527                 foreach (@{$ctx->{PRIVATE_DEPENDENCIES}}) {
528                         next if ($other->{$_}->{ENABLE} eq "NO");
529                         if ($other->{$_}->{TYPE} eq "LIBRARY") {
530                                 s/^LIB//g;
531                                 $_ = lc($_);
532
533                                 $privs .= "$_ ";
534                         } else {
535                                 s/^LIB//g;
536                                 $_ = lc($_);
537
538                                 $privlibs .= "-l$_ ";
539                         }
540                 }
541         }
542
543         smb_build::env::PkgConfig($self,
544                 $path,
545                 $link_name,
546                 "-L\${libdir} -l$link_name",
547                 $privlibs,
548                 "",
549                 "$ctx->{VERSION}",
550                 $ctx->{DESCRIPTION},
551                 defined($ctx->{INIT_FUNCTIONS}),
552                 $pubs,
553                 "",
554                 [
555                         "prefix=$self->{config}->{prefix}",
556                         "exec_prefix=$self->{config}->{exec_prefix}",
557                         "libdir=$self->{config}->{libdir}",
558                         "includedir=$self->{config}->{includedir}"
559                 ]
560         ); 
561         my $abs_srcdir = abs_path($self->{config}->{srcdir});
562         smb_build::env::PkgConfig($self,
563                 "bin/pkgconfig/$link_name-uninstalled.pc",
564                 $link_name,
565                 "-Lbin/shared -Lbin/static -l$link_name",
566                 $privlibs,
567                 join(' ', 
568                         "-I$abs_srcdir",
569                         "-I$abs_srcdir/include",
570                         "-I$abs_srcdir/lib",
571                         "-I$abs_srcdir/lib/replace"),
572                 "$ctx->{VERSION}",
573                 $ctx->{DESCRIPTION},
574                 defined($ctx->{INIT_FUNCTIONS}),
575                 $pubs,
576                 $privs,
577                 [
578                         "prefix=bin/",
579                         "includedir=$ctx->{BASEDIR}"
580                 ]
581         ); 
582 }
583
584 sub ProtoHeader($$)
585 {
586         my ($self,$ctx) = @_;
587
588         my $dir = $ctx->{BASEDIR};
589
590         $dir =~ s/^\.\///g;
591
592         my $target = "";
593
594         my $comment = "Creating ";
595         if (defined($ctx->{PRIVATE_PROTO_HEADER})) {
596                 $target.= "$dir/$ctx->{PRIVATE_PROTO_HEADER}";
597                 $comment.= "$dir/$ctx->{PRIVATE_PROTO_HEADER}";
598                 if (defined($ctx->{PUBLIC_PROTO_HEADER})) {
599                         $comment .= " and ";
600                         $target.= " ";
601                 }
602                 push (@{$self->{proto_headers}}, "$dir/$ctx->{PRIVATE_PROTO_HEADER}");
603         } else {
604                 $ctx->{PRIVATE_PROTO_HEADER} = $ctx->{PUBLIC_PROTO_HEADER};
605         }
606         
607         if (defined($ctx->{PUBLIC_PROTO_HEADER})) {
608                 $comment.= "$dir/$ctx->{PUBLIC_PROTO_HEADER}";
609                 $target .= "$dir/$ctx->{PUBLIC_PROTO_HEADER}";
610                 push (@{$self->{proto_headers}}, "$dir/$ctx->{PUBLIC_PROTO_HEADER}");
611         } else {
612                 $ctx->{PUBLIC_PROTO_HEADER} = $ctx->{PRIVATE_PROTO_HEADER};
613         }       
614
615         $self->output("$dir/$ctx->{PUBLIC_PROTO_HEADER}: $ctx->{MK_FILE} \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST:.o=.c) \$(srcdir)/script/mkproto.pl\n");
616         $self->output("\t\@echo \"$comment\"\n");
617
618         $self->output("\t\@\$(PERL) \$(srcdir)/script/mkproto.pl --srcdir=\$(srcdir) --builddir=\$(builddir) --private=$dir/$ctx->{PRIVATE_PROTO_HEADER} --public=$dir/$ctx->{PUBLIC_PROTO_HEADER} \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n\n");
619 }
620
621 sub write($$)
622 {
623         my ($self,$file) = @_;
624
625         $self->output("MANPAGES = ".array2oneperline($self->{manpages})."\n");
626         $self->output("BIN_PROGS = " . array2oneperline($self->{bin_progs}) . "\n");
627         $self->output("SBIN_PROGS = " . array2oneperline($self->{sbin_progs}) . "\n");
628         $self->output("TORTURE_PROGS = " . array2oneperline($self->{torture_progs}) . "\n");
629         $self->output("BINARIES = " . array2oneperline($self->{binaries}) . "\n");
630         $self->output("STATIC_LIBS = " . array2oneperline($self->{static_libs}) . "\n");
631         $self->output("SHARED_LIBS = " . array2oneperline($self->{shared_libs}) . "\n");
632         $self->output("INSTALLABLE_SHARED_LIBS = " . array2oneperline($self->{installable_shared_libs}) . "\n");
633         $self->output("PUBLIC_HEADERS = " . array2oneperline($self->{headers}) . "\n");
634         $self->output("PC_FILES = " . array2oneperline($self->{pc_files}) . "\n");
635         $self->output("ALL_OBJS = " . array2oneperline($self->{all_objs}) . "\n");
636         $self->output("PROTO_HEADERS = " . array2oneperline($self->{proto_headers}) .  "\n");
637         $self->output("SHARED_MODULES = " . array2oneperline($self->{shared_modules}) . "\n");
638         $self->output("PLUGINS = " . array2oneperline($self->{plugins}) . "\n");
639
640         $self->output("\ninstallplugins: \$(PLUGINS)\n".$self->{install_plugins}."\n");
641         $self->output("\nuninstallplugins:\n".$self->{uninstall_plugins}."\n");
642
643         $self->_prepare_mk_files();
644
645         $self->output($self->{mkfile});
646
647         if ($self->{automatic_deps}) {
648                 $self->output("
649 ifneq (\$(MAKECMDGOALS),clean)
650 ifneq (\$(MAKECMDGOALS),distclean)
651 ifneq (\$(MAKECMDGOALS),realdistclean)
652 ifneq (\$(SKIP_DEP_FILES),yes)
653 -include \$(DEP_FILES)
654 endif
655 endif
656 endif
657 endif
658
659 ifneq (\$(SKIP_DEP_FILES),yes)
660 clean::
661         \@echo Removing dependency files
662         \@find . -name '*.d' -o -name '*.hd' | xargs rm -f
663 endif
664 ");
665         } else {
666                 $self->output("include \$(srcdir)/static_deps.mk\n");
667         }
668
669         open(MAKEFILE,">$file") || die ("Can't open $file\n");
670         print MAKEFILE $self->{output};
671         close(MAKEFILE);
672
673         print __FILE__.": creating $file\n";
674 }
675
676 1;