f074dcfa36523940131af33f16fbac3f708acd19
[portage.git] / Makefile
1 SHELL = /bin/sh
2 PN ?= portage
3 PF ?= portage
4 HOMEPAGE ?= http://www.gentoo.org/proj/en/portage/index.xml
5 PWD ?= $(shell pwd)
6 S ?= $(PWD)
7 WORKDIR ?= $(PWD)
8 DESTDIR = $(PWD)/image/
9 srcdir = $(S)
10 prefix = /usr
11 sysconfdir = /etc
12 exec_prefix = $(prefix)
13 bindir = $(exec_prefix)/bin
14 sbindir = $(exec_prefix)/sbin
15 libdir = $(exec_prefix)/lib
16 datarootdir = $(prefix)/share
17 datadir = $(datarootdir)
18 mandir = $(datarootdir)/man
19 docdir = $(datarootdir)/doc/$(PF)
20 htmldir = $(docdir)/html
21 portage_datadir = $(datarootdir)/$(PN)
22 portage_confdir = $(portage_datadir)/config
23 portage_setsdir = $(portage_confdir)/sets
24 portage_base = $(libdir)/$(PN)
25 EPYDOC_OPTS = -qqqqq --no-frames --show-imports
26 INSMODE = 0644
27 EXEMODE = 0755
28 DIRMODE = 0755
29 SYSCONFDIR_FILES = etc-update.conf dispatch-conf.conf
30 PORTAGE_CONFDIR_FILES = make.globals
31 LOGROTATE_FILES = elog-save-summary
32 BINDIR_FILES = ebuild egencache emerge emerge-webrsync \
33         portageq quickpkg repoman
34 SBINDIR_FILES = archive-conf dispatch-conf emaint \
35         env-update etc-update fixpackages regenworld
36 DOCS = ChangeLog NEWS RELEASE-NOTES
37
38 ifdef PYTHONPATH
39         PYTHONPATH := $(srcdir)/pym:$(PYTHONPATH)
40 else
41         PYTHONPATH := $(srcdir)/pym
42 endif
43
44 all: docbook epydoc
45
46 docbook:
47         set -e; \
48         touch "$(srcdir)/doc/fragment/date"; \
49         $(MAKE) -C "$(srcdir)/doc" xhtml xhtml-nochunks
50
51 epydoc:
52         set -e; \
53         # workaround for bug 282760 \
54         touch "$(srcdir)/pym/pysqlite2.py"; \
55         env PYTHONPATH="$(PYTHONPATH)" epydoc \
56                 -o "$(WORKDIR)/epydoc" \
57                 --name $(PN) \
58                 --url "$(HOMEPAGE)" \
59                 $(EPYDOC_OPTS) \
60                 $$(cd "$(srcdir)" && find pym -name '*.py' | sed \
61                 -e s:/__init__.py$$:: \
62                 -e s:\.py$$:: \
63                 -e s:^pym/:: \
64                 -e s:/:.:g \
65                 | sort); \
66         rm -f "$(srcdir)/pym/pysqlite2.py"* \
67                 "$(WORKDIR)/epydoc/pysqlite2-"* \
68                 "$(WORKDIR)/epydoc/api-objects.txt"; \
69
70 test:
71         set -e; \
72         "$(srcdir)/pym/portage/tests/runTests"; \
73
74 install:
75         set -e; \
76         cd "$(srcdir)/cnf"; \
77         install -d -m$(DIRMODE) "$(DESTDIR)$(sysconfdir)"; \
78         install -m$(INSMODE) $(SYSCONFDIR_FILES) "$(DESTDIR)$(sysconfdir)"; \
79         \
80         install -d -m$(DIRMODE) "$(DESTDIR)$(portage_confdir)"; \
81         cd "$(srcdir)/cnf"; \
82         install -m$(INSMODE) $(PORTAGE_CONFDIR_FILES) \
83                 "$(DESTDIR)$(portage_confdir)"; \
84         install -m$(INSMODE) "$(srcdir)/cnf/make.conf" \
85                 "$(DESTDIR)$(portage_confdir)/make.conf.example"; \
86         \
87         install -d -m$(DIRMODE) "$(DESTDIR)$(portage_setsdir)"; \
88         cd "$(S)/cnf/sets"; \
89         install -m$(INSMODE) *.conf "$(DESTDIR)$(portage_setsdir)"; \
90         \
91         install -d -m$(DIRMODE) "$(DESTDIR)$(sysconfdir)/logrotate.d"; \
92         cd "$(srcdir)/cnf/logrotate.d"; \
93         install -m$(INSMODE) $(LOGROTATE_FILES) \
94                 "$(DESTDIR)$(sysconfdir)/logrotate.d"; \
95         \
96         for x in $$(cd "$(srcdir)" && find bin -type d) ; do \
97                 cd "$(srcdir)/$$x"; \
98                 install -d -m$(DIRMODE) "$(DESTDIR)$(portage_base)/$$x"; \
99                 files=$$(find . -mindepth 1 -maxdepth 1 -type f ! -type l); \
100                 if [ -n "$$files" ] ; then \
101                         install -m$(EXEMODE) $$files \
102                                 "$(DESTDIR)$(portage_base)/$$x"; \
103                 fi; \
104                 symlinks=$$(find . -mindepth 1 -maxdepth 1 -type l); \
105                 if [ -n "$$symlinks" ] ; then \
106                         cp -P $$symlinks "$(DESTDIR)$(portage_base)/$$x"; \
107                 fi; \
108         done; \
109         \
110         for x in $$(cd "$(srcdir)" && find pym/* -type d \
111                 ! -path "pym/portage/tests*") ; do \
112                 cd "$(srcdir)/$$x"; \
113                 files=$$(echo *.py); \
114                 if [ -z "$$files" ] || [ "$$files" = "*.py" ]; then \
115                         # __pycache__ directories contain no py files \
116                         continue; \
117                 fi; \
118                 install -d -m$(DIRMODE) "$(DESTDIR)$(portage_base)/$$x"; \
119                 install -m$(INSMODE) $$files "$(DESTDIR)$(portage_base)/$$x"; \
120         done; \
121         \
122         install -d -m$(DIRMODE) "$(DESTDIR)$(bindir)"; \
123         relative_path=".."; \
124         x=$(bindir) ; \
125         y="$(portage_base)"; \
126         if [ "$${x#$(prefix)}" != "$$x" ] && \
127                 [ "$${y#$(prefix)}" != "$$y" ]; then \
128                 x=$${x#$(prefix)}; \
129                 y=$${y#$(prefix)}; \
130         fi; \
131         x=$${x%/*}; \
132         while [ -n "$$x" ] ; do \
133                 relative_path=$${relative_path}/..; \
134                 x=$${x%/*}; \
135         done; \
136         relative_path=$$relative_path$$y; \
137         for x in $(BINDIR_FILES) ; do \
138                 ln -sf "$$relative_path/bin/$$x" \
139                         "$(DESTDIR)$(bindir)/$$x"; \
140         done; \
141         \
142         install -d -m$(DIRMODE) "$(DESTDIR)$(sbindir)"; \
143         relative_path=".."; \
144         x=$(sbindir) ; \
145         y="$(portage_base)"; \
146         if [ "$${x#$(prefix)}" != "$$x" ] && \
147                 [ "$${y#$(prefix)}" != "$$y" ]; then \
148                 x=$${x#$(prefix)}; \
149                 y=$${y#$(prefix)}; \
150         fi; \
151         x=$${x%/*}; \
152         while [ -n "$$x" ] ; do \
153                 relative_path=$${relative_path}/..; \
154                 x=$${x%/*}; \
155         done; \
156         relative_path=$$relative_path$$y; \
157         for x in $(SBINDIR_FILES) ; do \
158                 ln -sf "$$relative_path/bin/$$x" \
159                         "$(DESTDIR)$(sbindir)/$$x"; \
160         done; \
161         \
162         ln -sf "$$relative_path/bin/env-update" \
163                 "$(DESTDIR)$(sbindir)/update-env"; \
164         ln -sf "$$relative_path/bin/etc-update" \
165                 "$(DESTDIR)$(sbindir)/update-etc"; \
166         \
167         # We install some minimal tests for use as a preinst sanity check. \
168         # These tests must be able to run without a full source tree and \
169         # without relying on a previous portage instance being installed. \
170         install -d -m$(DIRMODE) \
171                 "$(DESTDIR)$(portage_base)/pym/portage/tests"; \
172         install -m$(EXEMODE) "$(srcdir)/pym/portage/tests/runTests" \
173                 "$(DESTDIR)$(portage_base)/pym/portage/tests"; \
174         cd "$(srcdir)/pym/portage/tests"; \
175         install -m$(INSMODE) *.py \
176                 "$(DESTDIR)$(portage_base)/pym/portage/tests"; \
177         install -d -m$(DIRMODE) \
178                 "$(DESTDIR)$(portage_base)/pym/portage/tests/lint"; \
179         cd "$(srcdir)/pym/portage/tests/lint"; \
180         install -m$(INSMODE) *.py __test__ \
181                 "$(DESTDIR)$(portage_base)/pym/portage/tests/lint"; \
182         \
183         install -d -m$(DIRMODE) "$(DESTDIR)$(docdir)"; \
184         cd "$(srcdir)"; \
185         install -m $(INSMODE) $(DOCS) "$(DESTDIR)$(docdir)"; \
186         \
187         for x in 1 5 ; do \
188                 install -d -m$(DIRMODE) "$(DESTDIR)$(mandir)/man$$x"; \
189                 cd "$(srcdir)/man"; \
190                 install -m$(INSMODE) *.$$x "$(DESTDIR)$(mandir)/man$$x"; \
191         done; \
192         \
193         if [ -f "$(srcdir)/doc/portage.html" ] ; then \
194                 install -d -m$(DIRMODE) "$(DESTDIR)$(htmldir)"; \
195                 cd "$(srcdir)/doc"; \
196                 install -m$(INSMODE) *.html "$(DESTDIR)$(htmldir)"; \
197         fi; \
198         \
199         if [ -d "$(WORKDIR)/epydoc" ] ; then \
200                 install -d -m$(DIRMODE) "$(DESTDIR)$(htmldir)"; \
201                 cp -pPR "$(WORKDIR)/epydoc" \
202                         "$(DESTDIR)$(htmldir)/api"; \
203                 cd "$(DESTDIR)$(htmldir)/api"; \
204                 find . -type d | xargs chmod $(DIRMODE); \
205                 find . -type f | xargs chmod $(INSMODE); \
206         fi; \
207
208 clean:
209         set -e; \
210         $(MAKE) -C "$(srcdir)/doc" clean; \
211         rm -rf "$(srcdir)/pym/pysqlite2.py"* \
212                 "$(WORKDIR)/epydoc"; \
213
214 .PHONY: all clean docbook epydoc install test