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($)
23 sub _prepare_path_vars($)
28 $output = << '__EOD__';
30 exec_prefix=@exec_prefix@
39 CONFIGDIR = @configdir@
40 VARDIR = @localstatedir@
43 # The permissions to give the executables
46 # set these to where to find various files
47 # These can be overridden by command line switches (see smbd(8))
48 # or in smb.conf (see smb.conf(5))
49 LOGFILEBASE = @logfilebase@
50 CONFIGFILE = $(CONFIGDIR)/smb.conf
51 LMHOSTSFILE = $(CONFIGDIR)/lmhosts
52 NCALRPCDIR = @localstatedir@/ncalrpc
54 # This is where smbpasswd et al go
55 PRIVATEDIR = @privatedir@
56 SMB_PASSWD_FILE = $(PRIVATEDIR)/smbpasswd
58 # the directory where lock files go
61 # the directory where pid files go
64 PASSWD_FLAGS = -DSMB_PASSWD_FILE=\"$(SMB_PASSWD_FILE)\" -DPRIVATE_DIR=\"$(PRIVATEDIR)\"
65 PATH_FLAGS1 = -DCONFIGFILE=\"$(CONFIGFILE)\" -DSBINDIR=\"$(SBINDIR)\"
66 PATH_FLAGS2 = $(PATH_FLAGS1) -DBINDIR=\"$(BINDIR)\"
67 PATH_FLAGS3 = $(PATH_FLAGS2) -DLMHOSTSFILE=\"$(LMHOSTSFILE)\"
68 PATH_FLAGS4 = $(PATH_FLAGS3) -DLOCKDIR=\"$(LOCKDIR)\" -DPIDDIR=\"$(PIDDIR)\"
69 PATH_FLAGS5 = $(PATH_FLAGS4) -DLIBDIR=\"$(LIBDIR)\" \
70 -DLOGFILEBASE=\"$(LOGFILEBASE)\" -DSHLIBEXT=\"@SHLIBEXT@\"
71 PATH_FLAGS6 = $(PATH_FLAGS5) -DCONFIGDIR=\"$(CONFIGDIR)\" -DNCALRPCDIR=\"$(NCALRPCDIR)\"
72 PATH_FLAGS7 = $(PATH_FLAGS6) -DSWATDIR=\"$(SWATDIR)\"
73 PATH_FLAGS = $(PATH_FLAGS7) $(PASSWD_FLAGS)
80 sub _prepare_compiler_linker($)
86 CFLAGS=-Iinclude -I. -I$(srcdir)/include -I$(srcdir) -D_SAMBA_BUILD_ -DHAVE_CONFIG_H -Ilib @CFLAGS@ @CPPFLAGS@
89 LD_FLAGS=@LDFLAGS@ @CFLAGS@ -Lbin
95 SHLD_FLAGS=@LDSHFLAGS@ @LDFLAGS@ -Lbin
100 sub _prepare_default_rule($)
105 $output = << '__EOD__';
113 sub _prepare_SUFFIXES($)
118 $output = << '__EOD__';
120 .SUFFIXES: .c .o .h .h.gch .a .so
132 idl_full: build/pidl/idl.pm
133 CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh FULL @PIDL_ARGS@
135 idl: build/pidl/idl.pm
136 @CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh PARTIAL @PIDL_ARGS@
138 build/pidl/idl.pm: build/pidl/idl.yp
139 -yapp -s build/pidl/idl.yp
141 pch: proto include/includes.h.gch
144 -rm -f include/includes.h.gch
146 basics: idl proto_exists
148 test: @DEFAULT_TEST_TARGET@
151 ./script/tests/selftest.sh `pwd`/prefix-test SOCKET_WRAPPER
154 ./script/tests/selftest.sh `pwd`/prefix-test
159 sub _prepare_dummy_MAKEDIR()
167 dynconfig.o: TARGET_CFLAGS=$(PATH_FLAGS)
168 dynconfig.o: Makefile
173 ###########################################################
174 # This function creates a standard make rule which is using $(CC)
176 # $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
178 # $srcext - sourcefile extension
180 # $destext - destinationfile extension
182 # $flags - additional compiler flags
184 # $message - logmessage which is echoed while running this rule
186 # $comment - just a comment what this rule should do
188 # $output - the resulting output buffer
189 sub _prepare_std_CC_rule($$$$$)
199 $output = << "__EOD__";
202 \@echo $message \$\*.$src
203 \@\$(CC) \$(TARGET_CFLAGS) \$(CFLAGS) $flags -c \$< -o \$\@
204 \@BROKEN_CC\@ -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
211 sub array2oneperline($)
217 foreach my $str (@{$array}) {
218 if (!defined($str)) {
222 $output .= " \\\n\t\t";
235 foreach my $str (@{$array}) {
236 if (!defined($str)) {
247 ###########################################################
248 # This function creates a object file list
250 # $output = _prepare_var_obj_list($var, $var_ctx)
252 # $var_ctx - the subsystem context
254 # $var_ctx->{NAME} - the <var> name
255 # $var_ctx->{OBJ_LIST} - the list of objectfiles which sould be linked to this <var>
257 # $output - the resulting output buffer
258 sub _prepare_obj_list($$)
263 my $tmplist = array2oneperline($ctx->{OBJ_LIST});
266 # $var $ctx->{NAME} OBJ LIST
267 $var\_$ctx->{NAME}_OBJS =$tmplist
272 sub _prepare_cflags($$)
277 my $tmplist = array2oneperline($ctx->{CFLAGS});
280 $var\_$ctx->{NAME}_CFLAGS =$tmplist
285 ###########################################################
286 # This function creates a make rule for linking a library
288 # $output = _prepare_shared_library_rule($library_ctx)
290 # $library_ctx - the library context
292 # $library_ctx->{NAME} - the library name
294 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
296 # $library_ctx->{LIBRARY_NAME} - the shared library name
297 # $library_ctx->{LIBRARY_REALNAME} - the shared library real name
298 # $library_ctx->{LIBRARY_SONAME} - the shared library soname
299 # $library_ctx->{LINK_LIST} - the list of objectfiles and external libraries
300 # which sould be linked to this shared library
301 # $library_ctx->{LINK_FLAGS} - linker flags used by this shared library
303 # $output - the resulting output buffer
304 sub _prepare_shared_library_rule($)
315 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
317 $tmpshlink = array2oneperline($ctx->{LINK_LIST});
318 $tmpshflag = array2oneperline($ctx->{LINK_FLAGS});
320 $output = << "__EOD__";
321 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
323 LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
324 LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
327 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) \$(LIBRARY_$ctx->{NAME}_OBJS) bin/.dummy
329 \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
330 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
331 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
335 if (defined($ctx->{LIBRARY_SONAME})) {
336 $output .= << "__EOD__";
337 # Symlink $ctx->{LIBRARY_SONAME}
338 bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
340 \@ln -sf $ctx->{LIBRARY_REALNAME} \$\@
341 # Symlink $ctx->{LIBRARY_NAME}
342 bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
344 \@ln -sf $ctx->{LIBRARY_SONAME} \$\@
349 $output .= << "__EOD__";
350 library_$ctx->{NAME}: basics bin/lib$ctx->{LIBRARY_NAME}
357 sub _prepare_objlist_rule($)
360 my $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
363 $output = "$ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST = $tmpdepend\n";
365 $output .= "$ctx->{TARGET}: ";
367 if (defined ($ctx->{TARGET_CFLAGS})) {
368 $output .= "\n\t@\$(MAKE) TARGET_CFLAGS=\"" . join(' ', @{$ctx->{TARGET_CFLAGS}}) . "\" ";
371 $output .= "\$($ctx->{TYPE}_$ctx->{NAME}_DEPEND_LIST) \$($ctx->{TYPE}_$ctx->{NAME}_OBJS)\n";
372 $output .= "\t\@touch $ctx->{TARGET}\n";
377 ###########################################################
378 # This function creates a make rule for linking a library
380 # $output = _prepare_static_library_rule($library_ctx)
382 # $library_ctx - the library context
384 # $library_ctx->{NAME} - the library name
386 # $library_ctx->{DEPEND_LIST} - the list of rules on which this library depends
388 # $library_ctx->{LIBRARY_NAME} - the static library name
389 # $library_ctx->{LINK_LIST} - the list of objectfiles which sould be linked
390 # to this static library
391 # $library_ctx->{LINK_FLAGS} - linker flags used by this static library
393 # $output - the resulting output buffer
394 sub _prepare_static_library_rule($)
405 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
407 $tmpstlink = array2oneperline($ctx->{LINK_LIST});
408 $tmpstflag = array2oneperline($ctx->{LINK_FLAGS});
410 $output = << "__EOD__";
411 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
413 LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
415 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) \$(LIBRARY_$ctx->{NAME}_OBJS) bin/.dummy
417 \@\$(STLD) \$(STLD_FLAGS) \$@ \\
418 \$(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
420 library_$ctx->{NAME}: basics $ctx->{TARGET}
427 ###########################################################
428 # This function creates a make rule for linking a binary
430 # $output = _prepare_binary_rule($binary_ctx)
432 # $binary_ctx - the binary context
434 # $binary_ctx->{NAME} - the binary name
435 # $binary_ctx->{BINARY} - the binary binary name
437 # $binary_ctx->{DEPEND_LIST} - the list of rules on which this binary depends
438 # $binary_ctx->{LINK_LIST} - the list of objectfiles and external libraries
439 # which sould be linked to this binary
440 # $binary_ctx->{LINK_FLAGS} - linker flags used by this binary
442 # $output - the resulting output buffer
443 sub _prepare_binary_rule($)
451 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
452 $tmplink = array2oneperline($ctx->{LINK_LIST});
453 $tmpflag = array2oneperline($ctx->{LINK_FLAGS});
455 $output = << "__EOD__";
457 BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
458 BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
459 BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
461 bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST) \$(BINARY_$ctx->{NAME}_OBJS)
463 \@\$(LD) \$(LD_FLAGS) -o \$\@ \\
464 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS) \\
465 \$\(BINARY_$ctx->{NAME}_LINK_LIST) \\
466 \$\(BINARY_$ctx->{NAME}_LINK_FLAGS)
467 binary_$ctx->{BINARY}: basics bin/$ctx->{BINARY}
474 sub _prepare_custom_rule($)
477 return "$ctx->{NAME}:\n\t$ctx->{CMD}\n";
480 sub _prepare_proto_rules()
484 $output .= << '__EOD__';
485 # Making this target will just make sure that the prototype files
486 # exist, not necessarily that they are up to date. Since they're
487 # removed by 'make clean' this will always be run when you do anything
489 proto_exists: include/proto.h include/build_env.h
491 delheaders: pch_clean
492 -rm -f $(builddir)/include/proto.h $(builddir)/include/build_env.h:
495 @cd $(srcdir) && $(SHELL) script/mkproto.sh "$(PERL)" \
496 -h _PROTO_H_ $(builddir)/include/proto.h \
500 @echo Building include/build_env.h
501 @cd $(srcdir) && $(SHELL) script/build_env.sh $(srcdir) $(builddir) $(CC) > $(builddir)/include/build_env.h
503 # 'make headers' or 'make proto' calls a subshell because we need to
504 # make sure these commands are executed in sequence even for a
506 headers: delheaders proto_exists
511 @[ -f $(builddir)/include/proto.h ] || $(MAKE) proto
514 @echo Removing objects and binaries
515 @-rm -f $(_ALL_OBJS_OBJS) bin/* bin/.*_*
516 @echo Removing generated files
517 @-rm -rf librpc/gen_*
521 -rm -f include/config.h
524 -rm -f config.smb_build.*
525 -rm -f config.log config.cache
528 -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
530 realdistclean: distclean removebackup
531 -rm -f include/config.h.in
539 sub _prepare_make_target($)
545 $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
548 $ctx->{TARGET}: basics $tmpdepend
553 sub _prepare_target_settings($)
558 foreach my $key (values %$CTX) {
559 if (defined($key->{OBJ_LIST})) {
560 $output .= _prepare_obj_list($key->{TYPE}, $key);
563 if (defined($key->{OBJ_LIST})) {
564 $output .= _prepare_cflags($key->{TYPE}, $key);
571 sub _prepare_install_rules($)
576 $output .= << '__EOD__';
579 @echo "Samba will be installed into:"
580 @echo " basedir: $(BASEDIR)"
581 @echo " bindir: $(BINDIR)"
582 @echo " sbindir: $(SBINDIR)"
583 @echo " libdir: $(LIBDIR)"
584 @echo " vardir: $(VARDIR)"
585 @echo " privatedir: $(PRIVATEDIR)"
586 @echo " piddir: $(PIDDIR)"
587 @echo " lockdir: $(LOCKDIR)"
588 @echo " swatdir: $(SWATDIR)"
591 @echo "Samba will be compiled with flags:"
592 @echo " CFLAGS = $(CFLAGS)"
593 @echo " LD_FLAGS = $(LD_FLAGS)"
594 @echo " STLD_FLAGS = $(STLD_FLAGS)"
595 @echo " SHLD_FLAGS = $(SHLD_FLAGS)"
597 SBIN_PROGS = bin/smbd
599 BIN_PROGS = bin/smbclient \
604 TORTURE_PROGS = bin/smbtorture \
610 LDB_PROGS = bin/ldbadd \
616 REG_PROGS = bin/regpatch \
622 install: showlayout installbin installtorture installldb installreg installdat installswat
624 # DESTDIR is used here to prevent packagers wasting their time
625 # duplicating the Makefile. Remove it and you will have the privelege
626 # of package each samba release for muliple versions of multiple
627 # distributions and operating systems, or at least supplying patches
628 # to all the packaging files required for this, prior to committing
629 # the removal of DESTDIR. Do not remove it even though you think it
633 @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(PRIVATEDIR) $(DESTDIR)$(PIDDIR) $(DESTDIR)$(LOCKDIR) $(DESTDIR)$(PRIVATEDIR)/tls
635 installbin: all installdirs
636 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(SBIN_PROGS)
637 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(BIN_PROGS)
639 installtorture: all installdirs
640 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(TORTURE_PROGS)
642 installldb: all installdirs
643 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(LDB_PROGS)
645 installreg: all installdirs
646 @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(REG_PROGS)
648 installdat: installdirs
649 @$(SHELL) $(srcdir)/script/installdat.sh $(DESTDIR)$(LIBDIR) $(srcdir)
651 installswat: installdirs
652 @$(SHELL) $(srcdir)/script/installswat.sh $(DESTDIR)$(SWATDIR) $(srcdir)
654 uninstall: uninstallbin uninstalltorture uninstallldb uninstallreg
657 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(SBIN_PROGS)
660 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(TORTURE_PROGS)
663 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(LDB_PROGS)
666 @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(REG_PROGS)
670 swig: scripting/swig/_tdb.so scripting/swig/_dcerpc.so
672 scripting/swig/tdb_wrap.c: scripting/swig/tdb.i
673 swig -python scripting/swig/tdb.i
675 scripting/swig/_tdb.so: scripting/swig/tdb_wrap.o $(LIBRARY_swig_tdb_DEPEND_LIST)
676 $(SHLD) $(SHLD_FLAGS) -o scripting/swig/_tdb.so scripting/swig/tdb_wrap.o \
677 $(LIBRARY_swig_tdb_SHARED_LINK_LIST) $(LIBRARY_swig_tdb_SHARED_LINK_FLAGS)
679 SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i
681 scripting/swig/dcerpc_wrap.c: scripting/swig/dcerpc.i scripting/swig/samba.i scripting/swig/status_codes.i $(SWIG_INCLUDES)
682 swig -python scripting/swig/dcerpc.i
684 scripting/swig/_dcerpc.so: scripting/swig/dcerpc_wrap.o $(LIBRARY_swig_dcerpc_DEPEND_LIST)
685 $(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)
688 -rm -f scripting/swig/_tdb.so scripting/swig/tdb.pyc \
689 scripting/swig/tdb.py scripting/swig/tdb_wrap.c \
690 scripting/swig/tdb_wrap.o
695 etags `find $(srcdir) -name "*.[ch]"`
698 ctags `find $(srcdir) -name "*.[ch]"`
705 sub _prepare_rule_lists($)
710 foreach my $key (values %{$depend}) {
711 next if not defined $key->{OUTPUT_TYPE};
713 ($output .= _prepare_objlist_rule($key)) if $key->{OUTPUT_TYPE} eq "OBJLIST";
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";
717 ($output .= _prepare_custom_rule($key) ) if $key->{TYPE} eq "TARGET";
721 $output .= _prepare_IDL($idl_ctx);
723 $output .= _prepare_proto_rules();
725 $output .= _prepare_install_rules($depend);
730 ###########################################################
731 # This function prepares the output for Makefile
733 # $output = _prepare_makefile_in($OUTPUT)
735 # $OUTPUT - the global OUTPUT context
737 # $output - the resulting output buffer
738 sub _prepare_makefile_in($$)
741 my $settings = shift;
744 $output = "########################################\n";
745 $output .= "# Autogenerated by config.smb_build.pl #\n";
746 $output .= "########################################\n";
750 $output .= _prepare_command_interpreters($cmd_ctx);
753 $output .= _prepare_path_vars($path_ctx);
756 $output .= _prepare_compiler_linker($compiler_ctx);
759 $output .= _prepare_default_rule($rules_ctx);
762 $output .= _prepare_SUFFIXES($suffix_ctx);
764 $output .= _prepare_dummy_MAKEDIR();
766 $output .= _prepare_std_CC_rule("c","o",'@PICFLAG@',"Compiling","Rule for std objectfiles");
767 $output .= _prepare_std_CC_rule("h","h.gch",'@PICFLAG@',"Precompiling","Rule for precompiled headerfiles");
769 $output .= _prepare_target_settings($CTX);
771 $output .= _prepare_rule_lists($CTX);
775 foreach my $part (values %{$CTX}) {
776 push (@all, $part->{TARGET}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";
779 $output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });
784 ###########################################################
785 # This function creates Makefile.in from the OUTPUT
788 # create_makefile_in($OUTPUT)
790 # $OUTPUT - the global OUTPUT context
792 # $output - the resulting output buffer
793 sub create_makefile_in($$$)
796 my $settings = shift;
799 open(MAKEFILE_IN,">$file") || die ("Can't open $file\n");
800 print MAKEFILE_IN _prepare_makefile_in($CTX, $settings);
803 print "config.smb_build.pl: creating $file\n";