r7307: Add phony rules for OUTPUT_TYPE OBJLIST, e.g. it is now possible
[samba.git] / source4 / build / smb_build / makefile.pm
1 ###########################################################
2 ### SMB Build System                                    ###
3 ### - create output for Makefile                        ###
4 ###                                                     ###
5 ###  Copyright (C) Stefan (metze) Metzmacher 2004       ###
6 ###  Released under the GNU GPL                         ###
7 ###########################################################
8
9 package makefile;
10 use strict;
11
12 sub _prepare_command_interpreters($)
13 {
14         my $ctx = shift;
15         my $output;
16
17         $output = << '__EOD__';
18 SHELL=/bin/sh
19 PERL=@PERL@
20
21 __EOD__
22
23         return $output;
24 }
25
26 sub _prepare_path_vars($)
27 {
28         my $ctx = shift;
29         my $output;
30
31         $output = << '__EOD__';
32 prefix=@prefix@
33 exec_prefix=@exec_prefix@
34 VPATH=@srcdir@
35 srcdir=@srcdir@
36 builddir=@builddir@
37
38 BASEDIR= @prefix@
39 BINDIR = @bindir@
40 SBINDIR = @sbindir@
41 LIBDIR = @libdir@
42 CONFIGDIR = @configdir@
43 VARDIR = @localstatedir@
44 SWATDIR = @swatdir@
45
46 # The permissions to give the executables
47 INSTALLPERMS = 0755
48
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
56
57 # This is where smbpasswd et al go
58 PRIVATEDIR = @privatedir@
59 SMB_PASSWD_FILE = $(PRIVATEDIR)/smbpasswd
60
61 # the directory where lock files go
62 LOCKDIR = @lockdir@
63
64 # the directory where pid files go
65 PIDDIR = @piddir@
66
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)
77
78 __EOD__
79
80         return $output;
81 }
82
83 sub _prepare_compiler_linker($)
84 {
85         my $ctx = shift;
86         my $output;
87
88         $output = << '__EOD__';
89 CC=@CC@
90 CFLAGS=-Iinclude -I. -I$(srcdir)/include -I$(srcdir) -D_SAMBA_BUILD_ -DHAVE_CONFIG_H -Ilib @CFLAGS@ @CPPFLAGS@
91
92 LD=@CC@
93 LD_FLAGS=@LDFLAGS@ @CFLAGS@ -Lbin
94
95 STLD=ar
96 STLD_FLAGS=-rc
97
98 SHLD=@CC@
99 SHLD_FLAGS=@LDSHFLAGS@ @LDFLAGS@ -Lbin
100
101 __EOD__
102
103         return $output;
104 }
105
106
107 #############################
108 # return makefile fragment for 
109 # target specific rules
110 sub add_target_flags($$)
111 {
112         my $ctx = shift;
113         my $name = shift;
114         my $output = "";
115         if ($ctx->{TARGET_CFLAGS}) {
116 $output .= << "__EOD__";
117 $name: TARGET_CFLAGS = $ctx->{TARGET_CFLAGS}
118 __EOD__
119 }
120         return $output;
121 }
122
123
124 sub _prepare_default_rule($)
125 {
126         my $ctx = shift;
127         my $output;
128
129         $output = << '__EOD__';
130 default: all
131
132 __EOD__
133
134         return $output;
135 }
136
137 sub _prepare_SUFFIXES($)
138 {
139         my $ctx = shift;
140         my $output;
141
142         $output = << '__EOD__';
143 .SUFFIXES:
144 .SUFFIXES: .c .o .h .h.gch .a .so
145
146 __EOD__
147
148         return $output;
149 }
150
151 sub _prepare_IDL($)
152 {
153         my $ctx = shift;
154         my $output;
155
156         $output = << '__EOD__';
157 idl_full: build/pidl/idl.pm
158         CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh FULL
159
160 idl: build/pidl/idl.pm
161         @CPP="@CPP@" PERL="$(PERL)" script/build_idl.sh PARTIAL
162
163 build/pidl/idl.pm: build/pidl/idl.yp
164         -yapp -s build/pidl/idl.yp
165
166 pch: proto include/includes.h.gch
167
168 pch_clean:
169         -rm -f include/includes.h.gch
170
171 basics: idl proto_exists
172
173 test: @DEFAULT_TEST_TARGET@
174
175 test-swrap: all
176         SOCKET_WRAPPER_DIR=. ./script/tests/selftest.sh `pwd`/prefix-test
177
178 test-noswrap: all
179         ./script/tests/selftest.sh `pwd`/prefix-test
180
181 __EOD__
182
183         return $output;
184 }
185
186 sub _prepare_dummy_MAKEDIR()
187 {
188         my $ctx = shift;
189         my $output;
190
191         $output =  << '__EOD__';
192 bin/.dummy:
193         @: >> $@ || : > $@
194
195 dynconfig.o: dynconfig.c Makefile
196         @echo Compiling $*.c
197         @$(CC) $(CFLAGS) @PICFLAG@ $(PATH_FLAGS) -c $< -o $@
198 @BROKEN_CC@     -mv `echo $@ | sed 's%^.*/%%g'` $@
199
200 __EOD__
201
202         return $output;
203 }
204
205 ###########################################################
206 # This function creates a standard make rule which is using $(CC)
207 #
208 # $output = _prepare_std_CC_rule($srcext,$destext,$flags,$message,$comment)
209 #
210 # $srcext -     sourcefile extension
211 #
212 # $destext -    destinationfile extension
213 #
214 # $flags -      additional compiler flags
215 #
216 # $message -    logmessage which is echoed while running this rule
217 #
218 # $comment -    just a comment what this rule should do
219 #
220 # $output -             the resulting output buffer
221 sub _prepare_std_CC_rule($$$$$)
222 {
223         my $src = shift;
224         my $dst = shift;
225         my $flags = shift;
226         my $message = shift;
227         my $comment = shift;
228         my $flagsstr = "";
229         my $output;
230
231         $output = << "__EOD__";
232 ###################################
233 # Start $comment
234 .$src.$dst:
235         \@echo $message \$\*.$src
236         \@\$(CC) \$(TARGET_CFLAGS) \$(CFLAGS) $flags -c \$< -o \$\@
237 \@BROKEN_CC\@   -mv `echo \$\@ | sed 's%^.*/%%g'` \$\@
238 #End $comment
239 ###################################
240
241 __EOD__
242
243         return $output;
244 }
245
246 sub array2oneperline($)
247 {
248         my $array = shift;
249         my $i;
250         my $output = "";
251
252         foreach my $str (@{$array}) {
253                 if (!defined($str)) {
254                         next;
255                 }
256
257                 $output .= " \\\n\t\t";
258                 $output .= $str;
259         }
260
261         return $output;
262 }
263
264 sub array2oneline($)
265 {
266         my $array = shift;
267         my $i;
268         my $output = "";
269
270         foreach my $str (@{$array}) {
271                 if (!defined($str)) {
272                         next;
273                 }
274
275                 $output .= $str;
276                 $output .= " ";
277         }
278
279         return $output;
280 }
281
282 ###########################################################
283 # This function creates a object file list
284 #
285 # $output = _prepare_var_obj_list($var, $var_ctx)
286 #
287 # $var_ctx -            the subsystem context
288 #
289 # $var_ctx->{NAME}      -       the <var> name
290 # $var_ctx->{OBJ_LIST}  -       the list of objectfiles which sould be linked to this <var>
291 #
292 # $output -             the resulting output buffer
293 sub _prepare_obj_list($$)
294 {
295         my $var = shift;
296         my $ctx = shift;
297
298         my $tmplist = array2oneperline($ctx->{OBJ_LIST});
299
300         return << "__EOD__";
301 ###################################
302 # Start $var $ctx->{NAME} OBJ LIST
303 $var\_$ctx->{NAME}_OBJS =$tmplist
304 # End $var $ctx->{NAME} OBJ LIST
305 ###################################
306
307 __EOD__
308 }
309
310 sub _prepare_cflags($$)
311 {
312         my $var = shift;
313         my $ctx = shift;
314
315         my $tmplist = array2oneperline($ctx->{CFLAGS});
316
317         return << "__EOD__";
318 ###################################
319 # Start $var $ctx->{NAME} CFLAGS
320 $var\_$ctx->{NAME}_CFLAGS =$tmplist
321 # End $var $ctx->{NAME} CFLAGS
322 ###################################
323
324 __EOD__
325 }
326
327 ###########################################################
328 # This function creates a make rule for linking a library
329 #
330 # $output = _prepare_shared_library_rule($library_ctx)
331 #
332 # $library_ctx -                the library context
333 #
334 # $library_ctx->{NAME} -                the library name
335 #
336 # $library_ctx->{DEPEND_LIST} -         the list of rules on which this library depends
337 #
338 # $library_ctx->{LIBRARY_NAME} -        the shared library name
339 # $library_ctx->{LIBRARY_REALNAME} -    the shared library real name
340 # $library_ctx->{LIBRARY_SONAME} - the shared library soname
341 # $library_ctx->{LINK_LIST} -   the list of objectfiles and external libraries
342 #                                       which sould be linked to this shared library
343 # $library_ctx->{LINK_FLAGS} -  linker flags used by this shared library
344 #
345 # $output -             the resulting output buffer
346 sub _prepare_shared_library_rule($)
347 {
348         my $ctx = shift;
349         my $tmpdepend;
350         my $tmpstlink;
351         my $tmpstflag;
352         my $tmpshlink;
353         my $tmpshflag;
354         my $tmprules;
355         my $output;
356
357         $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
358
359         $tmpshlink = array2oneperline($ctx->{LINK_LIST});
360         $tmpshflag = array2oneperline($ctx->{LINK_FLAGS});
361
362         $output = << "__EOD__";
363 ###################################
364 # Start Library $ctx->{NAME}
365 #
366 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
367 #
368 LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST =$tmpshlink
369 LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS =$tmpshflag
370 #
371
372 # Shared $ctx->{LIBRARY_NAME}
373 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
374         \@echo Linking \$\@
375         \@\$(SHLD) \$(SHLD_FLAGS) -o \$\@ \\
376                 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_FLAGS) \\
377                 \$(LIBRARY_$ctx->{NAME}_SHARED_LINK_LIST)
378
379 __EOD__
380
381         if (defined($ctx->{LIBRARY_SONAME})) {
382             $output .= << "__EOD__";
383 # Symlink $ctx->{LIBRARY_SONAME}
384 bin/$ctx->{LIBRARY_SONAME}: bin/$ctx->{LIBRARY_REALNAME} bin/.dummy
385         \@echo Symlink \$\@
386         \@ln -sf $ctx->{LIBRARY_REALNAME} \$\@
387 # Symlink $ctx->{LIBRARY_NAME}
388 bin/$ctx->{LIBRARY_NAME}: bin/$ctx->{LIBRARY_SONAME} bin/.dummy
389         \@echo Symlink \$\@
390         \@ln -sf $ctx->{LIBRARY_SONAME} \$\@
391
392 __EOD__
393         }
394
395 $output .= << "__EOD__";
396 library_$ctx->{NAME}: basics bin/lib$ctx->{LIBRARY_NAME}
397
398 # End Library $ctx->{NAME}
399 ###################################
400
401 __EOD__
402
403 $output .= add_target_flags($ctx, "library_" . $ctx->{NAME});
404
405         return $output;
406 }
407
408 sub _prepare_objlist_rule($)
409 {
410         my $t = shift;
411         return "$t->{TYPE}_$t->{NAME}: \$($t->{TYPE}_$t->{NAME}_OBJS)\n";
412 }
413
414 ###########################################################
415 # This function creates a make rule for linking a library
416 #
417 # $output = _prepare_static_library_rule($library_ctx)
418 #
419 # $library_ctx -                the library context
420 #
421 # $library_ctx->{NAME} -                the library name
422 #
423 # $library_ctx->{DEPEND_LIST} -         the list of rules on which this library depends
424 #
425 # $library_ctx->{LIBRARY_NAME} -        the static library name
426 # $library_ctx->{LINK_LIST} -   the list of objectfiles which sould be linked
427 #                                       to this static library
428 # $library_ctx->{LINK_FLAGS} -  linker flags used by this static library
429 #
430 # $output -             the resulting output buffer
431 sub _prepare_static_library_rule($)
432 {
433         my $ctx = shift;
434         my $tmpdepend;
435         my $tmpstlink;
436         my $tmpstflag;
437         my $tmpshlink;
438         my $tmpshflag;
439         my $tmprules;
440         my $output;
441
442         $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
443
444         $tmpstlink = array2oneperline($ctx->{LINK_LIST});
445         $tmpstflag = array2oneperline($ctx->{LINK_FLAGS});
446
447         $output = << "__EOD__";
448 ###################################
449 # Start Library $ctx->{NAME}
450 #
451 LIBRARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
452 #
453 LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST =$tmpstlink
454 #
455 # Static $ctx->{LIBRARY_NAME}
456 $ctx->{TARGET}: \$(LIBRARY_$ctx->{NAME}_DEPEND_LIST) bin/.dummy
457         \@echo Linking \$@
458         \@\$(STLD) \$(STLD_FLAGS) \$@ \\
459                 \$(LIBRARY_$ctx->{NAME}_STATIC_LINK_LIST)
460
461 library_$ctx->{NAME}: basics $ctx->{TARGET}
462 # End Library $ctx->{NAME}
463 ###################################
464
465 __EOD__
466
467 $output .= add_target_flags($ctx, "library_" . $ctx->{NAME});
468
469         return $output;
470 }
471
472 ###########################################################
473 # This function creates a make rule for linking a binary
474 #
475 # $output = _prepare_binary_rule($binary_ctx)
476 #
477 # $binary_ctx -         the binary context
478 #
479 # $binary_ctx->{NAME} -         the binary name
480 # $binary_ctx->{BINARY} -       the binary binary name
481 #
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
486 #
487 # $output -             the resulting output buffer
488 sub _prepare_binary_rule($)
489 {
490         my $ctx = shift;
491         my $tmpdepend;
492         my $tmplink;
493         my $tmpflag;
494         my $output;
495
496         $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
497         $tmplink = array2oneperline($ctx->{LINK_LIST});
498         $tmpflag = array2oneperline($ctx->{LINK_FLAGS});
499
500         $output = << "__EOD__";
501 ###################################
502 # Start Binary $ctx->{BINARY}
503 #
504 BINARY_$ctx->{NAME}_DEPEND_LIST =$tmpdepend
505 BINARY_$ctx->{NAME}_LINK_LIST =$tmplink
506 BINARY_$ctx->{NAME}_LINK_FLAGS =$tmpflag
507 #
508 bin/$ctx->{BINARY}: bin/.dummy \$(BINARY_$ctx->{NAME}_DEPEND_LIST)
509         \@echo Linking \$\@
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 ###################################
517
518 __EOD__
519
520 $output .= add_target_flags($ctx, "binary_" . $ctx->{BINARY});
521
522         return $output;
523 }
524
525 sub _prepare_proto_rules()
526 {
527         my $output = "";
528
529         $output .= << '__EOD__';
530 # Making this target will just make sure that the prototype files
531 # exist, not necessarily that they are up to date.  Since they're
532 # removed by 'make clean' this will always be run when you do anything
533 # afterwards.
534 proto_exists: include/proto.h include/build_env.h
535
536 delheaders: pch_clean
537         -rm -f $(builddir)/include/proto.h $(builddir)/include/build_env.h:
538
539 include/proto.h:
540         @cd $(srcdir) && $(SHELL) script/mkproto.sh "$(PERL)" \
541           -h _PROTO_H_ $(builddir)/include/proto.h \
542           $(PROTO_PROTO_OBJS)
543
544 include/build_env.h:
545         @echo Building include/build_env.h
546         @cd $(srcdir) && $(SHELL) script/build_env.sh $(srcdir) $(builddir) $(CC) > $(builddir)/include/build_env.h
547
548 # 'make headers' or 'make proto' calls a subshell because we need to
549 # make sure these commands are executed in sequence even for a
550 # parallel make.
551 headers: delheaders proto_exists
552
553 proto: idl headers
554
555 proto_test:
556         @[ -f $(builddir)/include/proto.h ] || $(MAKE) proto
557
558 clean: delheaders
559         -rm -f *.o */*.o */*/*.o */*/*/*.o bin/*
560         -rm -rf librpc/gen_*
561
562 distclean: clean
563         -rm -f bin/.dummy
564         -rm -f include/config.h 
565         -rm -f Makefile*
566         -rm -f config.status
567         -rm -f config.smb_build.*
568         -rm -f config.log config.cache
569
570 removebackup:
571         -rm -f *.bak *~ */*.bak */*~ */*/*.bak */*/*~ */*/*/*.bak */*/*/*~
572
573 realdistclean: distclean removebackup
574         -rm -f include/config.h.in
575         -rm -f lib/version.h
576         -rm -f configure
577 __EOD__
578
579         return $output;
580 }
581
582 sub _prepare_make_target($)
583 {
584         my $ctx = shift;
585         my $tmpdepend;
586         my $output;
587
588         $tmpdepend = array2oneperline($ctx->{DEPEND_LIST});
589
590         $output = << "__EOD__";
591 ###################################
592 # Start Target $ctx->{TARGET}
593 $ctx->{TARGET}: basics $tmpdepend
594 # End Target $ctx->{TARGET}
595 ###################################
596
597 __EOD__
598
599         return $output;
600 }
601
602 sub _prepare_target_settings($)
603 {
604         my $CTX = shift;
605         my $output = "";
606
607         foreach my $key (values %$CTX) {
608                 if (defined($key->{OBJ_LIST})) {
609                         $output .= _prepare_obj_list($key->{TYPE}, $key);
610                 }
611
612                 if (defined($key->{OBJ_LIST})) {
613                         $output .= _prepare_cflags($key->{TYPE}, $key);
614                 }
615         }
616
617         return $output;
618 }
619
620 sub _prepare_install_rules($)
621 {
622         my $CTX = shift;
623         my $output = "";
624
625         $output .= << '__EOD__';
626
627 showlayout: 
628         @echo "Samba will be installed into:"
629         @echo "  basedir: $(BASEDIR)"
630         @echo "  bindir:  $(BINDIR)"
631         @echo "  sbindir: $(SBINDIR)"
632         @echo "  libdir:  $(LIBDIR)"
633         @echo "  vardir:  $(VARDIR)"
634         @echo "  privatedir:  $(PRIVATEDIR)"
635         @echo "  piddir:  $(PIDDIR)"
636         @echo "  lockdir:  $(LOCKDIR)"
637         @echo "  swatdir:  $(SWATDIR)"
638
639 showflags:
640         @echo "Samba will be compiled with flags:"
641         @echo "  CFLAGS = $(CFLAGS)"
642         @echo "  LD_FLAGS = $(LD_FLAGS)"
643         @echo "  STLD_FLAGS = $(STLD_FLAGS)"
644         @echo "  SHLD_FLAGS = $(SHLD_FLAGS)"
645
646 SBIN_PROGS = bin/smbd
647
648 BIN_PROGS = bin/smbclient \
649                 bin/net \
650                 bin/nmblookup \
651                 bin/ntlm_auth
652
653 TORTURE_PROGS = bin/smbtorture \
654                 bin/gentest \
655                 bin/locktest \
656                 bin/masktest \
657                 bin/ndrdump
658
659 LDB_PROGS =     bin/ldbadd \
660                 bin/ldbdel \
661                 bin/ldbmodify \
662                 bin/ldbedit \
663                 bin/ldbsearch
664
665 REG_PROGS =     bin/regpatch \
666                 bin/regshell \
667                 bin/regtree \
668                 bin/regpatch \
669                 bin/regdiff
670
671 install: showlayout installbin installtorture installldb installreg installdat installswat
672
673 # DESTDIR is used here to prevent packagers wasting their time
674 # duplicating the Makefile. Remove it and you will have the privelege
675 # of package each samba release for muliple versions of multiple
676 # distributions and operating systems, or at least supplying patches
677 # to all the packaging files required for this, prior to committing
678 # the removal of DESTDIR. Do not remove it even though you think it
679 # is not used
680
681 installdirs:
682         @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(PRIVATEDIR) $(DESTDIR)$(PIDDIR) $(DESTDIR)$(LOCKDIR) $(DESTDIR)$(PRIVATEDIR)/tls
683
684 installbin: all installdirs
685         @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(SBIN_PROGS)
686         @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(BIN_PROGS)
687
688 installtorture: all installdirs
689         @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(TORTURE_PROGS)
690
691 installldb: all installdirs
692         @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(LDB_PROGS)
693
694 installreg: all installdirs
695         @$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(REG_PROGS)
696
697 installdat: installdirs
698         @$(SHELL) $(srcdir)/script/installdat.sh $(DESTDIR)$(LIBDIR) $(srcdir)
699
700 installswat: installdirs
701         @$(SHELL) $(srcdir)/script/installswat.sh $(DESTDIR)$(SWATDIR) $(srcdir)
702
703 uninstall: uninstallbin uninstalltorture uninstallldb uninstallreg
704
705 uninstallbin:
706         @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(SBIN_PROGS)
707
708 uninstalltorture:
709         @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(TORTURE_PROGS)
710
711 uninstallldb:
712         @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(LDB_PROGS)
713
714 uninstallreg:
715         @$(SHELL) $(srcdir)/script/uninstallbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(REG_PROGS)
716
717 # Swig extensions
718
719 swig: scripting/swig/_tdb.so scripting/swig/_dcerpc.so
720
721 scripting/swig/tdb_wrap.c: scripting/swig/tdb.i
722         swig -python scripting/swig/tdb.i
723
724 scripting/swig/_tdb.so: scripting/swig/tdb_wrap.o $(LIBRARY_swig_tdb_DEPEND_LIST)
725         $(SHLD) $(SHLD_FLAGS) -o scripting/swig/_tdb.so scripting/swig/tdb_wrap.o \
726                 $(LIBRARY_swig_tdb_SHARED_LINK_LIST) $(LIBRARY_swig_tdb_SHARED_LINK_FLAGS)
727
728 SWIG_INCLUDES = librpc/gen_ndr/samr.i librpc/gen_ndr/lsa.i librpc/gen_ndr/spoolss.i
729
730 scripting/swig/dcerpc_wrap.c: scripting/swig/dcerpc.i scripting/swig/samba.i scripting/swig/status_codes.i $(SWIG_INCLUDES)
731         swig -python scripting/swig/dcerpc.i
732
733 scripting/swig/_dcerpc.so: scripting/swig/dcerpc_wrap.o $(LIBRARY_swig_dcerpc_DEPEND_LIST)
734         $(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)
735
736 swig_clean:
737         -rm -f scripting/swig/_tdb.so scripting/swig/tdb.pyc \
738                 scripting/swig/tdb.py scripting/swig/tdb_wrap.c \
739                 scripting/swig/tdb_wrap.o
740
741 everything: all
742
743 etags:
744         etags `find $(srcdir) -name "*.[ch]"`
745
746 ctags:
747         ctags `find $(srcdir) -name "*.[ch]"`
748
749 __EOD__
750
751         return $output;
752 }
753
754 sub _prepare_rule_lists($)
755 {
756         my $depend = shift;
757         my $output = "";
758
759         foreach my $key (values %{$depend}) {
760                 next if not defined $key->{OUTPUT_TYPE};
761                 ($output .= _prepare_objlist_rule($key)) if $key->{OUTPUT_TYPE} eq "OBJLIST";
762                 ($output .= _prepare_static_library_rule($key)) if $key->{OUTPUT_TYPE} eq "STATIC_LIBRARY";
763                 ($output .= _prepare_shared_library_rule($key)) if $key->{OUTPUT_TYPE} eq "SHARED_LIBRARY";
764                 ($output .= _prepare_binary_rule($key)) if $key->{OUTPUT_TYPE} eq "BINARY";
765         }
766
767         my $idl_ctx;
768         $output .= _prepare_IDL($idl_ctx);
769
770         $output .= _prepare_proto_rules();
771
772         $output .= _prepare_install_rules($depend);
773
774         return $output;
775 }
776
777 ###########################################################
778 # This function prepares the output for Makefile
779 #
780 # $output = _prepare_makefile_in($OUTPUT)
781 #
782 # $OUTPUT -     the global OUTPUT context
783 #
784 # $output -             the resulting output buffer
785 sub _prepare_makefile_in($)
786 {
787         my $CTX = shift;
788         my $output;
789
790         $output  = "########################################\n";
791         $output .= "# Autogenerated by config.smb_build.pl #\n";
792         $output .= "########################################\n";
793         $output .= "\n";
794
795         my $cmd_ctx;
796         $output .= _prepare_command_interpreters($cmd_ctx);
797
798         my $path_ctx;
799         $output .= _prepare_path_vars($path_ctx);
800
801         my $compiler_ctx;
802         $output .= _prepare_compiler_linker($compiler_ctx);
803
804         my $rules_ctx;
805         $output .= _prepare_default_rule($rules_ctx);
806
807         my $suffix_ctx;
808         $output .= _prepare_SUFFIXES($suffix_ctx);
809
810         $output .= _prepare_dummy_MAKEDIR();
811
812         $output .= _prepare_std_CC_rule("c","o",'@PICFLAG@',"Compiling","Rule for std objectfiles");
813         $output .= _prepare_std_CC_rule("h","h.gch",'@PICFLAG@',"Precompiling","Rule for precompiled headerfiles");
814
815         $output .= _prepare_target_settings($CTX);
816
817         $output .= _prepare_rule_lists($CTX);
818
819         my @all = ();
820         
821         foreach my $part (values %{$CTX}) {
822                 push (@all, $part->{TARGET}) if defined ($part->{OUTPUT_TYPE}) and $part->{OUTPUT_TYPE} eq "BINARY";    
823         }
824         
825         $output .= _prepare_make_target({ TARGET => "all", DEPEND_LIST => \@all });
826
827         return $output;
828 }
829
830 ###########################################################
831 # This function creates Makefile.in from the OUTPUT 
832 # context
833 #
834 # create_makefile_in($OUTPUT)
835 #
836 # $OUTPUT       -       the global OUTPUT context
837 #
838 # $output -             the resulting output buffer
839 sub create_makefile_in($$)
840 {
841         my $CTX = shift;
842         my $file = shift;
843
844         open(MAKEFILE_IN,">$file") || die ("Can't open $file\n");
845         print MAKEFILE_IN _prepare_makefile_in($CTX);
846         close(MAKEFILE_IN);
847
848         print "config.smb_build.pl: creating $file\n";
849         return; 
850 }
851
852 1;