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@
97 SHLD_FLAGS=@LDSHFLAGS@ @LDFLAGS@
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 export SOCKET_WRAPPER_DIR=.
157 ./script/tests/selftest.sh `pwd`/prefix-test
160 ./script/tests/selftest.sh `pwd`/prefix-test
167 sub _prepare_dummy_MAKEDIR()
172 $output = << '__EOD__';
176 dynconfig.o: dynconfig.c Makefile
178 @$(CC) $(CC_FLAGS) @PICFLAG@ $(PATH_FLAGS) -c $< -o $@
179 @BROKEN_CC@ -mv `echo $@ | sed 's%^.*/%%g'` $@
186 ###########################################################
187 # This function creates a standard make rule which is using $(CC)
189 # $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
191 # $srcext - sourcefile extension
193 # $destext - destinationfile extension
195 # $flags - additional compiler flags
197 # $message - logmessage which is echoed while running this rule
199 # $comment - just a comment what this rule should do
201 # $output - the resulting output buffer
202 sub _prepare_std_CC_rule($$$$$)
212 $output = << "__EOD__";
213 ###################################
216 \@echo $message \$\*.$src
217 \@\$(CC) \$(CC_FLAGS) $flags -c \$< -o \$\@
218 \@BROKEN_CC\@ -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
220 ###################################
227 sub array2oneperline($)
233 foreach my $str (@{$array}) {
234 if (!defined($str)) {
238 $output .= " \\\n\t\t";
251 foreach my $str (@{$array}) {
252 if (!defined($str)) {
263 ###########################################################
264 # This function creates a object file list
266 # $output = _prepare_var_obj_list($var, $var_ctx)
268 # $var_ctx - the subsystem context
270 # $var_ctx->{NAME} - the <var> name
271 # $var_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this <var>
273 # $output - the resulting output buffer
274 sub _prepare_obj_list($$)
281 $tmpobjlist = array2oneperline($ctx->{OBJ_LIST});
283 $output = << "__EOD__";
284 ###################################
285 # Start $var $ctx->{NAME} OBJ LIST
286 $var\_$ctx->{NAME}_OBJS =$tmpobjlist
287 # End $var $ctx->{NAME} OBJ LIST
288 ###################################
295 ###########################################################
296 # This function creates a object file list for a subsystem
298 # $output = _prepare_subsystem_obj_list($subsystem_ctx)
300 # $subsystem_ctx - the subsystem context
302 # $subsystem_ctx->{NAME} - the subsystem name
303 # $subsystem_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this subsystem
305 # $output - the resulting output buffer
306 sub _prepare_subsystem_obj_list($)
310 return _prepare_var_obj_list("SUBSYSTEM",$ctx);
313 ###########################################################
314 # This function creates a object file list for a module
316 # $output = _prepare_module_obj_and_lib_list($module_ctx)
318 # $module_ctx - the module context
320 # $module_ctx->{NAME} - the module binary name
321 # $module_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this module
323 # $output - the resulting output buffer
324 sub _prepare_module_obj_list($)
328 return _prepare_var_obj_list("MODULE",$ctx);
332 ###########################################################
333 # This function creates a make rule for linking a library
335 # $output = _prepare_shared_library_rule($library_ctx)
337 # $library_ctx - the library context
339 # $library_ctx->{NAME} - the library name
341 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
343 # $library_ctx->{LIBRARY_NAME} - the shared library name
344 # $library_ctx->{LIBRARY_REALNAME} - the shared library real name
345 # $library_ctx->{LIBRARY_SONAME} - the shared library soname
346 # $library_ctx->{LINK_LIST} - the list of objectfiles and external libraries
347 # which sould be linked to this shared library
348 # $library_ctx->{LINK_FLAGS} - linker flags used by this shared library
350 # $output - the resulting output buffer
351 sub _prepare_shared_library_rule($)
361 my $outname = $ctx->{OUTPUT};
363 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
365 $tmpshlink = array2oneperline($ctx->{LINK_LIST});
366 $tmpshflag = array2oneperline($ctx->{LINK_FLAGS});
368 $output = << "__EOD__";
369 ###################################
370 # Start Library $ctx->{NAME}
372 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
374 LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
375 LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
378 # Shared $ctx->{LIBRARY_NAME}
379 $ctx->{OUTPUT}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
381 \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
382 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
383 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
387 if (defined($ctx->{LIBRARY_SONAME})) {
388 $output .= << "__EOD__";
389 # Symlink $ctx->{LIBRARY_SONAME}
390 bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
392 \@ln -sf $ctx->{LIBRARY_REALNAME} \$\@
393 # Symlink $ctx->{LIBRARY_NAME}
394 bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
396 \@ln -sf $ctx->{LIBRARY_SONAME} \$\@
399 $outname = $ctx->{LIBRARY_NAME};
402 $output .= << "__EOD__";
403 library_$ctx->{NAME}: basics bin/$outname
404 # End Library $ctx->{NAME}
405 ###################################
412 ###########################################################
413 # This function creates a make rule for linking a library
415 # $output = _prepare_static_library_rule($library_ctx)
417 # $library_ctx - the library context
419 # $library_ctx->{NAME} - the library name
421 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
423 # $library_ctx->{LIBRARY_NAME} - the static library name
424 # $library_ctx->{LINK_LIST} - the list of objectfiles which sould be linked
425 # to this static library
426 # $library_ctx->{LINK_FLAGS} - linker flags used by this static library
428 # $output - the resulting output buffer
429 sub _prepare_static_library_rule($)
440 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
442 $tmpstlink = array2oneperline($ctx->{LINK_LIST});
443 $tmpstflag = array2oneperline($ctx->{LINK_FLAGS});
445 $tmprules = "bin/$ctx->{LIBRARY_NAME}";
447 $output = << '__EOD__';
448 ###################################
449 # Start Library $ctx->{NAME}
451 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
453 LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
455 # Static $ctx->{LIBRARY_NAME}
456 $ctx->{OUTPUT}: $(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
458 @$(STLD) $(STLD_FLAGS) $@ \\
459 $(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
461 library_$ctx->{NAME}: basics $tmprules
462 # End Library $ctx->{NAME}
463 ###################################
472 ###########################################################
473 # This function creates a make rule for linking a binary
475 # $output = _prepare_binary_rule($binary_ctx)
477 # $binary_ctx - the binary context
479 # $binary_ctx->{NAME} - the binary name
480 # $binary_ctx->{BINARY} - the binary binary name
482 # $binary_ctx->{DEPEND_LIST} - the list of rules on which this binary depends
483 # $binary_ctx->{LINK_LIST} - the list of objectfiles and external libraries
484 # which sould be linked to this binary
485 # $binary_ctx->{LINK_FLAGS} - linker flags used by this binary
487 # $output - the resulting output buffer
488 sub _prepare_binary_rule($)
496 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
497 $tmplink = array2oneperline($ctx->{LINK_LIST});
498 $tmpflag = array2oneperline($ctx->{LINK_FLAGS});
500 $output = << "__EOD__";
501 ###################################
502 # Start Binary $ctx->{BINARY}
504 BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
505 BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
506 BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
508 bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST)
510 \@\$(LD) \$(LD_FLAGS) -o \$\@ \\
511 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
512 \$\(BINARY_$ctx->{NAME}_LINK_LIST) \\
513 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS)
514 binary_$ctx->{BINARY}: basics bin/$ctx->{BINARY}
515 # End Binary $ctx->{BINARY}
516 ###################################
523 sub _prepare_proto_rules()
527 $output .= << '__EOD__';
528 # Making this target will just make sure that the prototype files
529 # exist, not necessarily that they are up to date. Since they're
530 # removed by 'make clean' this will always be run when you do anything
532 proto_exists: include/proto.h include/build_env.h
534 delheaders: pch_clean
535 -rm -f $(builddir)/include/proto.h $(builddir)/include/build_env.h:
538 @cd $(srcdir) && $(SHELL) script/mkproto.sh "$(PERL)" \
539 -h _PROTO_H_ $(builddir)/include/proto.h \
543 @echo Building include/build_env.h
544 @cd $(srcdir) && $(SHELL) script/build_env.sh $(srcdir) $(builddir) $(CC) > $(builddir)/include/build_env.h
546 # 'make headers' or 'make proto' calls a subshell because we need to
547 # make sure these commands are executed in sequence even for a
549 headers: delheaders proto_exists
554 @[ -f $(builddir)/include/proto.h ] || $(MAKE) proto
557 -rm -f *.o */*.o */*/*.o */*/*/*.o bin/*
562 -rm -f include/config.h
565 -rm -f config.smb_build.*
566 -rm -f config.log config.cache
569 -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
571 realdistclean: distclean removebackup
572 -rm -f include/config.h.in
580 sub _prepare_make_target($)
586 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
588 $output = << "__EOD__";
589 ###################################
590 # Start Target $ctx->{TARGET}
591 $ctx->{TARGET}: basics $tmpdepend
592 # End Target $ctx->{TARGET}
593 ###################################
600 sub _prepare_obj_lists($)
605 foreach my $key (values %{$CTX}) {
606 next if not defined($key->{OBJ_LIST});
607 $output .= _prepare_obj_list($key->{TYPE}, $key);
613 sub _prepare_install_rules($)
618 $output .= << '__EOD__';
621 @echo "Samba will be installed into:"
622 @echo " basedir: $(BASEDIR)"
623 @echo " bindir: $(BINDIR)"
624 @echo " sbindir: $(SBINDIR)"
625 @echo " libdir: $(LIBDIR)"
626 @echo " vardir: $(VARDIR)"
627 @echo " privatedir: $(PRIVATEDIR)"
628 @echo " piddir: $(PIDDIR)"
629 @echo " lockdir: $(LOCKDIR)"
632 @echo "Samba will be compiled with flags:"
633 @echo " CC_FLAGS = $(CC_FLAGS)"
634 @echo " LD_FLAGS = $(LD_FLAGS)"
635 @echo " STLD_FLAGS = $(STLD_FLAGS)"
636 @echo " SHLD_FLAGS = $(SHLD_FLAGS)"
638 SBIN_PROGS = bin/smbd
640 BIN_PROGS = bin/smbclient \
645 TORTURE_PROGS = bin/smbtorture \
651 LDB_PROGS = bin/ldbadd \
657 REG_PROGS = bin/regpatch \
663 install: showlayout installbin installtorture installldb installreg installdat
665 # DESTDIR is used here to prevent packagers wasting their time
666 # duplicating the Makefile. Remove it and you will have the privelege
667 # of package each samba release for muliple versions of multiple
668 # distributions and operating systems, or at least supplying patches
669 # to all the packaging files required for this, prior to committing
670 # the removal of DESTDIR. Do not remove it even though you think it
674 @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(PRIVATEDIR) $(DESTDIR)$(PIDDIR) $(DESTDIR)$(LOCKDIR)
676 installbin: all installdirs
677 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(SBIN_PROGS)
678 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(BIN_PROGS)
680 installtorture: all installdirs
681 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(TORTURE_PROGS)
683 installldb: all installdirs
684 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(LDB_PROGS)
686 installreg: all installdirs
687 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(REG_PROGS)
689 installdat: installdirs
690 @$(SHELL) $(srcdir)/script/installdat.sh $(DESTDIR)$(LIBDIR) $(srcdir)
692 uninstall: uninstallbin uninstalltorture uninstallldb uninstallreg
695 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(SBIN_PROGS)
698 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(TORTURE_PROGS)
701 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(LDB_PROGS)
704 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(REG_PROGS)
708 swig: scripting/swig/_tdb.so scripting/swig/_dcerpc.so
710 scripting/swig/tdb_wrap.c: scripting/swig/tdb.i
711 swig -python scripting/swig/tdb.i
713 scripting/swig/_tdb.so: scripting/swig/tdb_wrap.o $(LIBRARY_swig_tdb_DEPEND_LIST)
714 $(SHLD) $(SHLD_FLAGS) -o scripting/swig/_tdb.so scripting/swig/tdb_wrap.o \
715 $(LIBRARY_swig_tdb_SHARED_LINK_LIST) $(LIBRARY_swig_tdb_SHARED_LINK_FLAGS)
717 SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i
719 scripting/swig/dcerpc_wrap.c: scripting/swig/dcerpc.i scripting/swig/samba.i scripting/swig/status_codes.i $(SWIG_INCLUDES)
720 swig -python scripting/swig/dcerpc.i
722 scripting/swig/_dcerpc.so: scripting/swig/dcerpc_wrap.o $(LIBRARY_swig_dcerpc_DEPEND_LIST)
723 $(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)
726 -rm -f scripting/swig/_tdb.so scripting/swig/tdb.pyc \
727 scripting/swig/tdb.py scripting/swig/tdb_wrap.c \
728 scripting/swig/tdb_wrap.o
733 etags `find $(srcdir) -name "*.[ch]"`
736 ctags `find $(srcdir) -name "*.[ch]"`
743 sub _prepare_rule_lists($)
748 foreach my $key (values %{$depend}) {
749 next if not defined $key->{OUTPUT_TYPE};
750 ($output .= _prepare_static_library_rule($key)) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
751 ($output .= _prepare_shared_library_rule($key)) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
752 ($output .= _prepare_binary_rule($key)) if $key->{OUTPUT_TYPE} eq "BINARY";
756 $output .= _prepare_IDL($idl_ctx);
758 $output .= _prepare_proto_rules();
760 $output .= _prepare_install_rules($depend);
765 ###########################################################
766 # This function prepares the output for Makefile
768 # $output = _prepare_makefile_in($SMB_BUILD_CTX)
770 # $SMB_BUILD_CTX - the global SMB_BUILD context
772 # $output - the resulting output buffer
773 sub _prepare_makefile_in($)
778 $output = "########################################\n";
779 $output .= "# Autogenerated by config.smb_build.pl #\n";
780 $output .= "########################################\n";
784 $output .= _prepare_command_interpreters($cmd_ctx);
787 $output .= _prepare_path_vars($path_ctx);
790 $output .= _prepare_compiler_linker($compiler_ctx);
793 $output .= _prepare_default_rule($rules_ctx);
796 $output .= _prepare_SUFFIXES($suffix_ctx);
798 $output .= _prepare_dummy_MAKEDIR();
800 $output .= _prepare_std_CC_rule("c","o",'@PICFLAG@',"Compiling","Rule for std objectfiles");
801 $output .= _prepare_std_CC_rule("h","h.gch",'@PICFLAG@',"Precompiling","Rule for precompiled headerfiles");
803 $output .= _prepare_obj_lists($CTX);
805 $output .= _prepare_rule_lists($CTX);
809 foreach my $part (values %{$CTX}) {
810 push (@all, $part->{OUTPUT}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";
813 $output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });
818 ###########################################################
819 # This function creates Makefile.in from the SMB_BUILD
822 # create_makefile_in($SMB_BUILD_CTX)
824 # $SMB_BUILD_CTX - the global SMB_BUILD context
826 # $output - the resulting output buffer
827 sub create_makefile_in($)
831 open(MAKEFILE_IN,"> Makefile.in") || die ("Can't open Makefile.in\n");
832 print MAKEFILE_IN _prepare_makefile_in($CTX);
835 print "config.smb_build.pl: creating Makefile.in\n";