Imported Upstream version 3.2.0
[debian/amanda] / config / automake / installperms.am
1 # vim:ft=automake
2 #
3 # Adjust post-install permissions settings.  This rule works off two
4 # specially-formatted variables, INSTALLPERMS_exec and INSTALLPERMS_data. 
5 # Each is a whitespace-separated list of commands, all of which are either
6 # a variable assignment or a filename.  Three variables are available:
7 #
8 #  - dest= sets the destination directory to e.g., $(sbindir)
9 #  - chown= controls changes in ownership; value is first argument to chown
10 #  - chmod= controls changes in permissions; value is first argument to chmod
11 #
12 # The following special cases are available:
13 #       amanda:setuid = $(BINARY_OWNER):$(SETUID_GROUP)
14 #       root:setuid = root:$(SETUID_GROUP)
15 # These variables might otherwise have problems with whitespace in the user/group
16 # names.
17 #
18 # when a filename is seen, the currently active variables are applied.
19 #
20 # Note that scripts are data, not executables!
21 #
22 # EXAMPLE
23 #
24 # sbin_PROGRAMS = foo bar bing
25 # libexec_PROGRAMS = pro gram
26 # sbin_SCRIPTS = sk ript
27 # INSTALLPERMS_exec = \
28 #       dest=$(sbindir) chown=amanda chmod= \
29 #               foo bar \
30 #       chmod=07450 \
31 #               bing
32 #       dest=$(libexecdir) chmod= \
33 #               $(libexec_PROGRAMS)
34 # INSTALLPERMS_data = \
35 #       dest=$(sbindir) chown=amanda chmod= \
36 #               $(sbin_SCRIPTS)
37 #
38 # This whole operation is not required when making builds for packaging,
39 # and can be disabled with --disable-installperms, via the WANT_INSTALLPERMS
40 # AM_CONDITIONAL.  When disabled, the file 'installperms.sh' in the top-level
41 # build directory is populated with a format suitable for shell interpretation,
42 # with lines like this:
43 #   installperm "amanda:disk" "04750" "/usr/local/sbin/bing"
44 # the arguments being, respectively, owner:group, mode, and filename.  There will
45 # be exactly one line for each file which has specific permissions.  The intention
46 # is that this file be used by packaging scripts to set correct permissions at install
47 # time.  Note that files which have no special permissions requirements do not appear 
48 # in this file at all, due to limitations of Automake.
49
50 # sed expression to strip leading directories from a filename; this converts e.g.,
51 # src/foo/bar.so to bar.so.
52 strip_leading_dirs=s|^.*/||
53
54 # define a snippet of the scripts below to either perform a chown/chmod operation,
55 # or record that operation in the logfile.  On entry to the snippet, $$dest is the
56 # destination directory, $$cmd is the srcdir-relative pathname of the target file,
57 # $$chown is the ownership, and $$chmod is the permission pattern.
58 if WANT_INSTALLPERMS
59 do_file=pa="$(DESTDIR)$$dest"/`echo "$$cmd"|sed '$(strip_leading_dirs)'|sed '$(transform)'`; \
60     if test -n "$$chown"; then \
61         echo chown "$$chown" "$$pa"; \
62         chown "$$chown" "$$pa" || exit 1; \
63     fi; \
64     if test -n "$$chmod"; then \
65         echo chmod "$$chmod" "$$pa"; \
66         chmod "$$chmod" "$$pa" || exit 1; \
67     fi 
68 else
69 installperms_sh="$(top_builddir)/installperms.sh"
70 do_file=pa="$$dest"/`echo "$$cmd"|sed '$(strip_leading_dirs)'|sed '$(transform)'`; \
71     echo "installperm \"$$chown\" \"$$chmod\" \"$$pa\"" >> "$(installperms_sh)"
72 DISTCLEANFILES += $(installperms_sh)
73 endif
74
75 do_installperms=dest=; chown=; chmod=; \
76         for cmd in $$installperms; do \
77             case "$$cmd" in \
78                 chown=amanda:setuid) \
79                     echo "  ($$cmd)"; chown="$(BINARY_OWNER):$(SETUID_GROUP)";; \
80                 chown=root:setuid) \
81                     echo "  ($$cmd)"; chown="root:$(SETUID_GROUP)";; \
82                 dest=*|chown=*|chmod=*) \
83                         echo "  ($$cmd)"; eval $$cmd;; \
84                 *) $(do_file) ;; \
85             esac; \
86         done
87
88 installperms-exec:
89         @installperms="$(INSTALLPERMS_exec)"; \
90         test -n "$$installperms" && echo "Setting installation permissions on executables"; \
91         $(do_installperms)
92
93 installperms-data:
94         @installperms="$(INSTALLPERMS_data)"; \
95         test -n "$$installperms" && echo "Setting installation permissions on data"; \
96         $(do_installperms)
97
98 install-exec-hook: installperms-exec
99 install-data-hook: installperms-data
100
101 # define a rule to initialize the installperms manifest file
102 if WANT_INSTALLPERMS
103 installperms-init:
104 else
105 installperms-init:
106         rm -f "$(installperms_sh)"
107 endif