1 ###########################################################
2 ### SMB Build System ###
3 ### - create output for Makefile ###
5 ### Copyright (C) Stefan (metze) Metzmacher 2004 ###
6 ### Released under the GNU GPL ###
7 ###########################################################
12 sub _prepare_command_interpreters($)
17 $output = << '__EOD__';
26 sub _prepare_path_vars($)
31 $output = << '__EOD__';
33 exec_prefix=@exec_prefix@
42 CONFIGDIR = @configdir@
43 VARDIR = @localstatedir@
45 # The permissions to give the executables
48 # set these to where to find various files
49 # These can be overridden by command line switches (see smbd(8))
50 # or in smb.conf (see smb.conf(5))
51 LOGFILEBASE = @logfilebase@
52 CONFIGFILE = $(CONFIGDIR)/smb.conf
53 LMHOSTSFILE = $(CONFIGDIR)/lmhosts
54 NCALRPCDIR = @localstatedir@/ncalrpc
56 # This is where smbpasswd et al go
57 PRIVATEDIR = @privatedir@
58 SMB_PASSWD_FILE = $(PRIVATEDIR)/smbpasswd
60 # the directory where lock files go
63 # the directory where pid files go
66 PASSWD_FLAGS = -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" -DPRIVATE_DIR=\"$(PRIVATEDIR)\"
67 PATH_FLAGS1 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DSBINDIR=\"$(SBINDIR)\"
68 PATH_FLAGS2 = $(PATH_FLAGS1) -DBINDIR=\"$(BINDIR)\"
69 PATH_FLAGS3 = $(PATH_FLAGS2) -DLMHOSTSFILE=\"$(LMHOSTSFILE)\"
70 PATH_FLAGS4 = $(PATH_FLAGS3) -DLOCKDIR=\"$(LOCKDIR)\" -DPIDDIR=\"$(PIDDIR)\"
71 PATH_FLAGS5 = $(PATH_FLAGS4) -DLIBDIR=\"$(LIBDIR)\" \
72 -DLOGFILEBASE=\"$(LOGFILEBASE)\" -DSHLIBEXT=\"@SHLIBEXT@\"
73 PATH_FLAGS6 = $(PATH_FLAGS5) -DCONFIGDIR=\"$(CONFIGDIR)\" -DNCALRPCDIR=\"$(NCALRPCDIR)\"
74 PATH_FLAGS = $(PATH_FLAGS6) $(PASSWD_FLAGS)
81 sub _prepare_compiler_linker($)
86 $output = << '__EOD__';
88 CC_FLAGS=-Iinclude -I. -I$(srcdir)/include -I$(srcdir) -D_SAMBA_BUILD_ -DHAVE_CONFIG_H -Ilib @CFLAGS@ @CPPFLAGS@
91 LD_FLAGS=@LDFLAGS@ @CFLAGS@ -Lbin
97 SHLD_FLAGS=@LDSHFLAGS@ @LDFLAGS@ -Lbin
104 sub _prepare_default_rule($)
109 $output = << '__EOD__';
117 sub _prepare_SUFFIXES($)
122 $output = << '__EOD__';
124 .SUFFIXES: .c .o .h .h.gch .a .so
136 $output = << '__EOD__';
137 idl_full: build/pidl/idl.pm
138 CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh FULL
140 idl: build/pidl/idl.pm
141 @CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh PARTIAL
143 build/pidl/idl.pm: build/pidl/idl.yp
144 -yapp -s build/pidl/idl.yp
146 pch: proto include/includes.h.gch
149 -rm -f include/includes.h.gch
151 basics: idl proto_exists
153 test: @DEFAULT_TEST_TARGET@
156 SOCKET_WRAPPER_DIR=. ./script/tests/selftest.sh `pwd`/prefix-test
159 ./script/tests/selftest.sh `pwd`/prefix-test
166 sub _prepare_dummy_MAKEDIR()
171 $output = << '__EOD__';
175 dynconfig.o: dynconfig.c Makefile
177 @$(CC) $(CC_FLAGS) @PICFLAG@ $(PATH_FLAGS) -c $< -o $@
178 @BROKEN_CC@ -mv `echo $@ | sed 's%^.*/%%g'` $@
185 ###########################################################
186 # This function creates a standard make rule which is using $(CC)
188 # $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
190 # $srcext - sourcefile extension
192 # $destext - destinationfile extension
194 # $flags - additional compiler flags
196 # $message - logmessage which is echoed while running this rule
198 # $comment - just a comment what this rule should do
200 # $output - the resulting output buffer
201 sub _prepare_std_CC_rule($$$$$)
211 $output = << "__EOD__";
212 ###################################
215 \@echo $message \$\*.$src
216 \@\$(CC) \$(CC_FLAGS) $flags -c \$< -o \$\@
217 \@BROKEN_CC\@ -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
219 ###################################
226 sub array2oneperline($)
232 foreach my $str (@{$array}) {
233 if (!defined($str)) {
237 $output .= " \\\n\t\t";
250 foreach my $str (@{$array}) {
251 if (!defined($str)) {
262 ###########################################################
263 # This function creates a object file list
265 # $output = _prepare_var_obj_list($var, $var_ctx)
267 # $var_ctx - the subsystem context
269 # $var_ctx->{NAME} - the <var> name
270 # $var_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this <var>
272 # $output - the resulting output buffer
273 sub _prepare_obj_list($$)
280 $tmpobjlist = array2oneperline($ctx->{OBJ_LIST});
282 $output = << "__EOD__";
283 ###################################
284 # Start $var $ctx->{NAME} OBJ LIST
285 $var\_$ctx->{NAME}_OBJS =$tmpobjlist
286 # End $var $ctx->{NAME} OBJ LIST
287 ###################################
294 ###########################################################
295 # This function creates a object file list for a subsystem
297 # $output = _prepare_subsystem_obj_list($subsystem_ctx)
299 # $subsystem_ctx - the subsystem context
301 # $subsystem_ctx->{NAME} - the subsystem name
302 # $subsystem_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this subsystem
304 # $output - the resulting output buffer
305 sub _prepare_subsystem_obj_list($)
309 return _prepare_var_obj_list("SUBSYSTEM",$ctx);
312 ###########################################################
313 # This function creates a object file list for a module
315 # $output = _prepare_module_obj_and_lib_list($module_ctx)
317 # $module_ctx - the module context
319 # $module_ctx->{NAME} - the module binary name
320 # $module_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this module
322 # $output - the resulting output buffer
323 sub _prepare_module_obj_list($)
327 return _prepare_var_obj_list("MODULE",$ctx);
331 ###########################################################
332 # This function creates a make rule for linking a library
334 # $output = _prepare_shared_library_rule($library_ctx)
336 # $library_ctx - the library context
338 # $library_ctx->{NAME} - the library name
340 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
342 # $library_ctx->{LIBRARY_NAME} - the shared library name
343 # $library_ctx->{LIBRARY_REALNAME} - the shared library real name
344 # $library_ctx->{LIBRARY_SONAME} - the shared library soname
345 # $library_ctx->{LINK_LIST} - the list of objectfiles and external libraries
346 # which sould be linked to this shared library
347 # $library_ctx->{LINK_FLAGS} - linker flags used by this shared library
349 # $output - the resulting output buffer
350 sub _prepare_shared_library_rule($)
361 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
363 $tmpshlink = array2oneperline($ctx->{LINK_LIST});
364 $tmpshflag = array2oneperline($ctx->{LINK_FLAGS});
366 $output = << "__EOD__";
367 ###################################
368 # Start Library $ctx->{NAME}
370 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
372 LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
373 LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
376 # Shared $ctx->{LIBRARY_NAME}
377 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
379 \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
380 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
381 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
385 if (defined($ctx->{LIBRARY_SONAME})) {
386 $output .= << "__EOD__";
387 # Symlink $ctx->{LIBRARY_SONAME}
388 bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
390 \@ln -sf $ctx->{LIBRARY_REALNAME} \$\@
391 # Symlink $ctx->{LIBRARY_NAME}
392 bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
394 \@ln -sf $ctx->{LIBRARY_SONAME} \$\@
399 $output .= << "__EOD__";
400 library_$ctx->{NAME}: basics bin/lib$ctx->{LIBRARY_NAME}
401 # End Library $ctx->{NAME}
402 ###################################
409 ###########################################################
410 # This function creates a make rule for linking a library
412 # $output = _prepare_static_library_rule($library_ctx)
414 # $library_ctx - the library context
416 # $library_ctx->{NAME} - the library name
418 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
420 # $library_ctx->{LIBRARY_NAME} - the static library name
421 # $library_ctx->{LINK_LIST} - the list of objectfiles which sould be linked
422 # to this static library
423 # $library_ctx->{LINK_FLAGS} - linker flags used by this static library
425 # $output - the resulting output buffer
426 sub _prepare_static_library_rule($)
437 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
439 $tmpstlink = array2oneperline($ctx->{LINK_LIST});
440 $tmpstflag = array2oneperline($ctx->{LINK_FLAGS});
442 $tmprules = "bin/$ctx->{LIBRARY_NAME}";
444 $output = << '__EOD__';
445 ###################################
446 # Start Library $ctx->{NAME}
448 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
450 LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
452 # Static $ctx->{LIBRARY_NAME}
453 $ctx->{TARGET}: $(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
455 @$(STLD) $(STLD_FLAGS) $@ \\
456 $(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
458 library_$ctx->{NAME}: basics $tmprules
459 # End Library $ctx->{NAME}
460 ###################################
469 ###########################################################
470 # This function creates a make rule for linking a binary
472 # $output = _prepare_binary_rule($binary_ctx)
474 # $binary_ctx - the binary context
476 # $binary_ctx->{NAME} - the binary name
477 # $binary_ctx->{BINARY} - the binary binary name
479 # $binary_ctx->{DEPEND_LIST} - the list of rules on which this binary depends
480 # $binary_ctx->{LINK_LIST} - the list of objectfiles and external libraries
481 # which sould be linked to this binary
482 # $binary_ctx->{LINK_FLAGS} - linker flags used by this binary
484 # $output - the resulting output buffer
485 sub _prepare_binary_rule($)
493 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
494 $tmplink = array2oneperline($ctx->{LINK_LIST});
495 $tmpflag = array2oneperline($ctx->{LINK_FLAGS});
497 $output = << "__EOD__";
498 ###################################
499 # Start Binary $ctx->{BINARY}
501 BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
502 BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
503 BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
505 bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST)
507 \@\$(LD) \$(LD_FLAGS) -o \$\@ \\
508 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
509 \$\(BINARY_$ctx->{NAME}_LINK_LIST) \\
510 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS)
511 binary_$ctx->{BINARY}: basics bin/$ctx->{BINARY}
512 # End Binary $ctx->{BINARY}
513 ###################################
520 sub _prepare_proto_rules()
524 $output .= << '__EOD__';
525 # Making this target will just make sure that the prototype files
526 # exist, not necessarily that they are up to date. Since they're
527 # removed by 'make clean' this will always be run when you do anything
529 proto_exists: include/proto.h include/build_env.h
531 delheaders: pch_clean
532 -rm -f $(builddir)/include/proto.h $(builddir)/include/build_env.h:
535 @cd $(srcdir) && $(SHELL) script/mkproto.sh "$(PERL)" \
536 -h _PROTO_H_ $(builddir)/include/proto.h \
540 @echo Building include/build_env.h
541 @cd $(srcdir) && $(SHELL) script/build_env.sh $(srcdir) $(builddir) $(CC) > $(builddir)/include/build_env.h
543 # 'make headers' or 'make proto' calls a subshell because we need to
544 # make sure these commands are executed in sequence even for a
546 headers: delheaders proto_exists
551 @[ -f $(builddir)/include/proto.h ] || $(MAKE) proto
554 -rm -f *.o */*.o */*/*.o */*/*/*.o bin/*
559 -rm -f include/config.h
562 -rm -f config.smb_build.*
563 -rm -f config.log config.cache
566 -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
568 realdistclean: distclean removebackup
569 -rm -f include/config.h.in
577 sub _prepare_make_target($)
583 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
585 $output = << "__EOD__";
586 ###################################
587 # Start Target $ctx->{TARGET}
588 $ctx->{TARGET}: basics $tmpdepend
589 # End Target $ctx->{TARGET}
590 ###################################
597 sub _prepare_obj_lists($)
602 foreach my $key (values %{$CTX}) {
603 next if not defined($key->{OBJ_LIST});
604 $output .= _prepare_obj_list($key->{TYPE}, $key);
610 sub _prepare_install_rules($)
615 $output .= << '__EOD__';
618 @echo "Samba will be installed into:"
619 @echo " basedir: $(BASEDIR)"
620 @echo " bindir: $(BINDIR)"
621 @echo " sbindir: $(SBINDIR)"
622 @echo " libdir: $(LIBDIR)"
623 @echo " vardir: $(VARDIR)"
624 @echo " privatedir: $(PRIVATEDIR)"
625 @echo " piddir: $(PIDDIR)"
626 @echo " lockdir: $(LOCKDIR)"
629 @echo "Samba will be compiled with flags:"
630 @echo " CC_FLAGS = $(CC_FLAGS)"
631 @echo " LD_FLAGS = $(LD_FLAGS)"
632 @echo " STLD_FLAGS = $(STLD_FLAGS)"
633 @echo " SHLD_FLAGS = $(SHLD_FLAGS)"
635 SBIN_PROGS = bin/smbd
637 BIN_PROGS = bin/smbclient \
642 TORTURE_PROGS = bin/smbtorture \
648 LDB_PROGS = bin/ldbadd \
654 REG_PROGS = bin/regpatch \
660 install: showlayout installbin installtorture installldb installreg installdat
662 # DESTDIR is used here to prevent packagers wasting their time
663 # duplicating the Makefile. Remove it and you will have the privelege
664 # of package each samba release for muliple versions of multiple
665 # distributions and operating systems, or at least supplying patches
666 # to all the packaging files required for this, prior to committing
667 # the removal of DESTDIR. Do not remove it even though you think it
671 @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(PRIVATEDIR) $(DESTDIR)$(PIDDIR) $(DESTDIR)$(LOCKDIR)
673 installbin: all installdirs
674 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(SBIN_PROGS)
675 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(BIN_PROGS)
677 installtorture: all installdirs
678 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(TORTURE_PROGS)
680 installldb: all installdirs
681 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(LDB_PROGS)
683 installreg: all installdirs
684 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(REG_PROGS)
686 installdat: installdirs
687 @$(SHELL) $(srcdir)/script/installdat.sh $(DESTDIR)$(LIBDIR) $(srcdir)
689 uninstall: uninstallbin uninstalltorture uninstallldb uninstallreg
692 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(SBIN_PROGS)
695 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(TORTURE_PROGS)
698 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(LDB_PROGS)
701 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(REG_PROGS)
705 swig: scripting/swig/_tdb.so scripting/swig/_dcerpc.so
707 scripting/swig/tdb_wrap.c: scripting/swig/tdb.i
708 swig -python scripting/swig/tdb.i
710 scripting/swig/_tdb.so: scripting/swig/tdb_wrap.o $(LIBRARY_swig_tdb_DEPEND_LIST)
711 $(SHLD) $(SHLD_FLAGS) -o scripting/swig/_tdb.so scripting/swig/tdb_wrap.o \
712 $(LIBRARY_swig_tdb_SHARED_LINK_LIST) $(LIBRARY_swig_tdb_SHARED_LINK_FLAGS)
714 SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i
716 scripting/swig/dcerpc_wrap.c: scripting/swig/dcerpc.i scripting/swig/samba.i scripting/swig/status_codes.i $(SWIG_INCLUDES)
717 swig -python scripting/swig/dcerpc.i
719 scripting/swig/_dcerpc.so: scripting/swig/dcerpc_wrap.o $(LIBRARY_swig_dcerpc_DEPEND_LIST)
720 $(SHLD) $(SHLD_FLAGS) -o scripting/swig/_dcerpc.so scripting/swig/dcerpc_wrap.o $(LIBRARY_swig_dcerpc_SHARED_LINK_LIST) $(LIBRARY_swig_dcerpc_SHARED_LINK_FLAGS)
723 -rm -f scripting/swig/_tdb.so scripting/swig/tdb.pyc \
724 scripting/swig/tdb.py scripting/swig/tdb_wrap.c \
725 scripting/swig/tdb_wrap.o
730 etags `find $(srcdir) -name "*.[ch]"`
733 ctags `find $(srcdir) -name "*.[ch]"`
740 sub _prepare_rule_lists($)
745 foreach my $key (values %{$depend}) {
746 next if not defined $key->{OUTPUT_TYPE};
747 ($output .= _prepare_static_library_rule($key)) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
748 ($output .= _prepare_shared_library_rule($key)) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
749 ($output .= _prepare_binary_rule($key)) if $key->{OUTPUT_TYPE} eq "BINARY";
753 $output .= _prepare_IDL($idl_ctx);
755 $output .= _prepare_proto_rules();
757 $output .= _prepare_install_rules($depend);
762 ###########################################################
763 # This function prepares the output for Makefile
765 # $output = _prepare_makefile_in($SMB_BUILD_CTX)
767 # $SMB_BUILD_CTX - the global SMB_BUILD context
769 # $output - the resulting output buffer
770 sub _prepare_makefile_in($)
775 $output = "########################################\n";
776 $output .= "# Autogenerated by config.smb_build.pl #\n";
777 $output .= "########################################\n";
781 $output .= _prepare_command_interpreters($cmd_ctx);
784 $output .= _prepare_path_vars($path_ctx);
787 $output .= _prepare_compiler_linker($compiler_ctx);
790 $output .= _prepare_default_rule($rules_ctx);
793 $output .= _prepare_SUFFIXES($suffix_ctx);
795 $output .= _prepare_dummy_MAKEDIR();
797 $output .= _prepare_std_CC_rule("c","o",'@PICFLAG@',"Compiling","Rule for std objectfiles");
798 $output .= _prepare_std_CC_rule("h","h.gch",'@PICFLAG@',"Precompiling","Rule for precompiled headerfiles");
800 $output .= _prepare_obj_lists($CTX);
802 $output .= _prepare_rule_lists($CTX);
806 foreach my $part (values %{$CTX}) {
807 push (@all, $part->{TARGET}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";
810 $output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });
815 ###########################################################
816 # This function creates Makefile.in from the SMB_BUILD
819 # create_makefile_in($SMB_BUILD_CTX)
821 # $SMB_BUILD_CTX - the global SMB_BUILD context
823 # $output - the resulting output buffer
824 sub create_makefile_in($)
828 open(MAKEFILE_IN,"> Makefile.in") || die ("Can't open Makefile.in\n");
829 print MAKEFILE_IN _prepare_makefile_in($CTX);
832 print "config.smb_build.pl: creating Makefile.in\n";