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}
94 DEFAULT_TEST_TARGET=$config{DEFAULT_TEST_TARGET}
99 sub _prepare_default_rule()
107 sub _prepare_SUFFIXES()
110 .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
115 sub _prepare_man_rule($)
120 .$suffix.xml.$suffix:
121 \$(XSLTPROC) -o \$@ http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl \$<
126 sub _prepare_binaries($)
133 foreach (values %$ctx) {
134 next unless defined $_->{OUTPUT_TYPE};
135 next unless ($_->{OUTPUT_TYPE} eq "BINARY");
137 push(@sbn_list, $_->{OUTPUT}) if ($_->{INSTALLDIR} eq "SBINDIR");
138 push(@bbn_list, $_->{OUTPUT}) if ($_->{INSTALLDIR} eq "BINDIR");
141 my $bbn = array2oneperline(\@bbn_list);
142 my $sbn = array2oneperline(\@sbn_list);
149 sub _prepare_manpages($)
155 foreach (values %$ctx) {
156 push (@mp_list, $_->{MANPAGE}) if (defined($_->{MANPAGE}) and $_->{MANPAGE} ne "");
159 my $mp = array2oneperline(\@mp_list);
166 sub _prepare_dummy_MAKEDIR()
174 dynconfig.o: dynconfig.c Makefile
176 @$(CC) $(CFLAGS) @PICFLAG@ $(PATH_FLAGS) -c $< -o $@
177 @BROKEN_CC@ -mv `echo $@ | sed 's%^.*/%%g'` $@
182 sub _prepare_depend_CC_rule()
187 @echo "Generating dependencies for $<"
188 @$(CC) -MM -MG -MT $(<:.c=.o) -MF $@ $(CFLAGS) $<
193 ###########################################################
194 # This function creates a standard make rule which is using $(CC)
196 # $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
198 # $srcext - sourcefile extension
200 # $destext - destinationfile extension
202 # $flags - additional compiler flags
204 # $message - logmessage which is echoed while running this rule
206 # $comment - just a comment what this rule should do
208 # $output - the resulting output buffer
209 sub _prepare_std_CC_rule($$$$$)
211 my ($src,$dst,$flags,$message,$comment) = @_;
216 \@echo $message \$\*.$src
217 \@\$(CC) `script/cflags.sh \$\@` \$(CFLAGS) $flags -c \$< -o \$\@
218 \@BROKEN_CC\@ -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
223 sub array2oneperline($)
229 next unless defined($_);
231 $output .= " \\\n\t\t$_";
237 ###########################################################
238 # This function creates a object file list
240 # $output = _prepare_var_obj_list($var, $var_ctx)
242 # $var_ctx - the subsystem context
244 # $var_ctx->{NAME} - the <var> name
245 # $var_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this <var>
247 # $output - the resulting output buffer
248 sub _prepare_obj_list($$)
252 my $tmplist = array2oneperline($ctx->{OBJ_LIST});
253 return "" if ($tmplist eq "");
256 $var\_$ctx->{NAME}_OBJS =$tmplist
260 sub _prepare_cflags($$)
264 my $tmplist = array2oneperline($ctx->{CFLAGS});
265 return "" if ($tmplist eq "");
268 $var\_$ctx->{NAME}_CFLAGS =$tmplist
273 ###########################################################
274 # This function creates a make rule for linking a library
276 # $output = _prepare_shared_library_rule($library_ctx)
278 # $library_ctx - the library context
280 # $library_ctx->{NAME} - the library name
282 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
284 # $library_ctx->{LIBRARY_NAME} - the shared library name
285 # $library_ctx->{LIBRARY_REALNAME} - the shared library real name
286 # $library_ctx->{LIBRARY_SONAME} - the shared library soname
287 # $library_ctx->{LINK_LIST} - the list of objectfiles and external libraries
288 # which sould be linked to this shared library
289 # $library_ctx->{LINK_FLAGS} - linker flags used by this shared library
291 # $output - the resulting output buffer
292 sub _prepare_shared_library_rule($)
297 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
298 my $tmpshlink = array2oneperline($ctx->{LINK_LIST});
299 my $tmpshflag = array2oneperline($ctx->{LINK_FLAGS});
301 $output = << "__EOD__";
302 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
303 LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
304 LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
307 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) \$(LIBRARY_$ctx->{NAME}_OBJS) bin/.dummy
309 \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
310 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
311 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
315 if (defined($ctx->{LIBRARY_SONAME})) {
316 $output .= << "__EOD__";
317 # Symlink $ctx->{LIBRARY_SONAME}
318 bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
320 \@ln -sf $ctx->{LIBRARY_REALNAME} \$\@
321 # Symlink $ctx->{LIBRARY_NAME}
322 bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
324 \@ln -sf $ctx->{LIBRARY_SONAME} \$\@
329 $output .= << "__EOD__";
330 library_$ctx->{NAME}: basics bin/lib$ctx->{LIBRARY_NAME}
337 sub _prepare_mergedobj_rule($)
341 return "" unless $ctx->{TARGET};
343 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
345 my $output = "$ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST = $tmpdepend\n";
347 $output .= "$ctx->{TARGET}: \$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJS)\n";
349 $output .= "\t\@echo \"Pre-Linking $ctx->{TYPE} $ctx->{NAME}\"\n";
350 $output .= "\t@\$(LD) -r \$($ctx->{TYPE}_$ctx->{NAME}_OBJS) -o $ctx->{TARGET}\n";
356 sub _prepare_objlist_rule($)
359 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
361 return "" unless $ctx->{TARGET};
363 my $output = "$ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST = $tmpdepend\n";
364 $output .= "$ctx->{TARGET}: ";
365 $output .= "\$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJS)\n";
366 $output .= "\t\@touch $ctx->{TARGET}\n";
371 ###########################################################
372 # This function creates a make rule for linking a library
374 # $output = _prepare_static_library_rule($library_ctx)
376 # $library_ctx - the library context
378 # $library_ctx->{NAME} - the library name
380 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
382 # $library_ctx->{LIBRARY_NAME} - the static library name
383 # $library_ctx->{LINK_LIST} - the list of objectfiles which sould be linked
384 # to this static library
385 # $library_ctx->{LINK_FLAGS} - linker flags used by this static library
387 # $output - the resulting output buffer
388 sub _prepare_static_library_rule($)
393 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
394 my $tmpstlink = array2oneperline($ctx->{LINK_LIST});
395 my $tmpstflag = array2oneperline($ctx->{LINK_FLAGS});
397 $output = << "__EOD__";
398 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
400 LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
402 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) \$(LIBRARY_$ctx->{NAME}_OBJS) bin/.dummy
404 \@\$(STLD) \$(STLD_FLAGS) \$@ \\
405 \$(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
407 library_$ctx->{NAME}: basics $ctx->{TARGET}
414 ###########################################################
415 # This function creates a make rule for linking a binary
417 # $output = _prepare_binary_rule($binary_ctx)
419 # $binary_ctx - the binary context
421 # $binary_ctx->{NAME} - the binary name
422 # $binary_ctx->{BINARY} - the binary binary name
424 # $binary_ctx->{DEPEND_LIST} - the list of rules on which this binary depends
425 # $binary_ctx->{LINK_LIST} - the list of objectfiles and external libraries
426 # which sould be linked to this binary
427 # $binary_ctx->{LINK_FLAGS} - linker flags used by this binary
429 # $output - the resulting output buffer
430 sub _prepare_binary_rule($)
434 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
435 my $tmplink = array2oneperline($ctx->{LINK_LIST});
436 my $tmpflag = array2oneperline($ctx->{LINK_FLAGS});
438 my $output = << "__EOD__";
440 BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
441 BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
442 BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
444 bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST) \$(BINARY_$ctx->{NAME}_OBJS)
446 \@\$(CC) \$(LD_FLAGS) -o \$\@ \\
447 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
448 \$\(BINARY_$ctx->{NAME}_LINK_LIST) \\
449 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS)
450 binary_$ctx->{BINARY}: basics bin/$ctx->{BINARY}
457 sub _prepare_custom_rule($)
461 $ctx->{NAME}: bin/.TARGET_$ctx->{NAME}
463 bin/.TARGET_$ctx->{NAME}:
465 touch bin/.TARGET_$ctx->{NAME}
469 sub _prepare_proto_rules()
471 my $output = << '__EOD__';
472 # Making this target will just make sure that the prototype files
473 # exist, not necessarily that they are up to date. Since they're
474 # removed by 'make clean' this will always be run when you do anything
476 proto_exists: include/proto.h
478 delheaders: pch_clean
479 -rm -f $(builddir)/include/proto.h
482 @cd $(srcdir) && $(SHELL) script/mkproto.sh "$(PERL)" \
483 -h _PROTO_H_ $(builddir)/include/proto.h \
486 # 'make headers' or 'make proto' calls a subshell because we need to
487 # make sure these commands are executed in sequence even for a
489 headers: delheaders proto_exists
494 @[ -f $(builddir)/include/proto.h ] || $(MAKE) proto
496 clean: delheaders heimdal_clean
497 @echo Removing objects
498 @-find . -name '*.o' -exec rm -f '{}' \;
499 @echo Removing binaries
501 @echo Removing dummy targets
503 @echo Removing generated files
504 @-rm -rf librpc/gen_*
512 -rm -f include/config.h include/smb_build.h
513 -rm -f Makefile Makefile.in
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";