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($)
24 sub _prepare_path_vars($)
31 exec_prefix=\@exec_prefix\@
40 CONFIGDIR = \@configdir\@
41 VARDIR = \@localstatedir\@
44 # The permissions to give the executables
47 # set these to where to find various files
48 # These can be overridden by command line switches (see smbd(8))
49 # or in smb.conf (see smb.conf(5))
50 LOGFILEBASE = \@logfilebase\@
51 CONFIGFILE = \$(CONFIGDIR)/smb.conf
52 LMHOSTSFILE = \$(CONFIGDIR)/lmhosts
53 NCALRPCDIR = \@localstatedir\@/ncalrpc
55 # This is where smbpasswd et al go
56 PRIVATEDIR = \@privatedir\@
57 SMB_PASSWD_FILE = \$(PRIVATEDIR)/smbpasswd
59 # the directory where lock files go
62 # the directory where pid files go
65 PASSWD_FLAGS = -DSMB_PASSWD_FILE=\\\"\$(SMB_PASSWD_FILE)\\\" -DPRIVATE_DIR=\\\"\$(PRIVATEDIR)\\\"
66 PATH_FLAGS1 = -DCONFIGFILE=\\\"\$(CONFIGFILE)\\\" -DSBINDIR=\\\"\$(SBINDIR)\\\"
67 PATH_FLAGS2 = \$(PATH_FLAGS1) -DBINDIR=\\\"\$(BINDIR)\\\"
68 PATH_FLAGS3 = \$(PATH_FLAGS2) -DLMHOSTSFILE=\\\"\$(LMHOSTSFILE)\\\"
69 PATH_FLAGS4 = \$(PATH_FLAGS3) -DLOCKDIR=\\\"\$(LOCKDIR)\\\" -DPIDDIR=\\\"\$(PIDDIR)\\\"
70 PATH_FLAGS5 = \$(PATH_FLAGS4) -DLIBDIR=\\\"\$(LIBDIR)\\\" \\
71 -DLOGFILEBASE=\\\"\$(LOGFILEBASE)\\\" -DSHLIBEXT=\\\"\@SHLIBEXT\@\\\"
72 PATH_FLAGS6 = \$(PATH_FLAGS5) -DCONFIGDIR=\\\"\$(CONFIGDIR)\\\" -DNCALRPCDIR=\\\"\$(NCALRPCDIR)\\\"
73 PATH_FLAGS = \$(PATH_FLAGS6) \$(PASSWD_FLAGS)
78 sub _prepare_compiler_linker($)
85 CC_FLAGS=-Iinclude -I. -I\$(srcdir)/include -I\$(srcdir) -D_SAMBA_BUILD_ -Ilib \@CFLAGS\@ \@CPPFLAGS\@
88 LD_FLAGS=\@LDFLAGS\@ \@CFLAGS\@
94 SHLD_FLAGS=\@LDSHFLAGS\@ \@LDFLAGS\@
99 sub _prepare_default_rule($)
110 sub _prepare_SUFFIXES($)
117 .SUFFIXES: .c .o .h .h.gch .a .so
128 idl_full: build/pidl/idl.pm
129 CPP=\"\@CPP\@\" PERL=\"\$(PERL)\" script/build_idl.sh FULL
131 idl: build/pidl/idl.pm
132 \@CPP=\"\@CPP\@\" PERL=\"\$(PERL)\" script/build_idl.sh PARTIAL
134 build/pidl/idl.pm: build/pidl/idl.yp
135 -yapp -s build/pidl/idl.yp
137 pch: proto include/includes.h.gch
140 -rm -f include/includes.h.gch
142 basics: idl proto_exists
148 sub _prepare_dummy_MAKEDIR()
155 \@: >> \$\@ || : > \$\@
157 dynconfig.o: dynconfig.c Makefile
158 \@echo Compiling \$*.c
159 \@\$(CC) \$(CC_FLAGS) \@PICFLAG\@ \$(PATH_FLAGS) -c \$< -o \$\@
160 \@BROKEN_CC\@ -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
166 ###########################################################
167 # This function creates a standard make rule which is using $(CC)
169 # $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
171 # $srcext - sourcefile extension
173 # $destext - destinationfile extension
175 # $flags - additional compiler flags
177 # $message - logmessage which is echoed while running this rule
179 # $comment - just a comment what this rule should do
181 # $output - the resulting output buffer
182 sub _prepare_std_CC_rule($$$$$)
193 ###################################
196 \@echo $message \$*.$src
197 \@\$(CC) \$(CC_FLAGS) $flags -c \$< -o \$\@
198 \@BROKEN_CC\@ -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
200 ###################################
206 sub array2oneperline($)
212 foreach my $str (@{$array}) {
213 if (!defined($str)) {
217 $output .= " \\\n\t\t";
230 foreach my $str (@{$array}) {
231 if (!defined($str)) {
242 ###########################################################
243 # This function creates a object file list
245 # $output = _prepare_var_obj_list($var, $var_ctx)
247 # $var_ctx - the subsystem context
249 # $var_ctx->{NAME} - the <var> name
250 # $var_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this <var>
252 # $output - the resulting output buffer
253 sub _prepare_obj_list($$)
260 $tmpobjlist = array2oneperline($ctx->{OBJ_LIST});
263 ###################################
264 # Start $var $ctx->{NAME} OBJ LIST
265 $var\_$ctx->{NAME}_OBJS =$tmpobjlist
266 # End $var $ctx->{NAME} OBJ LIST
267 ###################################
273 ###########################################################
274 # This function creates a object file list for a subsystem
276 # $output = _prepare_subsystem_obj_list($subsystem_ctx)
278 # $subsystem_ctx - the subsystem context
280 # $subsystem_ctx->{NAME} - the subsystem name
281 # $subsystem_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this subsystem
283 # $output - the resulting output buffer
284 sub _prepare_subsystem_obj_list($)
288 return _prepare_var_obj_list("SUBSYSTEM",$ctx);
291 ###########################################################
292 # This function creates a object file list for a module
294 # $output = _prepare_module_obj_and_lib_list($module_ctx)
296 # $module_ctx - the module context
298 # $module_ctx->{NAME} - the module binary name
299 # $module_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this module
301 # $output - the resulting output buffer
302 sub _prepare_module_obj_list($)
306 return _prepare_var_obj_list("MODULE",$ctx);
310 ###########################################################
311 # This function creates a make rule for linking a library
313 # $output = _prepare_shared_library_rule($library_ctx)
315 # $library_ctx - the library context
317 # $library_ctx->{NAME} - the library name
319 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
321 # $library_ctx->{LIBRARY_NAME} - the shared library name
322 # $library_ctx->{LIBRARY_REALNAME} - the shared library real name
323 # $library_ctx->{LIBRARY_SONAME} - the shared library soname
324 # $library_ctx->{LINK_LIST} - the list of objectfiles and external libraries
325 # which sould be linked to this shared library
326 # $library_ctx->{LINK_FLAGS} - linker flags used by this shared library
328 # $output - the resulting output buffer
329 sub _prepare_shared_library_rule($)
339 my $outname = $ctx->{OUTPUT};
341 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
343 $tmpshlink = array2oneperline($ctx->{LINK_LIST});
344 $tmpshflag = array2oneperline($ctx->{LINK_FLAGS});
347 ###################################
348 # Start Library $ctx->{NAME}
350 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
352 LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
353 LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
356 # Shared $ctx->{LIBRARY_NAME}
357 $ctx->{OUTPUT}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
359 \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
360 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
361 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
364 if (defined($ctx->{LIBRARY_SONAME})) {
366 # Symlink $ctx->{LIBRARY_SONAME}
367 bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
369 \@ln -sf $ctx->{LIBRARY_REALNAME} \$\@
370 # Symlink $ctx->{LIBRARY_NAME}
371 bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
373 \@ln -sf $ctx->{LIBRARY_SONAME} \$\@
375 $outname = $ctx->{LIBRARY_NAME};
379 library_$ctx->{NAME}: basics bin/$outname
380 # End Library $ctx->{NAME}
381 ###################################
387 ###########################################################
388 # This function creates a make rule for linking a library
390 # $output = _prepare_static_library_rule($library_ctx)
392 # $library_ctx - the library context
394 # $library_ctx->{NAME} - the library name
396 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
398 # $library_ctx->{LIBRARY_NAME} - the static library name
399 # $library_ctx->{LINK_LIST} - the list of objectfiles which sould be linked
400 # to this static library
401 # $library_ctx->{LINK_FLAGS} - linker flags used by this static library
403 # $output - the resulting output buffer
404 sub _prepare_static_library_rule($)
415 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
417 $tmpstlink = array2oneperline($ctx->{LINK_LIST});
418 $tmpstflag = array2oneperline($ctx->{LINK_FLAGS});
420 $tmprules = "bin/$ctx->{LIBRARY_NAME}";
423 ###################################
424 # Start Library $ctx->{NAME}
426 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
428 LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
430 # Static $ctx->{LIBRARY_NAME}
431 $ctx->{OUTPUT}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
433 \@\$(STLD) \$(STLD_FLAGS) \$\@ \\
434 \$(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
436 library_$ctx->{NAME}: basics $tmprules
437 # End Library $ctx->{NAME}
438 ###################################
446 ###########################################################
447 # This function creates a make rule for linking a binary
449 # $output = _prepare_binary_rule($binary_ctx)
451 # $binary_ctx - the binary context
453 # $binary_ctx->{NAME} - the binary name
454 # $binary_ctx->{BINARY} - the binary binary name
456 # $binary_ctx->{DEPEND_LIST} - the list of rules on which this binary depends
457 # $binary_ctx->{LINK_LIST} - the list of objectfiles and external libraries
458 # which sould be linked to this binary
459 # $binary_ctx->{LINK_FLAGS} - linker flags used by this binary
461 # $output - the resulting output buffer
462 sub _prepare_binary_rule($)
470 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
471 $tmplink = array2oneperline($ctx->{LINK_LIST});
472 $tmpflag = array2oneperline($ctx->{LINK_FLAGS});
475 ###################################
476 # Start Binary $ctx->{BINARY}
478 BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
479 BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
480 BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
482 bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST)
484 \@\$(LD) \$(LD_FLAGS) -o \$\@ \\
485 \$(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
486 \$(BINARY_$ctx->{NAME}_LINK_LIST) \\
487 \$(BINARY_$ctx->{NAME}_LINK_FLAGS)
488 binary_$ctx->{BINARY}: basics bin/$ctx->{BINARY}
489 # End Binary $ctx->{BINARY}
490 ###################################
496 sub _prepare_proto_rules()
501 # Making this target will just make sure that the prototype files
502 # exist, not necessarily that they are up to date. Since they're
503 # removed by 'make clean' this will always be run when you do anything
505 proto_exists: include/proto.h include/build_env.h
507 delheaders: pch_clean
508 -rm -f \$(builddir)/include/proto.h \$(builddir)/include/build_env.h:
511 \@cd \$(srcdir) && \$(SHELL) script/mkproto.sh \"\$(PERL)\" \\
512 -h _PROTO_H_ \$(builddir)/include/proto.h \\
516 \@echo Building include/build_env.h
517 \@cd \$(srcdir) && \$(SHELL) script/build_env.sh \$(srcdir) \$(builddir) \$(CC) > \$(builddir)/include/build_env.h
519 # 'make headers' or 'make proto' calls a subshell because we need to
520 # make sure these commands are executed in sequence even for a
522 headers: delheaders proto_exists
527 \@[ -f \$(builddir)/include/proto.h ] || \$(MAKE) proto
530 -rm -f *.o */*.o */*/*.o */*/*/*.o bin/*
535 -rm -f include/config.h
538 -rm -f config.smb_build.*
539 -rm -f config.log config.cache
542 -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
544 realdistclean: distclean removebackup
545 -rm -f include/config.h.in
553 sub _prepare_make_target($)
559 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
562 ###################################
563 # Start Target $ctx->{TARGET}
564 $ctx->{TARGET}: basics $tmpdepend
565 # End Target $ctx->{TARGET}
566 ###################################
572 sub _prepare_obj_lists($)
577 foreach my $key (values %{$CTX}) {
578 next if not defined($key->{OBJ_LIST});
579 $output .= _prepare_obj_list($key->{TYPE}, $key);
585 sub _prepare_install_rules($)
593 \@echo \"Samba will be installed into:\"
594 \@echo \" basedir: \$(BASEDIR)\"
595 \@echo \" bindir: \$(BINDIR)\"
596 \@echo \" sbindir: \$(SBINDIR)\"
597 \@echo \" libdir: \$(LIBDIR)\"
598 \@echo \" vardir: \$(VARDIR)\"
599 \@echo \" privatedir: \$(PRIVATEDIR)\"
600 \@echo \" piddir: \$(PIDDIR)\"
601 \@echo \" lockdir: \$(LOCKDIR)\"
603 SBIN_PROGS = bin/smbd
605 BIN_PROGS = bin/smbclient
607 TORTURE_PROGS = bin/smbtorture \\
615 LDB_PROGS = bin/ldbadd \\
621 REG_PROGS = bin/regpatch \\
627 install: showlayout installbin installtorture installldb installreg installdat
629 # DESTDIR is used here to prevent packagers wasting their time
630 # duplicating the Makefile. Remove it and you will have the privelege
631 # of package each samba release for muliple versions of multiple
632 # distributions and operating systems, or at least supplying patches
633 # to all the packaging files required for this, prior to committing
634 # the removal of DESTDIR. Do not remove it even though you think it
638 \@\$(SHELL) \$(srcdir)/script/installdirs.sh \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(SBINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(PRIVATEDIR) \$(DESTDIR)\$(PIDDIR) \$(DESTDIR)\$(LOCKDIR)
640 installbin: all installdirs
641 \@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(SBINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(SBIN_PROGS)
642 \@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(BIN_PROGS)
644 installtorture: all installdirs
645 \@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(TORTURE_PROGS)
647 installldb: all installdirs
648 \@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(LDB_PROGS)
650 installreg: all installdirs
651 \@\$(SHELL) \$(srcdir)/script/installbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(REG_PROGS)
653 installdat: installdirs
654 \@\$(SHELL) \$(srcdir)/script/installdat.sh \$(DESTDIR)\$(LIBDIR) \$(srcdir)
656 uninstall: uninstallbin uninstalltorture uninstallldb uninstallreg
659 \@\$(SHELL) \$(srcdir)/script/uninstallbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(SBINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(SBIN_PROGS)
662 \@\$(SHELL) \$(srcdir)/script/uninstallbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(TORTURE_PROGS)
665 \@\$(SHELL) \$(srcdir)/script/uninstallbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(LDB_PROGS)
668 \@\$(SHELL) \$(srcdir)/script/uninstallbin.sh \$(INSTALLPERMS) \$(DESTDIR)\$(BASEDIR) \$(DESTDIR)\$(BINDIR) \$(DESTDIR)\$(LIBDIR) \$(DESTDIR)\$(VARDIR) \$(DESTDIR)\$(REG_PROGS)
672 swig: scripting/swig/_tdb.so scripting/swig/_dcerpc.so
674 scripting/swig/tdb_wrap.c: scripting/swig/tdb.i
675 swig -python scripting/swig/tdb.i
677 scripting/swig/_tdb.so: scripting/swig/tdb_wrap.o \$(LIBRARY_swig_tdb_DEPEND_LIST)
678 \$(SHLD) \$(SHLD_FLAGS) -o scripting/swig/_tdb.so scripting/swig/tdb_wrap.o \\
679 \$(LIBRARY_swig_tdb_SHARED_LINK_LIST) \$(LIBRARY_swig_tdb_SHARED_LINK_FLAGS)
681 SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i
683 scripting/swig/dcerpc_wrap.c: scripting/swig/dcerpc.i scripting/swig/samba.i scripting/swig/status_codes.i \$(SWIG_INCLUDES)
684 swig -python scripting/swig/dcerpc.i
686 scripting/swig/_dcerpc.so: scripting/swig/dcerpc_wrap.o \$(LIBRARY_swig_dcerpc_DEPEND_LIST)
687 \$(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)
690 -rm -f scripting/swig/_tdb.so scripting/swig/tdb.pyc \\
691 scripting/swig/tdb.py scripting/swig/tdb_wrap.c \\
692 scripting/swig/tdb_wrap.o
697 etags `find \$(srcdir) -name \"*.[ch]\"`
700 ctags `find \$(srcdir) -name \"*.[ch]\"`
707 sub _prepare_rule_lists($)
712 foreach my $key (values %{$depend}) {
713 next if not defined $key->{OUTPUT_TYPE};
714 ($output .= _prepare_static_library_rule($key)) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
715 ($output .= _prepare_shared_library_rule($key)) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
716 ($output .= _prepare_binary_rule($key)) if $key->{OUTPUT_TYPE} eq "BINARY";
720 $output .= _prepare_IDL($idl_ctx);
722 $output .= _prepare_proto_rules();
724 $output .= _prepare_install_rules($depend);
729 ###########################################################
730 # This function prepares the output for Makefile
732 # $output = _prepare_makefile_in($SMB_BUILD_CTX)
734 # $SMB_BUILD_CTX - the global SMB_BUILD context
736 # $output - the resulting output buffer
737 sub _prepare_makefile_in($)
742 $output = "########################################\n";
743 $output .= "# Autogenerated by config.smb_build.pl #\n";
744 $output .= "########################################\n";
747 $output .= _prepare_command_interpreters($cmd_ctx);
750 $output .= _prepare_path_vars($path_ctx);
753 $output .= _prepare_compiler_linker($compiler_ctx);
756 $output .= _prepare_default_rule($rules_ctx);
759 $output .= _prepare_SUFFIXES($suffix_ctx);
761 $output .= _prepare_dummy_MAKEDIR();
763 $output .= _prepare_std_CC_rule("c","o","\@PICFLAG\@","Compiling","Rule for std objectfiles");
764 $output .= _prepare_std_CC_rule("h","h.gch","\@PICFLAG\@","Precompiling","Rule for precompiled headerfiles");
766 $output .= _prepare_obj_lists($CTX);
768 $output .= _prepare_rule_lists($CTX);
772 foreach my $part (values %{$CTX}) {
773 push (@all, $part->{OUTPUT}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";
776 $output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });
781 ###########################################################
782 # This function creates Makefile.in from the SMB_BUILD
785 # create_makefile_in($SMB_BUILD_CTX)
787 # $SMB_BUILD_CTX - the global SMB_BUILD context
789 # $output - the resulting output buffer
790 sub create_makefile_in($)
794 open(MAKEFILE_IN,"> Makefile.in") || die ("Can't open Makefile.in\n");
795 print MAKEFILE_IN _prepare_makefile_in($CTX);
798 print "config.smb_build.pl: creating Makefile.in\n";