2 # - create output for Makefile
4 # Copyright (C) Stefan (metze) Metzmacher 2004
5 # Copyright (C) Jelmer Vernooij 2005
6 # Released under the GNU GPL
8 package smb_build
::makefile
;
12 use base
'smb_build::env';
16 my ($myname, $config, $mkfile) = @_;
17 my $self = new smb_build
::env
($config);
19 bless($self, $myname);
21 $self->{manpages
} = [];
22 $self->{sbin_progs
} = [];
23 $self->{bin_progs
} = [];
24 $self->{static_libs
} = [];
25 $self->{shared_libs
} = [];
26 $self->{installable_shared_libs
} = [];
27 $self->{headers
} = [];
28 $self->{shared_modules
} = [];
29 $self->{plugins
} = [];
30 $self->{install_plugins
} = "";
31 $self->{uninstall_plugins
} = "";
32 $self->{pc_files
} = [];
33 $self->{proto_headers
} = [];
36 $self->{mkfile
} = $mkfile;
38 $self->output("#!gmake\n");
39 $self->output("################################################\n");
40 $self->output("# Autogenerated by build/smb_build/makefile.pm #\n");
41 $self->output("################################################\n");
44 $self->output("default: all\n\n");
46 $self->_prepare_path_vars();
47 $self->_prepare_compiler_linker();
54 my ($self, $text) = @_;
56 $self->{output
} .= $text;
59 sub _prepare_path_vars
($)
63 $self->output(<< "__EOD__"
64 prefix
= $self->{config
}->{prefix
}
65 exec_prefix
= $self->{config
}->{exec_prefix
}
66 selftest_prefix
= $self->{config
}->{selftest_prefix
}
67 VPATH
= $self->{config
}->{srcdir
}
68 srcdir
= $self->{config
}->{srcdir
}
69 builddir
= $self->{config
}->{builddir
}
71 BASEDIR
= $self->{config
}->{prefix
}
72 BINDIR
= $self->{config
}->{bindir
}
73 SBINDIR
= $self->{config
}->{sbindir
}
74 LIBDIR
= $self->{config
}->{libdir
}
75 MODULESDIR
= $self->{config
}->{modulesdir
}
76 INCLUDEDIR
= $self->{config
}->{includedir
}
77 CONFIGDIR
= $self->{config
}->{sysconfdir
}
78 DATADIR
= $self->{config
}->{datadir
}
79 SWATDIR
= $self->{config
}->{datadir
}/swat
80 JSDIR
= $self->{config
}->{datadir
}/js
81 SETUPDIR
= $self->{config
}->{datadir
}/setup
82 VARDIR
= $self->{config
}->{localstatedir
}
83 LOGFILEBASE
= $self->{config
}->{logfilebase
}
84 NCALRPCDIR
= $self->{config
}->{localstatedir
}/ncalrpc
85 LOCKDIR
= $self->{config
}->{lockdir
}
86 PIDDIR
= $self->{config
}->{piddir
}
87 MANDIR
= $self->{config
}->{mandir
}
88 PRIVATEDIR
= $self->{config
}->{privatedir
}
89 WINBINDD_SOCKET_DIR
= $self->{config
}->{winbindd_socket_dir
}
95 sub _prepare_compiler_linker
($)
100 my $devld_install = "";
102 $self->{duplicate_build
} = 0;
103 if ($self->{config
}->{LIBRARY_OUTPUT_TYPE
} eq "SHARED_LIBRARY") {
104 if ($self->{developer
}) {
105 $self->{duplicate_build
} = 1;
106 $devld_local = " -Wl,-rpath,\$(builddir)/bin";
108 $devld_install = " -Wl,-rpath-link,\$(builddir)/bin";
111 $self->output(<< "__EOD__"
112 SHELL
=$self->{config
}->{SHELL
}
114 PERL
=$self->{config
}->{PERL
}
116 CPP
=$self->{config
}->{CPP
}
117 CPPFLAGS
=$self->{config
}->{CPPFLAGS
}
119 CC
=$self->{config
}->{CC
}
120 CFLAGS
=-I\
$(srcdir
)/include -I\$(srcdir) -I\$(srcdir)/lib
-D_SAMBA_BUILD_
-DHAVE_CONFIG_H
$self->{config
}->{CFLAGS
} \
$(CPPFLAGS
)
121 PICFLAG
=$self->{config
}->{PICFLAG
}
122 HOSTCC
=$self->{config
}->{HOSTCC
}
124 LOCAL_LINK_FLAGS
=$devld_local
125 INSTALL_LINK_FLAGS
=$devld_install
127 LD
=$self->{config
}->{LD
}
128 LDFLAGS
=$self->{config
}->{LDFLAGS
} -L\
$(builddir
)/bin
130 STLD
=$self->{config
}->{AR
}
131 STLD_FLAGS
=-rc
-L\
$(builddir
)/bin
133 SHLD
=$self->{config
}->{CC
}
134 SHLD_FLAGS
=$self->{config
}->{LDSHFLAGS
} -L\
$(builddir
)/bin
135 SHLIBEXT
=$self->{config
}->{SHLIBEXT
}
137 XSLTPROC
=$self->{config
}->{XSLTPROC
}
139 LEX
=$self->{config
}->{LEX
}
140 YACC
=$self->{config
}->{YACC
}
141 YAPP
=$self->{config
}->{YAPP
}
142 PIDL_ARGS
=$self->{config
}->{PIDL_ARGS
}
144 GCOV
=$self->{config
}->{GCOV
}
146 DEFAULT_TEST_TARGET
=$self->{config
}->{DEFAULT_TEST_TARGET
}
152 sub _prepare_mk_files
($)
158 foreach (@smb_build::config_mk
::parsed_files
) {
163 $self->output("MK_FILES = " . array2oneperline
(\
@tmp) . "\n");
166 sub array2oneperline
($)
172 next unless defined($_);
174 $output .= " \\\n\t\t$_";
180 sub _prepare_list
($$$)
182 my ($self,$ctx,$var) = @_;
184 my $tmplist = array2oneperline
($ctx->{$var});
185 return if ($tmplist eq "");
187 $self->output("$ctx->{TYPE}\_$ctx->{NAME}_$var =$tmplist\n");
190 sub SharedLibrary
($$)
192 my ($self,$ctx) = @_;
197 if ($self->{duplicate_build
}) {
198 $installdir = $ctx->{RELEASEDIR
};
200 $installdir = $ctx->{DEBUGDIR
};
203 if ($ctx->{TYPE
} eq "LIBRARY") {
204 push (@
{$self->{shared_libs
}}, "$ctx->{DEBUGDIR}/$ctx->{LIBRARY_REALNAME}");
205 push (@
{$self->{installable_shared_libs
}}, "$installdir/$ctx->{LIBRARY_REALNAME}");
206 } elsif ($ctx->{TYPE
} eq "MODULE") {
207 push (@
{$self->{shared_modules
}}, "$ctx->{DEBUGDIR}/$ctx->{LIBRARY_REALNAME}");
208 push (@
{$self->{plugins
}}, "$installdir/$ctx->{LIBRARY_REALNAME}");
210 my $fixedname = $ctx->{NAME
};
212 $fixedname =~ s/^$ctx->{SUBSYSTEM}_//g;
214 $self->{install_plugins
} .= "\t\@echo Installing $installdir/$ctx->{LIBRARY_REALNAME} as \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$fixedname.\$(SHLIBEXT)\n";
215 $self->{install_plugins
} .= "\t\@mkdir -p \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/\n";
216 $self->{install_plugins
} .= "\t\@cp $installdir/$ctx->{LIBRARY_REALNAME} \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$fixedname.\$(SHLIBEXT)\n";
217 $self->{uninstall_plugins
} .= "\t\@echo Uninstalling \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$fixedname.\$(SHLIBEXT)\n";
218 $self->{uninstall_plugins
} .= "\t\@-rm \$(DESTDIR)\$(MODULESDIR)/$ctx->{SUBSYSTEM}/$fixedname.\$(SHLIBEXT)\n";
221 $self->_prepare_list($ctx, "OBJ_LIST");
222 $self->_prepare_list($ctx, "CFLAGS");
223 $self->_prepare_list($ctx, "DEPEND_LIST");
224 $self->_prepare_list($ctx, "LINK_LIST");
225 $self->_prepare_list($ctx, "LINK_FLAGS");
227 push(@
{$self->{all_objs
}}, "\$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)");
229 if ($ctx->{TYPE
} eq "MODULE" and defined($ctx->{INIT_FUNCTION
})) {
230 my $init_fn = $ctx->{INIT_FUNCTION_TYPE
};
231 $init_fn =~ s/\(\*\)/init_module/;
232 my $proto_fn = $ctx->{INIT_FUNCTION_TYPE
};
233 $proto_fn =~ s/\(\*\)/$ctx->{INIT_FUNCTION}/;
235 $self->output(<< "__EOD__"
236 bin
/$ctx->{NAME
}_init_module
.c
:
238 \
@echo \"#include \\\"includes.h\\\"\" > \$\@
239 \
@echo \"$proto_fn;\" >> \
$\@
240 \
@echo -e
\"_PUBLIC_
$init_fn \\n
{\\n
\\treturn
$ctx->{INIT_FUNCTION
}();\\n
}\\n
\" >> \
$\@
243 $init_obj = "bin/$ctx->{NAME}_init_module.o";
248 if ($self->{config
}->{SONAMEFLAG
} ne "" and
249 defined($ctx->{LIBRARY_SONAME
})) {
250 $soarg = "$self->{config}->{SONAMEFLAG}$ctx->{LIBRARY_SONAME} ";
253 if ($self->{config
}->{SONAMEFLAG
} ne "") {
254 $soargdebug = "$self->{config}->{SONAMEFLAG}$ctx->{LIBRARY_REALNAME} ";
257 if ($self->{duplicate_build
}) {
258 $self->output(<< "__EOD__"
261 $ctx->{TARGET
}: \
$($ctx->{TYPE
}_
$ctx->{NAME
}_DEPEND_LIST
) \
$($ctx->{TYPE
}_
$ctx->{NAME
}_OBJ_LIST
) $init_obj
263 \
@mkdir -p
$ctx->{DEBUGDIR
}
264 \@\
$(SHLD
) \
$(SHLD_FLAGS
) -o \
$\@ \
$(LOCAL_LINK_FLAGS
) \\
265 \
$($ctx->{TYPE
}_
$ctx->{NAME
}_LINK_FLAGS
) $soargdebug \\
266 $init_obj \
$($ctx->{TYPE
}_
$ctx->{NAME
}_LINK_LIST
)
272 $self->output(<< "__EOD__"
275 $installdir/$ctx->{LIBRARY_REALNAME
}: \
$($ctx->{TYPE
}_
$ctx->{NAME
}_DEPEND_LIST
) \
$($ctx->{TYPE
}_
$ctx->{NAME
}_OBJ_LIST
) $init_obj
277 \@\
$(SHLD
) \
$(SHLD_FLAGS
) -o \
$\@
\\
278 \
$($ctx->{TYPE
}_
$ctx->{NAME
}_LINK_FLAGS
) $soarg \\
279 $init_obj \
$($ctx->{TYPE
}_
$ctx->{NAME
}_LINK_LIST
)
287 my ($self,$ctx) = @_;
289 return unless $ctx->{TARGET
};
291 $self->_prepare_list($ctx, "OBJ_LIST");
292 $self->_prepare_list($ctx, "CFLAGS");
293 $self->_prepare_list($ctx, "DEPEND_LIST");
295 push(@
{$self->{all_objs
}}, "\$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)");
297 $self->output("$ctx->{TARGET}: \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n");
299 $self->output("\t\@echo \"Pre-Linking $ctx->{TYPE} $ctx->{NAME}\"\n");
300 $self->output("\t@\$(LD) -r \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST) -o $ctx->{TARGET}\n");
306 my ($self,$ctx) = @_;
308 return unless $ctx->{TARGET
};
310 push(@
{$self->{all_objs
}}, "\$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)");
312 $self->_prepare_list($ctx, "OBJ_LIST");
313 $self->_prepare_list($ctx, "CFLAGS");
314 $self->_prepare_list($ctx, "DEPEND_LIST");
315 $self->output("$ctx->{TARGET}: ");
316 $self->output("\$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n");
317 $self->output("\t\@touch $ctx->{TARGET}\n");
320 sub StaticLibrary
($$)
322 my ($self,$ctx) = @_;
324 push (@
{$self->{static_libs
}}, $ctx->{OUTPUT
});
326 $self->_prepare_list($ctx, "OBJ_LIST");
327 $self->_prepare_list($ctx, "CFLAGS");
329 $self->_prepare_list($ctx, "DEPEND_LIST");
330 $self->_prepare_list($ctx, "LINK_LIST");
331 $self->_prepare_list($ctx, "LINK_FLAGS");
333 push(@
{$self->{all_objs
}}, "\$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)");
335 $self->output(<< "__EOD__"
337 $ctx->{TARGET
}: \
$($ctx->{TYPE
}_
$ctx->{NAME
}_DEPEND_LIST
) \
$($ctx->{TYPE
}_
$ctx->{NAME
}_OBJ_LIST
)
339 \@\
$(STLD
) \
$(STLD_FLAGS
) \
$@
\\
340 \
$($ctx->{TYPE
}_
$ctx->{NAME
}_LINK_LIST
)
348 my ($self,$ctx) = @_;
350 foreach (@
{$ctx->{PUBLIC_HEADERS
}}) {
351 push (@
{$self->{headers
}}, "$ctx->{BASEDIR}/$_");
357 my ($self,$ctx) = @_;
361 if ($self->{duplicate_build
}) {
362 $installdir = "bin/install";
367 push(@
{$self->{all_objs
}}, "\$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)");
369 unless (defined($ctx->{INSTALLDIR
})) {
370 } elsif ($ctx->{INSTALLDIR
} eq "SBINDIR") {
371 push (@
{$self->{sbin_progs
}}, "$installdir/$ctx->{BINARY}");
372 } elsif ($ctx->{INSTALLDIR
} eq "BINDIR") {
373 push (@
{$self->{bin_progs
}}, "$installdir/$ctx->{BINARY}");
376 push (@
{$self->{binaries
}}, "bin/$ctx->{BINARY}");
378 $self->_prepare_list($ctx, "OBJ_LIST");
379 $self->_prepare_list($ctx, "CFLAGS");
380 $self->_prepare_list($ctx, "DEPEND_LIST");
381 $self->_prepare_list($ctx, "LINK_LIST");
382 $self->_prepare_list($ctx, "LINK_FLAGS");
384 if ($self->{duplicate_build
}) {
385 $self->output(<< "__EOD__"
387 bin
/$ctx->{BINARY
}: \
$($ctx->{TYPE
}_
$ctx->{NAME
}_DEPEND_LIST
) \
$($ctx->{TYPE
}_
$ctx->{NAME
}_OBJ_LIST
)
389 \@\
$(CC
) \
$(LDFLAGS
) -o \
$\@ \
$(LOCAL_LINK_FLAGS
) \
$(INSTALL_LINK_FLAGS
) \\
390 \
$\
($ctx->{TYPE
}_
$ctx->{NAME
}_LINK_LIST
) \\
391 \
$\
($ctx->{TYPE
}_
$ctx->{NAME
}_LINK_FLAGS
)
397 $self->output(<< "__EOD__"
398 $installdir/$ctx->{BINARY
}: \
$($ctx->{TYPE
}_
$ctx->{NAME
}_DEPEND_LIST
) \
$($ctx->{TYPE
}_
$ctx->{NAME
}_OBJ_LIST
)
400 \@\
$(CC
) \
$(LDFLAGS
) -o \
$\@ \
$(INSTALL_LINK_FLAGS
) \\
401 \
$\
($ctx->{TYPE
}_
$ctx->{NAME
}_LINK_LIST
) \\
402 \
$\
($ctx->{TYPE
}_
$ctx->{NAME
}_LINK_FLAGS
)
410 my ($self,$ctx) = @_;
412 my $dir = $ctx->{BASEDIR
};
416 push (@
{$self->{manpages
}}, "$dir/$ctx->{MANPAGE}");
421 my ($self,$ctx) = @_;
423 my $link_name = $ctx->{NAME
};
425 $link_name =~ s/^LIB//g;
426 $link_name = lc($link_name);
428 if (not defined($ctx->{DESCRIPTION
})) {
429 warn("$ctx->{NAME} has not DESCRIPTION set, not generating .pc file");
433 my $path = "$ctx->{BASEDIR}/$link_name.pc";
435 push (@
{$self->{pc_files
}}, $path);
437 smb_build
::env
::PkgConfig
($self,
450 my ($self,$ctx) = @_;
452 my $dir = $ctx->{BASEDIR
};
456 my $comment = "Creating ";
457 if (defined($ctx->{PRIVATE_PROTO_HEADER
})) {
458 $comment.= "$dir/$ctx->{PRIVATE_PROTO_HEADER}";
459 if (defined($ctx->{PUBLIC_PROTO_HEADER
})) {
462 push (@
{$self->{proto_headers
}}, "$dir/$ctx->{PRIVATE_PROTO_HEADER}");
464 $ctx->{PRIVATE_PROTO_HEADER
} = $ctx->{PUBLIC_PROTO_HEADER
};
467 if (defined($ctx->{PUBLIC_PROTO_HEADER
})) {
468 $comment.= "$dir/$ctx->{PUBLIC_PROTO_HEADER}";
469 push (@
{$self->{proto_headers
}}, "$dir/$ctx->{PUBLIC_PROTO_HEADER}");
471 $ctx->{PUBLIC_PROTO_HEADER
} = $ctx->{PRIVATE_PROTO_HEADER
};
474 $self->output("$dir/$ctx->{PUBLIC_PROTO_HEADER}: \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST:.o=.c)\n");
475 $self->output("\t\@echo \"$comment\"\n");
477 $self->output("\t\@\$(PERL) \$(srcdir)/script/mkproto.pl --private=$dir/$ctx->{PRIVATE_PROTO_HEADER} --public=$dir/$ctx->{PUBLIC_PROTO_HEADER} \$($ctx->{TYPE}_$ctx->{NAME}_OBJ_LIST)\n\n");
482 my ($self,$file) = @_;
484 $self->output("MANPAGES = ".array2oneperline
($self->{manpages
})."\n");
485 $self->output("BIN_PROGS = " . array2oneperline
($self->{bin_progs
}) . "\n");
486 $self->output("SBIN_PROGS = " . array2oneperline
($self->{sbin_progs
}) . "\n");
487 $self->output("BINARIES = " . array2oneperline
($self->{binaries
}) . "\n");
488 $self->output("STATIC_LIBS = " . array2oneperline
($self->{static_libs
}) . "\n");
489 $self->output("SHARED_LIBS = " . array2oneperline
($self->{shared_libs
}) . "\n");
490 $self->output("INSTALLABLE_SHARED_LIBS = " . array2oneperline
($self->{installable_shared_libs
}) . "\n");
491 $self->output("PUBLIC_HEADERS = " . array2oneperline
($self->{headers
}) . "\n");
492 $self->output("PC_FILES = " . array2oneperline
($self->{pc_files
}) . "\n");
493 $self->output("ALL_OBJS = " . array2oneperline
($self->{all_objs
}) . "\n");
494 $self->output("PROTO_HEADERS = " . array2oneperline
($self->{proto_headers
}) . "\n");
495 $self->output("SHARED_MODULES = " . array2oneperline
($self->{shared_modules
}) . "\n");
496 $self->output("PLUGINS = " . array2oneperline
($self->{plugins
}) . "\n");
498 $self->output("\ninstallplugins: \$(PLUGINS)\n".$self->{install_plugins
}."\n");
499 $self->output("\nuninstallplugins:\n".$self->{uninstall_plugins
}."\n");
501 # nasty hack to allow running locally
502 if ($self->{duplicate_build
}) {
503 $self->output("bin/libdynconfig.\$(SHLIBEXT): dynconfig-devel.o\n");
504 $self->output("bin/libdynconfig.\$(SHLIBEXT): LIBRARY_DYNCONFIG_OBJ_LIST=dynconfig-devel.o\n");
507 $self->_prepare_mk_files();
509 $self->output($self->{mkfile
});
511 if ($self->{developer
}) {
512 $self->output(<<__EOD__
514 -include \
$(DEP_FILES
)
520 open(MAKEFILE
,">$file") || die ("Can't open $file\n");
521 print MAKEFILE
$self->{output
};
524 print __FILE__
.": creating $file\n";