1 ###########################################################
2 ### SMB Build System ###
3 ### - create output for Makefile ###
5 ### Copyright (C) Stefan (metze) Metzmacher 2004 ###
6 ### Copyright (C) Jelmer Vernooij 2005 ###
7 ### Released under the GNU GPL ###
8 ###########################################################
11 use config qw(%config);
14 sub _prepare_path_vars()
18 $output = << '__EOD__';
20 exec_prefix = @exec_prefix@
21 selftest_prefix = @selftest_prefix@
30 CONFIGDIR = @configdir@
31 localstatedir = @localstatedir@
33 VARDIR = @localstatedir@
35 # The permissions to give the executables
38 # set these to where to find various files
39 # These can be overridden by command line switches (see smbd(8))
40 # or in smb.conf (see smb.conf(5))
41 LOGFILEBASE = @logfilebase@
42 CONFIGFILE = $(CONFIGDIR)/smb.conf
43 LMHOSTSFILE = $(CONFIGDIR)/lmhosts
44 NCALRPCDIR = @localstatedir@/ncalrpc
46 # This is where smbpasswd et al go
47 PRIVATEDIR = @privatedir@
48 SMB_PASSWD_FILE = $(PRIVATEDIR)/smbpasswd
50 # the directory where lock files go
53 # the directory where pid files go
58 PATH_FLAGS = -DCONFIGFILE=\"$(CONFIGFILE)\" -DSBINDIR=\"$(SBINDIR)\" \
59 -DBINDIR=\"$(BINDIR)\" -DLMHOSTSFILE=\"$(LMHOSTSFILE)\" \
60 -DLOCKDIR=\"$(LOCKDIR)\" -DPIDDIR=\"$(PIDDIR)\" -DLIBDIR=\"$(LIBDIR)\" \
61 -DLOGFILEBASE=\"$(LOGFILEBASE)\" -DSHLIBEXT=\"@SHLIBEXT@\" \
62 -DCONFIGDIR=\"$(CONFIGDIR)\" -DNCALRPCDIR=\"$(NCALRPCDIR)\" \
63 -DSWATDIR=\"$(SWATDIR)\" -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" \
64 -DPRIVATE_DIR=\"$(PRIVATEDIR)\"
70 sub _prepare_compiler_linker()
76 CFLAGS=-I\$(srcdir)/include -I\$(srcdir) -D_SAMBA_BUILD_ -DHAVE_CONFIG_H -I\$(srcdir)/lib $config{CFLAGS} $config{CPPFLAGS}
79 LD_FLAGS=$config{LDFLAGS} -Lbin
85 SHLD_FLAGS=$config{LDSHFLAGS} -Lbin
87 XSLTPROC=$config{XSLTPROC}
92 DEFAULT_TEST_TARGET=$config{DEFAULT_TEST_TARGET}
97 sub _prepare_default_rule()
105 sub _prepare_SUFFIXES()
108 .SUFFIXES: .x .c .et .y .l .d .o .h .h.gch .a .so .1 .1.xml .3 .3.xml .5 .5.xml .7 .7.xml
113 sub _prepare_man_rule($)
118 .$suffix.xml.$suffix:
119 \$(XSLTPROC) -o \$@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl \$<
124 sub _prepare_binaries($)
131 foreach (values %$ctx) {
132 next unless defined $_->{OUTPUT_TYPE};
133 next unless ($_->{OUTPUT_TYPE} eq "BINARY");
135 push(@sbn_list, $_->{OUTPUT}) if ($_->{INSTALLDIR} eq "SBINDIR");
136 push(@bbn_list, $_->{OUTPUT}) if ($_->{INSTALLDIR} eq "BINDIR");
139 my $bbn = array2oneperline(\@bbn_list);
140 my $sbn = array2oneperline(\@sbn_list);
147 sub _prepare_manpages($)
153 foreach (values %$ctx) {
154 push (@mp_list, $_->{MANPAGE}) if (defined($_->{MANPAGE}) and $_->{MANPAGE} ne "");
157 my $mp = array2oneperline(\@mp_list);
164 sub _prepare_dummy_MAKEDIR()
172 dynconfig.o: dynconfig.c Makefile
174 @$(CC) $(CFLAGS) @PICFLAG@ $(PATH_FLAGS) -c $< -o $@
175 @BROKEN_CC@ -mv `echo $@ | sed 's%^.*/%%g'` $@
180 sub _prepare_depend_CC_rule()
185 @echo "Generating dependencies for $<"
186 @$(CC) -MM -MG -MT $(<:.c=.o) -MF $@ $(CFLAGS) $<
191 ###########################################################
192 # This function creates a standard make rule which is using $(CC)
194 # $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
196 # $srcext - sourcefile extension
198 # $destext - destinationfile extension
200 # $flags - additional compiler flags
202 # $message - logmessage which is echoed while running this rule
204 # $comment - just a comment what this rule should do
206 # $output - the resulting output buffer
207 sub _prepare_std_CC_rule($$$$$)
209 my ($src,$dst,$flags,$message,$comment) = @_;
214 \@echo $message \$\*.$src
215 \@\$(CC) `script/cflags.sh \$\@` \$(CFLAGS) $flags -c \$< -o \$\@
216 \@BROKEN_CC\@ -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
221 sub array2oneperline($)
227 next unless defined($_);
229 $output .= " \\\n\t\t$_";
235 ###########################################################
236 # This function creates a object file list
238 # $output = _prepare_var_obj_list($var, $var_ctx)
240 # $var_ctx - the subsystem context
242 # $var_ctx->{NAME} - the <var> name
243 # $var_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this <var>
245 # $output - the resulting output buffer
246 sub _prepare_obj_list($$)
250 my $tmplist = array2oneperline($ctx->{OBJ_LIST});
253 # $var $ctx->{NAME} OBJ LIST
254 $var\_$ctx->{NAME}_OBJS =$tmplist
259 sub _prepare_cflags($$)
263 my $tmplist = array2oneperline($ctx->{CFLAGS});
266 $var\_$ctx->{NAME}_CFLAGS =$tmplist
271 ###########################################################
272 # This function creates a make rule for linking a library
274 # $output = _prepare_shared_library_rule($library_ctx)
276 # $library_ctx - the library context
278 # $library_ctx->{NAME} - the library name
280 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
282 # $library_ctx->{LIBRARY_NAME} - the shared library name
283 # $library_ctx->{LIBRARY_REALNAME} - the shared library real name
284 # $library_ctx->{LIBRARY_SONAME} - the shared library soname
285 # $library_ctx->{LINK_LIST} - the list of objectfiles and external libraries
286 # which sould be linked to this shared library
287 # $library_ctx->{LINK_FLAGS} - linker flags used by this shared library
289 # $output - the resulting output buffer
290 sub _prepare_shared_library_rule($)
295 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
296 my $tmpshlink = array2oneperline($ctx->{LINK_LIST});
297 my $tmpshflag = array2oneperline($ctx->{LINK_FLAGS});
299 $output = << "__EOD__";
300 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
302 LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
303 LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
306 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) \$(LIBRARY_$ctx->{NAME}_OBJS) bin/.dummy
308 \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
309 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
310 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
314 if (defined($ctx->{LIBRARY_SONAME})) {
315 $output .= << "__EOD__";
316 # Symlink $ctx->{LIBRARY_SONAME}
317 bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
319 \@ln -sf $ctx->{LIBRARY_REALNAME} \$\@
320 # Symlink $ctx->{LIBRARY_NAME}
321 bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
323 \@ln -sf $ctx->{LIBRARY_SONAME} \$\@
328 $output .= << "__EOD__";
329 library_$ctx->{NAME}: basics bin/lib$ctx->{LIBRARY_NAME}
336 sub _prepare_mergedobj_rule($)
340 return "" unless $ctx->{TARGET};
342 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
344 my $output = "$ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST = $tmpdepend\n";
346 $output .= "$ctx->{TARGET}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJS)\n";
348 $output .= "\t\@echo \"Pre-Linking $ctx->{TYPE} $ctx->{NAME}\"\n";
349 $output .= "\t@\$(LD) -r \$($ctx->{TYPE}_$ctx->{NAME}_OBJS) -o $ctx->{TARGET}\n";
355 sub _prepare_objlist_rule($)
358 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
360 return "" unless $ctx->{TARGET};
362 my $output = "$ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST = $tmpdepend\n";
363 $output .= "$ctx->{TARGET}: ";
364 $output .= "\$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJS)\n";
365 $output .= "\t\@touch $ctx->{TARGET}\n";
370 ###########################################################
371 # This function creates a make rule for linking a library
373 # $output = _prepare_static_library_rule($library_ctx)
375 # $library_ctx - the library context
377 # $library_ctx->{NAME} - the library name
379 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
381 # $library_ctx->{LIBRARY_NAME} - the static library name
382 # $library_ctx->{LINK_LIST} - the list of objectfiles which sould be linked
383 # to this static library
384 # $library_ctx->{LINK_FLAGS} - linker flags used by this static library
386 # $output - the resulting output buffer
387 sub _prepare_static_library_rule($)
392 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
393 my $tmpstlink = array2oneperline($ctx->{LINK_LIST});
394 my $tmpstflag = array2oneperline($ctx->{LINK_FLAGS});
396 $output = << "__EOD__";
397 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
399 LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
401 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) \$(LIBRARY_$ctx->{NAME}_OBJS) bin/.dummy
403 \@\$(STLD) \$(STLD_FLAGS) \$@ \\
404 \$(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
406 library_$ctx->{NAME}: basics $ctx->{TARGET}
413 ###########################################################
414 # This function creates a make rule for linking a binary
416 # $output = _prepare_binary_rule($binary_ctx)
418 # $binary_ctx - the binary context
420 # $binary_ctx->{NAME} - the binary name
421 # $binary_ctx->{BINARY} - the binary binary name
423 # $binary_ctx->{DEPEND_LIST} - the list of rules on which this binary depends
424 # $binary_ctx->{LINK_LIST} - the list of objectfiles and external libraries
425 # which sould be linked to this binary
426 # $binary_ctx->{LINK_FLAGS} - linker flags used by this binary
428 # $output - the resulting output buffer
429 sub _prepare_binary_rule($)
433 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
434 my $tmplink = array2oneperline($ctx->{LINK_LIST});
435 my $tmpflag = array2oneperline($ctx->{LINK_FLAGS});
437 my $output = << "__EOD__";
439 BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
440 BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
441 BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
443 bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST) \$(BINARY_$ctx->{NAME}_OBJS)
445 \@\$(CC) \$(LD_FLAGS) -o \$\@ \\
446 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
447 \$\(BINARY_$ctx->{NAME}_LINK_LIST) \\
448 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS)
449 binary_$ctx->{BINARY}: basics bin/$ctx->{BINARY}
456 sub _prepare_custom_rule($)
460 $ctx->{NAME}: bin/.TARGET_$ctx->{NAME}
462 bin/.TARGET_$ctx->{NAME}:
464 touch bin/.TARGET_$ctx->{NAME}
468 sub _prepare_proto_rules()
470 my $output = << '__EOD__';
471 # Making this target will just make sure that the prototype files
472 # exist, not necessarily that they are up to date. Since they're
473 # removed by 'make clean' this will always be run when you do anything
475 proto_exists: include/proto.h
477 delheaders: pch_clean
478 -rm -f $(builddir)/include/proto.h
481 @cd $(srcdir) && $(SHELL) script/mkproto.sh "$(PERL)" \
482 -h _PROTO_H_ $(builddir)/include/proto.h \
485 # 'make headers' or 'make proto' calls a subshell because we need to
486 # make sure these commands are executed in sequence even for a
488 headers: delheaders proto_exists
493 @[ -f $(builddir)/include/proto.h ] || $(MAKE) proto
496 @echo Removing objects
497 @-find . -name '*.o' -exec rm -f '{}' \;
498 @echo Removing binaries
500 @echo Removing dummy targets
502 @echo Removing generated files
503 @-rm -rf librpc/gen_*
504 @echo Removing generated ASN1 files
505 @-find heimdal/lib/asn1 -name 'asn1_*.[xc]' -exec rm -f '{}' \;
506 @-find heimdal/lib/gssapi -name 'asn1_*.[xc]' -exec rm -f '{}' \;
507 @-find heimdal/lib/hdb -name 'asn1_*.[xc]' -exec rm -f '{}' \;
512 -rm -f include/config.h include/smb_build.h
515 -rm -f config.log config.cache
516 -rm -f samba4-deps.dot
517 -rm -f config.pm config.mk
518 -rm -f lib/registry/winregistry.pc
521 if ($config{developer} eq "yes") {
522 $output .= "\t@-rm -f \$(_ALL_OBJS_OBJS:.o=.d)\n";
525 $output .= << '__EOD__';
528 -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
530 realdistclean: distclean removebackup
531 -rm -f include/config.h.in
532 -rm -f include/version.h
540 sub _prepare_make_target($)
545 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
548 $ctx->{TARGET}: basics $tmpdepend
553 sub _prepare_target_settings($)
558 foreach my $key (values %$CTX) {
559 if (defined($key->{OBJ_LIST})) {
560 $output .= _prepare_obj_list($key->{TYPE}, $key);
561 $output .= _prepare_cflags($key->{TYPE}, $key);
568 sub _prepare_rule_lists($)
573 foreach my $key (values %{$depend}) {
574 next unless defined $key->{OUTPUT_TYPE};
576 ($output .= _prepare_mergedobj_rule($key)) if $key->{OUTPUT_TYPE} eq "MERGEDOBJ";
577 ($output .= _prepare_objlist_rule($key)) if $key->{OUTPUT_TYPE} eq "OBJLIST";
578 ($output .= _prepare_static_library_rule($key)) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
579 ($output .= _prepare_shared_library_rule($key)) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
580 ($output .= _prepare_binary_rule($key)) if $key->{OUTPUT_TYPE} eq "BINARY";
581 ($output .= _prepare_custom_rule($key) ) if $key->{TYPE} eq "TARGET";
584 $output .= _prepare_proto_rules();
589 ###########################################################
590 # This function prepares the output for Makefile
592 # $output = _prepare_makefile_in($OUTPUT)
594 # $OUTPUT - the global OUTPUT context
596 # $output - the resulting output buffer
597 sub _prepare_makefile_in($)
602 $output = "########################################\n";
603 $output .= "# Autogenerated by config.smb_build.pl #\n";
604 $output .= "########################################\n";
607 $output .= _prepare_path_vars();
608 $output .= _prepare_compiler_linker();
609 $output .= _prepare_default_rule();
610 $output .= _prepare_SUFFIXES();
611 $output .= _prepare_dummy_MAKEDIR();
612 $output .= _prepare_std_CC_rule("c","o",$config{PICFLAG},"Compiling","Rule for std objectfiles");
613 $output .= _prepare_std_CC_rule("h","h.gch",$config{PICFLAG},"Precompiling","Rule for precompiled headerfiles");
615 $output .= _prepare_depend_CC_rule();
617 $output .= _prepare_man_rule("1");
618 $output .= _prepare_man_rule("3");
619 $output .= _prepare_man_rule("5");
620 $output .= _prepare_man_rule("7");
621 $output .= _prepare_manpages($CTX);
622 $output .= _prepare_binaries($CTX);
623 $output .= _prepare_target_settings($CTX);
624 $output .= _prepare_rule_lists($CTX);
626 if ($config{developer} eq "yes") {
628 #-include \$(_ALL_OBJS_OBJS:.o=.d)
629 IDL_FILES = \$(wildcard librpc/idl/*.idl)
630 \$(patsubst librpc/idl/%.idl,librpc/gen_ndr/ndr_%.c,\$(IDL_FILES)) \\
631 \$(patsubst librpc/idl/%.idl,librpc/gen_ndr/ndr_\%_c.c,\$(IDL_FILES)) \\
632 \$(patsubst librpc/idl/%.idl,librpc/gen_ndr/ndr_%.h,\$(IDL_FILES)): idl
639 ###########################################################
640 # This function creates Makefile.in from the OUTPUT
643 # create_makefile_in($OUTPUT)
645 # $OUTPUT - the global OUTPUT context
647 # $output - the resulting output buffer
648 sub create_makefile_in($$$)
650 my ($CTX, $mk, $file) = @_;
652 open(MAKEFILE_IN,">$file") || die ("Can't open $file\n");
653 print MAKEFILE_IN _prepare_makefile_in($CTX) . $mk;
656 print "config.smb_build.pl: creating $file\n";