summaryrefslogtreecommitdiffabout
path: root/GNUmakefile
blob: b5b4909f0f8d016a487eba558a507315e55aa254 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# usage:
#
# 1. make config PREFIX=dir [MAILMANSRC=dir] [NAME=VAL]...
#   Configure the system. PREFIX is installation prefix. MAILMANSRC is
#   the name of the Mailman source tree directory (must be writable).
#   Other meaningful variables are:
#
#     MAILMANDIR   - Top installation directory for mailman script.
#                    Default: $(PREFIX)/Mailman
#     BINDIR       - Installation directory for executable scripts.
#                    Default: $(PREFIX)/bin
#     HTDOCSDIR    - Installation directory for static HTML pages.
#                    Default: $(PREFIX)/htdocs
#     TEMPLATESDIR - Top installation directory for templates.
#                    Default: $(PREFIX)/templates
#     MANDIR       - Top installation directory for manual pages.
#                    Default: $(PREFIX)/man
#     CGIDIR       - Installation directory for listarchive CGI
#                    Default: $(PREFIX)/cgi-bin
#
#   If all these variables are supplied, PREFIX can be omitted.
#
# 2. make install
#   Installs everything.
#   Following targets can be used instead of install:
#
#     install-cgi       - Builds (if necessary) and installs the listarchive
#                         cgi.
#     install-Mailman   - Installs scripts in the Mailman subdirectory.
#     install-templates - Installs templates.
#     install-bin       - Installs scripts,
#     install-man       - Installs manpages.
#     install-htdocs    - Installs static HTML files.
#     
# 3. make listarchive
#   Builds the listarchive cgi in $(MAILMANSRC)/src.
#
# 4. make clean
#   Remove created files.
#
# 5. make distclean
#   Remove all created files and configuration cache.
#
# 6. make help
#   Shows this help list.
#
# usage ends

ifneq (,$(wildcard .config))
  include .config
else ifeq (,$(MAKECMDGOALS))
  # Nothing
else ifeq (,$(findstring $(MAKECMDGOALS),help config))
  $(error Please run make config first)
endif

help:
	@sed -n \
	     -e '/# usage ends/,$$d' \
             -e 's/^# //' \
             -e ta \
             -e 's/^#$$//' \
             -e ta \
             -e d \
             -e :a \
             -e '/^usage:/,$$p' $(firstword $(MAKEFILE_LIST))

DEFSRC = $(firstword $(wildcard /usr/src/mailman-[0-9][0-9.]*))

config:
	@(for var in PREFIX MAILMANDIR BINDIR HTDOCSDIR \
                   TEMPLATESDIR MANDIR CGIDIR;                       \
	do                                                           \
	    eval x=\$${$$var};                                       \
            if [ -n "$$x" ]; then                                    \
	        echo "$$var=$$x";                                    \
	    fi;                                                      \
	done;                                                        \
	if [ -n "$$MAILMANSRC" ]; then	                             \
	    echo "MAILMANSRC=$$MAILMANSRC";                          \
	elif [ -n "$(DEFSRC)" ]; then                                \
	    echo >&2 "assuming MAILMANSRC=$(DEFSRC)";                \
	    echo "MAILMANSRC=$(DEFSRC)";                             \
	else                                                         \
	    echo >&2 "Please set MAILMANSRC to point to the mailman-2.x tree"; \
            exit 1;                                                  \
	fi) > .config.tmp
	@if ! grep -q ^PREFIX .config.tmp && \
           test "$$(sed -r -n -e 's/^(MAILMANDIR|BINDIR|HTDOCSDIR|TEMPLATESDIR|MANDIR|CGIDIR)=.*/x/p' .config.tmp | tr -d '\n')" != xxxxxx; then    \
            echo >&2 "PREFIX must be supplied";                      \
	    rm .config.tmp;                                          \
            exit 1;                                                  \
	fi
	@mv .config.tmp .config

define build_cgi_rule = 
$(1):; @if [ -z "$(MAILMANSRC)" ]; then                                     \
	  echo >&2 "Please set MAILMANSRC to point to the mailman-2.x tree"; \
	  exit 1;                                                            \
	elif ! test -w $(MAILMANSRC)/src; then                               \
          echo >&2 "$(MAILMANSRC)/src must be writable";                     \
          exit 1;                                                            \
	else                                                                 \
          make -C $(MAILMANSRC)/src CGI_PROGS=$(1) $(1);                     \
        fi
endef

$(foreach tgt,listarchive findmail,$(eval $(call build_cgi_rule,$(tgt))))

define geninstall
install-$(1):;
	install -d $$(DESTDIR)$$($(shell echo $(1) | tr '[:lower:]' '[:upper:]')DIR)
	tar -C $(1) -cf - . | tar -C $$(DESTDIR)$$($(shell echo $(1) | tr '[:lower:]' '[:upper:]')DIR) -xpf -
endef

MAILMANDIR   = $(PREFIX)/Mailman
BINDIR       = $(PREFIX)/bin
HTDOCSDIR    = $(PREFIX)/htdocs
TEMPLATESDIR = $(PREFIX)/templates
MANDIR       = $(PREFIX)/man
CGIDIR       = $(PREFIX)/cgi-bin

TARGETS=\
  Mailman\
  templates\
  bin\
  man\
  htdocs

$(foreach tgt,$(TARGETS),$(eval $(call geninstall,$(tgt))))

install-cgi: listarchive findmail
	install -d $(DESTDIR)$(CGIDIR)
	install -o root -g mailman -m 2755 $(MAILMANSRC)/src/listarchive $(DESTDIR)$(CGIDIR)
	install -o root -g mailman -m 2755 $(MAILMANSRC)/src/findmail $(DESTDIR)$(CGIDIR)

install: install-cgi $(foreach tgt,$(TARGETS), install-$(tgt))

clean:
	@rm -f $(MAILMANSRC)/src/listarchive

distclean: clean
	@rm -f .config

Return to:

Send suggestions and report system problems to the System administrator.