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@
46 # The permissions to give the executables
49 # set these to where to find various files
50 # These can be overridden by command line switches (see smbd(8))
51 # or in smb.conf (see smb.conf(5))
52 LOGFILEBASE = @logfilebase@
53 CONFIGFILE = $(CONFIGDIR)/smb.conf
54 LMHOSTSFILE = $(CONFIGDIR)/lmhosts
55 NCALRPCDIR = @localstatedir@/ncalrpc
57 # This is where smbpasswd et al go
58 PRIVATEDIR = @privatedir@
59 SMB_PASSWD_FILE = $(PRIVATEDIR)/smbpasswd
61 # the directory where lock files go
64 # the directory where pid files go
67 PASSWD_FLAGS = -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" -DPRIVATE_DIR=\"$(PRIVATEDIR)\"
68 PATH_FLAGS1 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DSBINDIR=\"$(SBINDIR)\"
69 PATH_FLAGS2 = $(PATH_FLAGS1) -DBINDIR=\"$(BINDIR)\"
70 PATH_FLAGS3 = $(PATH_FLAGS2) -DLMHOSTSFILE=\"$(LMHOSTSFILE)\"
71 PATH_FLAGS4 = $(PATH_FLAGS3) -DLOCKDIR=\"$(LOCKDIR)\" -DPIDDIR=\"$(PIDDIR)\"
72 PATH_FLAGS5 = $(PATH_FLAGS4) -DLIBDIR=\"$(LIBDIR)\" \
73 -DLOGFILEBASE=\"$(LOGFILEBASE)\" -DSHLIBEXT=\"@SHLIBEXT@\"
74 PATH_FLAGS6 = $(PATH_FLAGS5) -DCONFIGDIR=\"$(CONFIGDIR)\" -DNCALRPCDIR=\"$(NCALRPCDIR)\"
75 PATH_FLAGS7 = $(PATH_FLAGS6) -DSWATDIR=\"$(SWATDIR)\"
76 PATH_FLAGS = $(PATH_FLAGS7) $(PASSWD_FLAGS)
83 sub _prepare_compiler_linker($)
88 $output = << '__EOD__';
90 CC_FLAGS=-Iinclude -I. -I$(srcdir)/include -I$(srcdir) -D_SAMBA_BUILD_ -DHAVE_CONFIG_H -Ilib @CFLAGS@ @CPPFLAGS@
93 LD_FLAGS=@LDFLAGS@ @CFLAGS@ -Lbin
99 SHLD_FLAGS=@LDSHFLAGS@ @LDFLAGS@ -Lbin
106 sub _prepare_default_rule($)
111 $output = << '__EOD__';
119 sub _prepare_SUFFIXES($)
124 $output = << '__EOD__';
126 .SUFFIXES: .c .o .h .h.gch .a .so
138 $output = << '__EOD__';
139 idl_full: build/pidl/idl.pm
140 CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh FULL
142 idl: build/pidl/idl.pm
143 @CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh PARTIAL
145 build/pidl/idl.pm: build/pidl/idl.yp
146 -yapp -s build/pidl/idl.yp
148 pch: proto include/includes.h.gch
151 -rm -f include/includes.h.gch
153 basics: idl proto_exists
155 test: @DEFAULT_TEST_TARGET@
158 SOCKET_WRAPPER_DIR=. ./script/tests/selftest.sh `pwd`/prefix-test
161 ./script/tests/selftest.sh `pwd`/prefix-test
168 sub _prepare_dummy_MAKEDIR()
173 $output = << '__EOD__';
177 dynconfig.o: dynconfig.c Makefile
179 @$(CC) $(CC_FLAGS) @PICFLAG@ $(PATH_FLAGS) -c $< -o $@
180 @BROKEN_CC@ -mv `echo $@ | sed 's%^.*/%%g'` $@
187 ###########################################################
188 # This function creates a standard make rule which is using $(CC)
190 # $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
192 # $srcext - sourcefile extension
194 # $destext - destinationfile extension
196 # $flags - additional compiler flags
198 # $message - logmessage which is echoed while running this rule
200 # $comment - just a comment what this rule should do
202 # $output - the resulting output buffer
203 sub _prepare_std_CC_rule($$$$$)
213 $output = << "__EOD__";
214 ###################################
217 \@echo $message \$\*.$src
218 \@\$(CC) \$(CC_FLAGS) $flags -c \$< -o \$\@
219 \@BROKEN_CC\@ -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
221 ###################################
228 sub array2oneperline($)
234 foreach my $str (@{$array}) {
235 if (!defined($str)) {
239 $output .= " \\\n\t\t";
252 foreach my $str (@{$array}) {
253 if (!defined($str)) {
264 ###########################################################
265 # This function creates a object file list
267 # $output = _prepare_var_obj_list($var, $var_ctx)
269 # $var_ctx - the subsystem context
271 # $var_ctx->{NAME} - the <var> name
272 # $var_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this <var>
274 # $output - the resulting output buffer
275 sub _prepare_obj_list($$)
282 $tmpobjlist = array2oneperline($ctx->{OBJ_LIST});
284 $output = << "__EOD__";
285 ###################################
286 # Start $var $ctx->{NAME} OBJ LIST
287 $var\_$ctx->{NAME}_OBJS =$tmpobjlist
288 # End $var $ctx->{NAME} OBJ LIST
289 ###################################
296 ###########################################################
297 # This function creates a object file list for a subsystem
299 # $output = _prepare_subsystem_obj_list($subsystem_ctx)
301 # $subsystem_ctx - the subsystem context
303 # $subsystem_ctx->{NAME} - the subsystem name
304 # $subsystem_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this subsystem
306 # $output - the resulting output buffer
307 sub _prepare_subsystem_obj_list($)
311 return _prepare_var_obj_list("SUBSYSTEM",$ctx);
314 ###########################################################
315 # This function creates a object file list for a module
317 # $output = _prepare_module_obj_and_lib_list($module_ctx)
319 # $module_ctx - the module context
321 # $module_ctx->{NAME} - the module binary name
322 # $module_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this module
324 # $output - the resulting output buffer
325 sub _prepare_module_obj_list($)
329 return _prepare_var_obj_list("MODULE",$ctx);
333 ###########################################################
334 # This function creates a make rule for linking a library
336 # $output = _prepare_shared_library_rule($library_ctx)
338 # $library_ctx - the library context
340 # $library_ctx->{NAME} - the library name
342 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
344 # $library_ctx->{LIBRARY_NAME} - the shared library name
345 # $library_ctx->{LIBRARY_REALNAME} - the shared library real name
346 # $library_ctx->{LIBRARY_SONAME} - the shared library soname
347 # $library_ctx->{LINK_LIST} - the list of objectfiles and external libraries
348 # which sould be linked to this shared library
349 # $library_ctx->{LINK_FLAGS} - linker flags used by this shared library
351 # $output - the resulting output buffer
352 sub _prepare_shared_library_rule($)
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->{TARGET}: \$(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} \$\@
401 $output .= << "__EOD__";
402 library_$ctx->{NAME}: basics bin/lib$ctx->{LIBRARY_NAME}
403 # End Library $ctx->{NAME}
404 ###################################
411 ###########################################################
412 # This function creates a make rule for linking a library
414 # $output = _prepare_static_library_rule($library_ctx)
416 # $library_ctx - the library context
418 # $library_ctx->{NAME} - the library name
420 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
422 # $library_ctx->{LIBRARY_NAME} - the static library name
423 # $library_ctx->{LINK_LIST} - the list of objectfiles which sould be linked
424 # to this static library
425 # $library_ctx->{LINK_FLAGS} - linker flags used by this static library
427 # $output - the resulting output buffer
428 sub _prepare_static_library_rule($)
439 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
441 $tmpstlink = array2oneperline($ctx->{LINK_LIST});
442 $tmpstflag = array2oneperline($ctx->{LINK_FLAGS});
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 $ctx->{TARGET}
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)"
627 @echo " swatdir: $(SWATDIR)"
630 @echo "Samba will be compiled with flags:"
631 @echo " CC_FLAGS = $(CC_FLAGS)"
632 @echo " LD_FLAGS = $(LD_FLAGS)"
633 @echo " STLD_FLAGS = $(STLD_FLAGS)"
634 @echo " SHLD_FLAGS = $(SHLD_FLAGS)"
636 SBIN_PROGS = bin/smbd
638 BIN_PROGS = bin/smbclient \
643 TORTURE_PROGS = bin/smbtorture \
649 LDB_PROGS = bin/ldbadd \
655 REG_PROGS = bin/regpatch \
661 install: showlayout installbin installtorture installldb installreg installdat installswat
663 # DESTDIR is used here to prevent packagers wasting their time
664 # duplicating the Makefile. Remove it and you will have the privelege
665 # of package each samba release for muliple versions of multiple
666 # distributions and operating systems, or at least supplying patches
667 # to all the packaging files required for this, prior to committing
668 # the removal of DESTDIR. Do not remove it even though you think it
672 @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(PRIVATEDIR) $(DESTDIR)$(PIDDIR) $(DESTDIR)$(LOCKDIR)
674 installbin: all installdirs
675 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(SBIN_PROGS)
676 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(BIN_PROGS)
678 installtorture: all installdirs
679 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(TORTURE_PROGS)
681 installldb: all installdirs
682 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(LDB_PROGS)
684 installreg: all installdirs
685 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(REG_PROGS)
687 installdat: installdirs
688 @$(SHELL) $(srcdir)/script/installdat.sh $(DESTDIR)$(LIBDIR) $(srcdir)
690 installswat: installdirs
691 @$(SHELL) $(srcdir)/script/installswat.sh $(DESTDIR)$(SWATDIR) $(srcdir)
693 uninstall: uninstallbin uninstalltorture uninstallldb uninstallreg
696 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(SBIN_PROGS)
699 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(TORTURE_PROGS)
702 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(LDB_PROGS)
705 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(REG_PROGS)
709 swig: scripting/swig/_tdb.so scripting/swig/_dcerpc.so
711 scripting/swig/tdb_wrap.c: scripting/swig/tdb.i
712 swig -python scripting/swig/tdb.i
714 scripting/swig/_tdb.so: scripting/swig/tdb_wrap.o $(LIBRARY_swig_tdb_DEPEND_LIST)
715 $(SHLD) $(SHLD_FLAGS) -o scripting/swig/_tdb.so scripting/swig/tdb_wrap.o \
716 $(LIBRARY_swig_tdb_SHARED_LINK_LIST) $(LIBRARY_swig_tdb_SHARED_LINK_FLAGS)
718 SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i
720 scripting/swig/dcerpc_wrap.c: scripting/swig/dcerpc.i scripting/swig/samba.i scripting/swig/status_codes.i $(SWIG_INCLUDES)
721 swig -python scripting/swig/dcerpc.i
723 scripting/swig/_dcerpc.so: scripting/swig/dcerpc_wrap.o $(LIBRARY_swig_dcerpc_DEPEND_LIST)
724 $(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)
727 -rm -f scripting/swig/_tdb.so scripting/swig/tdb.pyc \
728 scripting/swig/tdb.py scripting/swig/tdb_wrap.c \
729 scripting/swig/tdb_wrap.o
734 etags `find $(srcdir) -name "*.[ch]"`
737 ctags `find $(srcdir) -name "*.[ch]"`
744 sub _prepare_rule_lists($)
749 foreach my $key (values %{$depend}) {
750 next if not defined $key->{OUTPUT_TYPE};
751 ($output .= _prepare_static_library_rule($key)) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
752 ($output .= _prepare_shared_library_rule($key)) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
753 ($output .= _prepare_binary_rule($key)) if $key->{OUTPUT_TYPE} eq "BINARY";
757 $output .= _prepare_IDL($idl_ctx);
759 $output .= _prepare_proto_rules();
761 $output .= _prepare_install_rules($depend);
766 ###########################################################
767 # This function prepares the output for Makefile
769 # $output = _prepare_makefile_in($OUTPUT)
771 # $OUTPUT - the global OUTPUT context
773 # $output - the resulting output buffer
774 sub _prepare_makefile_in($)
779 $output = "########################################\n";
780 $output .= "# Autogenerated by config.smb_build.pl #\n";
781 $output .= "########################################\n";
785 $output .= _prepare_command_interpreters($cmd_ctx);
788 $output .= _prepare_path_vars($path_ctx);
791 $output .= _prepare_compiler_linker($compiler_ctx);
794 $output .= _prepare_default_rule($rules_ctx);
797 $output .= _prepare_SUFFIXES($suffix_ctx);
799 $output .= _prepare_dummy_MAKEDIR();
801 $output .= _prepare_std_CC_rule("c","o",'@PICFLAG@',"Compiling","Rule for std objectfiles");
802 $output .= _prepare_std_CC_rule("h","h.gch",'@PICFLAG@',"Precompiling","Rule for precompiled headerfiles");
804 $output .= _prepare_obj_lists($CTX);
806 $output .= _prepare_rule_lists($CTX);
810 foreach my $part (values %{$CTX}) {
811 push (@all, $part->{TARGET}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";
814 $output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });
819 ###########################################################
820 # This function creates Makefile.in from the OUTPUT
823 # create_makefile_in($OUTPUT)
825 # $OUTPUT - the global OUTPUT context
827 # $output - the resulting output buffer
828 sub create_makefile_in($$)
833 open(MAKEFILE_IN,">$file") || die ("Can't open $file\n");
834 print MAKEFILE_IN _prepare_makefile_in($CTX);
837 print "config.smb_build.pl: creating $file\n";