Git init
[framework/uifw/xorg/proto/x11proto-kb.git] / debian / xsfbs / xsfbs.mk
1 #!/usr/bin/make -f
2
3 # Debian X Strike Force Build System (XSFBS): Make portion
4
5 # Copyright 1996 Stephen Early
6 # Copyright 1997 Mark Eichin
7 # Copyright 1998-2005, 2007 Branden Robinson
8 # Copyright 2005 David Nusinow
9 #
10 # Licensed under the GNU General Public License, version 2.  See the file
11 # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
12
13 # Originally by Stephen Early <sde1000@debian.org>
14 # Modified by Mark W. Eichin <eichin@kitten.gen.ma.us>
15 # Modified by Adam Heath <doogie@debian.org>
16 # Modified by Branden Robinson <branden@debian.org>
17 # Modified by Fabio Massimo Di Nitto <fabbione@fabbione.net>
18 # Modified by David Nusinow <dnusinow@debian.org>
19 # Acknowledgements to Manoj Srivastava.
20
21 # Pass $(DH_OPTIONS) into the environment for debhelper's benefit.
22 export DH_OPTIONS
23
24 # force quilt to not use ~/.quiltrc and to use debian/patches
25 QUILT = QUILT_PATCHES=debian/patches quilt --quiltrc /dev/null
26
27 # Set up parameters for the upstream build environment.
28
29 # Determine (source) package name from Debian changelog.
30 SOURCE_NAME:=$(shell dpkg-parsechangelog -ldebian/changelog \
31                         | grep '^Source:' | awk '{print $$2}')
32
33 # Determine package version from Debian changelog.
34 SOURCE_VERSION:=$(shell dpkg-parsechangelog -ldebian/changelog \
35                         | grep '^Version:' | awk '{print $$2}')
36
37 # Determine upstream version number.
38 UPSTREAM_VERSION:=$(shell echo $(SOURCE_VERSION) | sed 's/-.*//')
39
40 # Determine the source version without the epoch for make-orig-tar-gz
41 NO_EPOCH_VER:=$(shell echo $(UPSTREAM_VERSION) | sed 's/^.://')
42
43 # Figure out who's building this package.
44 BUILDER:=$(shell echo $${DEBEMAIL:-$${EMAIL:-$$(echo $$LOGNAME@$$(cat /etc/mailname 2>/dev/null))}})
45
46 # Find out if this is an official build; an official build has nothing but
47 # digits, dots, and/or the codename of a release in the Debian part of the
48 # version number.  Anything else indicates an unofficial build.
49 OFFICIAL_BUILD:=$(shell VERSION=$(SOURCE_VERSION); if ! expr "$$(echo $${VERSION\#\#*-} | sed 's/\(woody\|sarge\|etch\|lenny\)//g')" : ".*[^0-9.].*" >/dev/null 2>&1; then echo yes; fi)
50
51 # Set up parameters for the Debian build environment.
52
53 # Determine our architecture.
54 BUILD_ARCH:=$(shell dpkg-architecture -qDEB_BUILD_ARCH)
55 # Work around some old-time dpkg braindamage.
56 BUILD_ARCH:=$(subst i486,i386,$(BUILD_ARCH))
57 # The DEB_HOST_ARCH variable may be set per the Debian cross-compilation policy.
58 ifdef DEB_HOST_ARCH
59  ARCH:=$(DEB_HOST_ARCH)
60 else
61  # dpkg-cross sets the ARCH environment variable; if set, use it.
62  ifdef ARCH
63   ARCH:=$(ARCH)
64  else
65   ARCH:=$(BUILD_ARCH)
66  endif
67 endif
68
69 # $(STAMP_DIR) houses stamp files for complex targets.
70 STAMP_DIR:=stampdir
71
72 # $(DEBTREEDIR) is where all install rules are told (via $(DESTDIR)) to place
73 # their files.
74 DEBTREEDIR:=$(CURDIR)/debian/tmp
75
76 # All "important" targets have four lines:
77 #   1) A target name that is invoked by a package-building tool or the user.
78 #      This consists of a dependency on a "$(STAMP_DIR)/"-prefixed counterpart.
79 #   2) A line delcaring 1) as a phony target (".PHONY:").
80 #   3) A "$(STAMP_DIR)/"-prefixed target which does the actual work, and may
81 #   depend on other targets.
82 #   4) A line declaring 3) as a member of the $(stampdir_targets) variable; the
83 #   "$(STAMP_DIR)/" prefix is omitted.
84 #
85 # This indirection is needed so that the "stamp" files that signify when a rule
86 # is done can be located in a separate "stampdir".  Recall that make has no way
87 # to know when a goal has been met for a phony target (like "build" or
88 # "install").
89 #
90 # At the end of each "$(STAMP_DIR)/" target, be sure to run the command ">$@"
91 # so that the target will not be run again.  Removing the file will make Make
92 # run the target over.
93
94 # All phony targets should be declared as dependencies of .PHONY, even if they
95 # do not have "($STAMP_DIR)/"-prefixed counterparts.
96
97 # Define a harmless default rule to keep things from going nuts by accident.
98 .PHONY: default
99 default:
100
101 # Set up the $(STAMP_DIR) directory.
102 .PHONY: stampdir
103 stampdir_targets+=stampdir
104 stampdir: $(STAMP_DIR)/stampdir
105 $(STAMP_DIR)/stampdir:
106         mkdir $(STAMP_DIR)
107         >$@
108
109 # Set up the package build directory as quilt expects to find it.
110 .PHONY: prepare
111 stampdir_targets+=prepare
112 prepare: $(STAMP_DIR)/prepare
113 $(STAMP_DIR)/prepare: $(STAMP_DIR)/log $(STAMP_DIR)/genscripts
114         >$@
115
116 .PHONY: log
117 stampdir_targets+=log
118 log: $(STAMP_DIR)/log
119 $(STAMP_DIR)/log: $(STAMP_DIR)/stampdir
120         mkdir -p $(STAMP_DIR)/log
121
122 # Apply all patches to the upstream source.
123 .PHONY: patch
124 stampdir_targets+=patch
125 patch: $(STAMP_DIR)/patch
126 $(STAMP_DIR)/patch: $(STAMP_DIR)/prepare
127         if ! [ `which quilt` ]; then \
128                 echo "Couldn't find quilt. Please install it or add it to the build-depends for this package."; \
129                 exit 1; \
130         fi; \
131         if $(QUILT) next >/dev/null 2>&1; then \
132           echo -n "Applying patches..."; \
133           if $(QUILT) push -a -v >$(STAMP_DIR)/log/patch 2>&1; then \
134             cat $(STAMP_DIR)/log/patch; \
135             echo "successful."; \
136           else \
137             cat $(STAMP_DIR)/log/patch; \
138             echo "failed! (check $(STAMP_DIR)/log/patch for details)"; \
139             exit 1; \
140           fi; \
141         else \
142           echo "No patches to apply"; \
143         fi; \
144         >$@
145
146 # Revert all patches to the upstream source.
147 .PHONY: unpatch
148 unpatch: $(STAMP_DIR)/log
149         rm -f $(STAMP_DIR)/patch
150         @echo -n "Unapplying patches..."; \
151         if $(QUILT) applied >/dev/null 2>/dev/null; then \
152           if $(QUILT) pop -a -v >$(STAMP_DIR)/log/unpatch 2>&1; then \
153             cat $(STAMP_DIR)/log/unpatch; \
154             echo "successful."; \
155           else \
156             cat $(STAMP_DIR)/log/unpatch; \
157             echo "failed! (check $(STAMP_DIR)/log/unpatch for details)"; \
158             exit 1; \
159           fi; \
160         else \
161           echo "nothing to do."; \
162         fi
163
164 # Clean the generated maintainer scripts.
165 .PHONY: cleanscripts
166 cleanscripts:
167         rm -f $(STAMP_DIR)/genscripts
168         rm -f debian/*.config \
169               debian/*.postinst \
170               debian/*.postrm \
171               debian/*.preinst \
172               debian/*.prerm
173
174 # Clean the package build tree.
175 .PHONY: xsfclean
176 xsfclean: cleanscripts unpatch
177         dh_testdir
178         rm -rf .pc
179         rm -rf $(STAMP_DIR) $(SOURCE_DIR)
180         rm -rf imports
181         dh_clean debian/shlibs.local \
182                  debian/po/pothead
183
184 # Generate the debconf templates POT file header.
185 debian/po/pothead: debian/po/pothead.in
186         sed -e 's/SOURCE_VERSION/$(SOURCE_VERSION)/' \
187           -e 's/DATE/$(shell date "+%F %X%z"/)' <$< >$@
188
189 # Update POT and PO files.
190 .PHONY: updatepo
191 updatepo: debian/po/pothead
192         debian/scripts/debconf-updatepo --pot-header=pothead --verbose
193
194 # Remove files from the upstream source tree that we don't need, or which have
195 # licensing problems.  It must be run before creating the .orig.tar.gz.
196 #
197 # Note: This rule is for Debian package maintainers' convenience, and is not
198 # needed for conventional build scenarios.
199 .PHONY: prune-upstream-tree
200 prune-upstream-tree:
201         # Ensure we're in the correct directory.
202         dh_testdir
203         grep -rvh '^#' debian/prune/ | xargs --no-run-if-empty rm -rf
204
205 # Verify that there are no offsets or fuzz in the patches we apply.
206 #
207 # Note: This rule is for Debian package maintainers' convenience, and is not
208 # needed for conventional build scenarios.
209 .PHONY: patch-audit
210 patch-audit: prepare unpatch
211         @echo -n "Auditing patches..."; \
212         >$(STAMP_DIR)/log/patch; \
213         FUZZY=; \
214         while [ -n "$$($(QUILT) next)" ]; do \
215           RESULT=$$($(QUILT) push -v | tee -a $(STAMP_DIR)/log/patch | grep ^Hunk | sed 's/^Hunk.*\(succeeded\|FAILED\).*/\1/');\
216           case "$$RESULT" in \
217             succeeded) \
218               echo "fuzzy patch: $$($(QUILT) top)" \
219                 | tee -a $(STAMP_DIR)/log/$$($(QUILT) top); \
220               FUZZY=yes; \
221               ;; \
222             FAILED) \
223               echo "broken patch: $$($(QUILT) next)" \
224                 | tee -a $(STAMP_DIR)/log/$$($(QUILT) next); \
225               exit 1; \
226               ;; \
227           esac; \
228         done; \
229         if [ -n "$$FUZZY" ]; then \
230           echo "there were fuzzy patches; please fix."; \
231           exit 1; \
232         else \
233           echo "done."; \
234         fi
235
236 # Generate the maintainer scripts.
237 .PHONY: genscripts
238 stampdir_targets+=genscripts
239 genscripts: $(STAMP_DIR)/genscripts
240 $(STAMP_DIR)/genscripts: $(STAMP_DIR)/stampdir
241         for FILE in debian/*.config.in \
242                     debian/*.postinst.in \
243                     debian/*.postrm.in \
244                     debian/*.preinst.in \
245                     debian/*.prerm.in; do \
246           if [ -e "$$FILE" ]; then \
247             MAINTSCRIPT=$$(echo $$FILE | sed 's/.in$$//'); \
248             sed -n '1,/^#INCLUDE_SHELL_LIB#$$/p' <$$FILE \
249               | sed -e '/^#INCLUDE_SHELL_LIB#$$/d' >$$MAINTSCRIPT.tmp; \
250             cat debian/xsfbs/xsfbs.sh >>$$MAINTSCRIPT.tmp; \
251             sed -n '/^#INCLUDE_SHELL_LIB#$$/,$$p' <$$FILE \
252               | sed -e '/^#INCLUDE_SHELL_LIB#$$/d' >>$$MAINTSCRIPT.tmp; \
253             sed -e 's/@SOURCE_VERSION@/$(SOURCE_VERSION)/' \
254                 -e 's/@OFFICIAL_BUILD@/$(OFFICIAL_BUILD)/' \
255                 -e 's/@DEFAULT_DCRESOLUTIONS@/$(DEFAULT_DCRESOLUTIONS)/' \
256               <$$MAINTSCRIPT.tmp >$$MAINTSCRIPT; \
257             rm $$MAINTSCRIPT.tmp; \
258           fi; \
259         done
260         # Validate syntax of generated shell scripts.
261         #sh debian/scripts/validate-posix-sh debian/*.config \
262         #                                    debian/*.postinst \
263         #                                    debian/*.postrm \
264         #                                    debian/*.preinst \
265         #                                    debian/*.prerm
266         >$@
267
268 # Generate the shlibs.local file.
269 debian/shlibs.local:
270         cat debian/*.shlibs >$@
271
272 SERVERMINVERS = $(shell cat /usr/share/xserver-xorg/serverminver 2>/dev/null)
273 VIDEOABI = $(shell cat /usr/share/xserver-xorg/videoabiver 2>/dev/null)
274 INPUTABI = $(shell cat /usr/share/xserver-xorg/inputabiver 2>/dev/null)
275 SERVER_DEPENDS = xserver-xorg-core (>= $(SERVERMINVERS))
276 VIDDRIVER_PROVIDES = xserver-xorg-video-$(VIDEOABI)
277 INPDRIVER_PROVIDES = xserver-xorg-input-$(INPUTABI)
278 ifeq ($(PACKAGE),)
279 PACKAGE=$(shell awk '/^Package:/ { print $$2; exit }' < debian/control)
280 endif
281
282 .PHONY: serverabi
283 serverabi: install
284 ifeq ($(SERVERMINVERS),)
285         @echo error: xserver-xorg-dev needs to be installed
286         @exit 1
287 else
288         echo "xserver:Depends=$(SERVER_DEPENDS)" >> debian/$(PACKAGE).substvars
289         echo "xviddriver:Provides=$(VIDDRIVER_PROVIDES)" >> debian/$(PACKAGE).substvars
290         echo "xinpdriver:Provides=$(INPDRIVER_PROVIDES)" >> debian/$(PACKAGE).substvars
291 endif
292
293 # vim:set noet ai sts=8 sw=8 tw=0: