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