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