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 $output = << "__EOD__";
443 ###################################
444 # Start Library $ctx->{NAME}
446 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
448 LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
450 # Static $ctx->{LIBRARY_NAME}
451 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
453 \@\$(STLD) \$(STLD_FLAGS) \$@ \\
454 \$(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
456 library_$ctx->{NAME}: basics $ctx->{TARGET}
457 # End Library $ctx->{NAME}
458 ###################################
467 ###########################################################
468 # This function creates a make rule for linking a binary
470 # $output = _prepare_binary_rule($binary_ctx)
472 # $binary_ctx - the binary context
474 # $binary_ctx->{NAME} - the binary name
475 # $binary_ctx->{BINARY} - the binary binary name
477 # $binary_ctx->{DEPEND_LIST} - the list of rules on which this binary depends
478 # $binary_ctx->{LINK_LIST} - the list of objectfiles and external libraries
479 # which sould be linked to this binary
480 # $binary_ctx->{LINK_FLAGS} - linker flags used by this binary
482 # $output - the resulting output buffer
483 sub _prepare_binary_rule($)
491 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
492 $tmplink = array2oneperline($ctx->{LINK_LIST});
493 $tmpflag = array2oneperline($ctx->{LINK_FLAGS});
495 $output = << "__EOD__";
496 ###################################
497 # Start Binary $ctx->{BINARY}
499 BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
500 BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
501 BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
503 bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST)
505 \@\$(LD) \$(LD_FLAGS) -o \$\@ \\
506 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
507 \$\(BINARY_$ctx->{NAME}_LINK_LIST) \\
508 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS)
509 binary_$ctx->{BINARY}: basics bin/$ctx->{BINARY}
510 # End Binary $ctx->{BINARY}
511 ###################################
518 sub _prepare_proto_rules()
522 $output .= << '__EOD__';
523 # Making this target will just make sure that the prototype files
524 # exist, not necessarily that they are up to date. Since they're
525 # removed by 'make clean' this will always be run when you do anything
527 proto_exists: include/proto.h include/build_env.h
529 delheaders: pch_clean
530 -rm -f $(builddir)/include/proto.h $(builddir)/include/build_env.h:
533 @cd $(srcdir) && $(SHELL) script/mkproto.sh "$(PERL)" \
534 -h _PROTO_H_ $(builddir)/include/proto.h \
538 @echo Building include/build_env.h
539 @cd $(srcdir) && $(SHELL) script/build_env.sh $(srcdir) $(builddir) $(CC) > $(builddir)/include/build_env.h
541 # 'make headers' or 'make proto' calls a subshell because we need to
542 # make sure these commands are executed in sequence even for a
544 headers: delheaders proto_exists
549 @[ -f $(builddir)/include/proto.h ] || $(MAKE) proto
552 -rm -f *.o */*.o */*/*.o */*/*/*.o bin/*
557 -rm -f include/config.h
560 -rm -f config.smb_build.*
561 -rm -f config.log config.cache
564 -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
566 realdistclean: distclean removebackup
567 -rm -f include/config.h.in
575 sub _prepare_make_target($)
581 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
583 $output = << "__EOD__";
584 ###################################
585 # Start Target $ctx->{TARGET}
586 $ctx->{TARGET}: basics $tmpdepend
587 # End Target $ctx->{TARGET}
588 ###################################
595 sub _prepare_obj_lists($)
600 foreach my $key (values %{$CTX}) {
601 next if not defined($key->{OBJ_LIST});
602 $output .= _prepare_obj_list($key->{TYPE}, $key);
608 sub _prepare_install_rules($)
613 $output .= << '__EOD__';
616 @echo "Samba will be installed into:"
617 @echo " basedir: $(BASEDIR)"
618 @echo " bindir: $(BINDIR)"
619 @echo " sbindir: $(SBINDIR)"
620 @echo " libdir: $(LIBDIR)"
621 @echo " vardir: $(VARDIR)"
622 @echo " privatedir: $(PRIVATEDIR)"
623 @echo " piddir: $(PIDDIR)"
624 @echo " lockdir: $(LOCKDIR)"
627 @echo "Samba will be compiled with flags:"
628 @echo " CC_FLAGS = $(CC_FLAGS)"
629 @echo " LD_FLAGS = $(LD_FLAGS)"
630 @echo " STLD_FLAGS = $(STLD_FLAGS)"
631 @echo " SHLD_FLAGS = $(SHLD_FLAGS)"
633 SBIN_PROGS = bin/smbd
635 BIN_PROGS = bin/smbclient \
640 TORTURE_PROGS = bin/smbtorture \
646 LDB_PROGS = bin/ldbadd \
652 REG_PROGS = bin/regpatch \
658 install: showlayout installbin installtorture installldb installreg installdat
660 # DESTDIR is used here to prevent packagers wasting their time
661 # duplicating the Makefile. Remove it and you will have the privelege
662 # of package each samba release for muliple versions of multiple
663 # distributions and operating systems, or at least supplying patches
664 # to all the packaging files required for this, prior to committing
665 # the removal of DESTDIR. Do not remove it even though you think it
669 @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(PRIVATEDIR) $(DESTDIR)$(PIDDIR) $(DESTDIR)$(LOCKDIR)
671 installbin: all installdirs
672 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(SBIN_PROGS)
673 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(BIN_PROGS)
675 installtorture: all installdirs
676 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(TORTURE_PROGS)
678 installldb: all installdirs
679 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(LDB_PROGS)
681 installreg: all installdirs
682 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(REG_PROGS)
684 installdat: installdirs
685 @$(SHELL) $(srcdir)/script/installdat.sh $(DESTDIR)$(LIBDIR) $(srcdir)
687 uninstall: uninstallbin uninstalltorture uninstallldb uninstallreg
690 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(SBIN_PROGS)
693 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(TORTURE_PROGS)
696 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(LDB_PROGS)
699 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(REG_PROGS)
703 swig: scripting/swig/_tdb.so scripting/swig/_dcerpc.so
705 scripting/swig/tdb_wrap.c: scripting/swig/tdb.i
706 swig -python scripting/swig/tdb.i
708 scripting/swig/_tdb.so: scripting/swig/tdb_wrap.o $(LIBRARY_swig_tdb_DEPEND_LIST)
709 $(SHLD) $(SHLD_FLAGS) -o scripting/swig/_tdb.so scripting/swig/tdb_wrap.o \
710 $(LIBRARY_swig_tdb_SHARED_LINK_LIST) $(LIBRARY_swig_tdb_SHARED_LINK_FLAGS)
712 SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i
714 scripting/swig/dcerpc_wrap.c: scripting/swig/dcerpc.i scripting/swig/samba.i scripting/swig/status_codes.i $(SWIG_INCLUDES)
715 swig -python scripting/swig/dcerpc.i
717 scripting/swig/_dcerpc.so: scripting/swig/dcerpc_wrap.o $(LIBRARY_swig_dcerpc_DEPEND_LIST)
718 $(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)
721 -rm -f scripting/swig/_tdb.so scripting/swig/tdb.pyc \
722 scripting/swig/tdb.py scripting/swig/tdb_wrap.c \
723 scripting/swig/tdb_wrap.o
728 etags `find $(srcdir) -name "*.[ch]"`
731 ctags `find $(srcdir) -name "*.[ch]"`
738 sub _prepare_rule_lists($)
743 foreach my $key (values %{$depend}) {
744 next if not defined $key->{OUTPUT_TYPE};
745 ($output .= _prepare_static_library_rule($key)) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
746 ($output .= _prepare_shared_library_rule($key)) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
747 ($output .= _prepare_binary_rule($key)) if $key->{OUTPUT_TYPE} eq "BINARY";
751 $output .= _prepare_IDL($idl_ctx);
753 $output .= _prepare_proto_rules();
755 $output .= _prepare_install_rules($depend);
760 ###########################################################
761 # This function prepares the output for Makefile
763 # $output = _prepare_makefile_in($SMB_BUILD_CTX)
765 # $SMB_BUILD_CTX - the global SMB_BUILD context
767 # $output - the resulting output buffer
768 sub _prepare_makefile_in($)
773 $output = "########################################\n";
774 $output .= "# Autogenerated by config.smb_build.pl #\n";
775 $output .= "########################################\n";
779 $output .= _prepare_command_interpreters($cmd_ctx);
782 $output .= _prepare_path_vars($path_ctx);
785 $output .= _prepare_compiler_linker($compiler_ctx);
788 $output .= _prepare_default_rule($rules_ctx);
791 $output .= _prepare_SUFFIXES($suffix_ctx);
793 $output .= _prepare_dummy_MAKEDIR();
795 $output .= _prepare_std_CC_rule("c","o",'@PICFLAG@',"Compiling","Rule for std objectfiles");
796 $output .= _prepare_std_CC_rule("h","h.gch",'@PICFLAG@',"Precompiling","Rule for precompiled headerfiles");
798 $output .= _prepare_obj_lists($CTX);
800 $output .= _prepare_rule_lists($CTX);
804 foreach my $part (values %{$CTX}) {
805 push (@all, $part->{TARGET}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";
808 $output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });
813 ###########################################################
814 # This function creates Makefile.in from the SMB_BUILD
817 # create_makefile_in($SMB_BUILD_CTX)
819 # $SMB_BUILD_CTX - the global SMB_BUILD context
821 # $output - the resulting output buffer
822 sub create_makefile_in($)
826 open(MAKEFILE_IN,"> Makefile.in") || die ("Can't open Makefile.in\n");
827 print MAKEFILE_IN _prepare_makefile_in($CTX);
830 print "config.smb_build.pl: creating Makefile.in\n";