245345bb18ae7f4a0a4c002c31c00f69332396cc
[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 # As a special case, chown=amanda is taken as equivalent to 
13 # chown=$(BINARY_OWNER):$(SETUID_GROUP), which may otherwise have problems with
14 # whitespace in the user/group names.
15
16 # when a filename is seen, the currently active variables are applied.
17 #
18 # Note that scripts are data, not executables!
19 #
20 # EXAMPLE
21 #
22 # sbin_PROGRAMS = foo bar bing
23 # libexec_PROGRAMS = pro gram
24 # sbin_SCRIPTS = sk ript
25 # INSTALLPERMS_exec = \
26 #       dest=$(sbindir) chown=amanda chmod= \
27 #               foo bar \
28 #       chmod=u+s,o-rwx \
29 #               bing
30 #       dest=$(libexecdir) chmod= \
31 #               $(libexec_PROGRAMS)
32 # INSTALLPERMS_data = \
33 #       dest=$(sbindir) chown=amanda chmod= \
34 #               $(sbin_SCRIPTS)
35 #
36 # This whole operation is not required when making builds for packaging,
37 # and can be disabled with --disable-installperms, via the WANT_INSTALLPERMS
38 # AM_CONDITIONAL.
39
40 # sed expression to strip leading directories from a filename; this converts e.g.,
41 # src/foo/bar.so to bar.so.
42 strip_leading_dirs=s|^.*/||
43
44 if WANT_INSTALLPERMS
45 installperms-exec:
46         @installperms="$(INSTALLPERMS_exec)"; \
47         test -n "$$installperms" && echo "Setting installation permissions on executables"; \
48         dest=; chown=; chmod=; \
49         for cmd in $$installperms; do \
50             case "$$cmd" in \
51                 chown=amanda) \
52                         echo "  ($$cmd)"; chown="$(BINARY_OWNER):$(SETUID_GROUP)";; \
53                 dest=*|chown=*|chmod=*) \
54                         echo "  ($$cmd)"; eval $$cmd;; \
55                 *)  pa="$(DESTDIR)$$dest"/`echo "$$cmd"|sed '$(strip_leading_dirs)'|sed '$(transform)'`; \
56                     if test -n "$$chown"; then \
57                         echo chown "$$chown" "$$pa"; \
58                         chown "$$chown" "$$pa" || exit 1; \
59                     fi; \
60                     if test -n "$$chmod"; then \
61                         echo chmod "$$chmod" "$$pa"; \
62                         chmod "$$chmod" "$$pa" || exit 1; \
63                     fi; \
64             esac; \
65         done
66
67 installperms-data:
68         @installperms="$(INSTALLPERMS_data)"; \
69         test -n "$$installperms" && echo "Setting installation permissions on data"; \
70         dest=; chown=; chmod=; \
71         for cmd in $$installperms; do \
72             case "$$cmd" in \
73                 chown=amanda) \
74                         echo "  ($$cmd)"; chown="$(BINARY_OWNER):$(SETUID_GROUP)";; \
75                 dest=*|chown=*|chmod=*) \
76                         echo "  ($$cmd)"; eval $$cmd;; \
77                 *)  pa="$(DESTDIR)$$dest"/`echo "$$cmd"|sed '$(strip_leading_dirs)'|sed '$(transform)'`; \
78                     if test -n "$$chown"; then \
79                         echo chown "$$chown" "$$pa"; \
80                         chown "$$chown" "$$pa" || exit 1; \
81                     fi; \
82                     if test -n "$$chmod"; then \
83                         echo chmod "$$chmod" "$$pa"; \
84                         chmod "$$chmod" "$$pa" || exit 1; \
85                     fi; \
86             esac; \
87         done
88
89 install-exec-hook: installperms-exec
90 install-data-hook: installperms-data
91 endif