b871b3bf6471111a835545f635c91595f897d6d4
[framework/uifw/xorg/lib/libdri2.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 strings "woody" or "sarge" 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\)//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 # $(SOURCE_DIR) houses one or more source trees.
73 SOURCE_DIR:=build-tree
74
75 # $(SOURCE_TREE) is the location of the source tree to be compiled.  If there
76 # is more than one, others are found using this name plus a suffix to indicate
77 # the purpose of the additional tree (e.g., $(SOURCE_TREE)-custom).  The
78 # "setup" target is responsible for creating such trees.
79 #SOURCE_TREE:=$(SOURCE_DIR)/xc
80 #FIXME We need to define this in our debian/rules file
81
82 # $(DEBTREEDIR) is where all install rules are told (via $(DESTDIR)) to place
83 # their files.
84 DEBTREEDIR:=$(CURDIR)/debian/tmp
85
86 # All "important" targets have four lines:
87 #   1) A target name that is invoked by a package-building tool or the user.
88 #      This consists of a dependency on a "$(STAMP_DIR)/"-prefixed counterpart.
89 #   2) A line delcaring 1) as a phony target (".PHONY:").
90 #   3) A "$(STAMP_DIR)/"-prefixed target which does the actual work, and may
91 #   depend on other targets.
92 #   4) A line declaring 3) as a member of the $(stampdir_targets) variable; the
93 #   "$(STAMP_DIR)/" prefix is omitted.
94 #
95 # This indirection is needed so that the "stamp" files that signify when a rule
96 # is done can be located in a separate "stampdir".  Recall that make has no way
97 # to know when a goal has been met for a phony target (like "build" or
98 # "install").
99 #
100 # At the end of each "$(STAMP_DIR)/" target, be sure to run the command ">$@"
101 # so that the target will not be run again.  Removing the file will make Make
102 # run the target over.
103
104 # All phony targets should be declared as dependencies of .PHONY, even if they
105 # do not have "($STAMP_DIR)/"-prefixed counterparts.
106
107 # Define a harmless default rule to keep things from going nuts by accident.
108 .PHONY: default
109 default:
110
111 # Set up the $(STAMP_DIR) directory.
112 .PHONY: stampdir
113 stampdir_targets+=stampdir
114 stampdir: $(STAMP_DIR)/stampdir
115 $(STAMP_DIR)/stampdir:
116         mkdir $(STAMP_DIR)
117         >$@
118
119 # Set up the package build directory as quilt expects to find it.
120 .PHONY: prepare
121 stampdir_targets+=prepare
122 prepare: $(STAMP_DIR)/genscripts $(STAMP_DIR)/prepare $(STAMP_DIR)/log
123 $(STAMP_DIR)/prepare: $(STAMP_DIR)/stampdir
124         if [ ! -e $(STAMP_DIR)/log ]; then \
125                 mkdir $(STAMP_DIR)/log; \
126         fi; \
127         >$@
128
129 # Apply all patches to the upstream source.
130 .PHONY: patch
131 stampdir_targets+=patch
132 patch: $(STAMP_DIR)/patch
133 $(STAMP_DIR)/patch: $(STAMP_DIR)/prepare
134         if ! [ `which quilt` ]; then \
135                 echo "Couldn't find quilt. Please install it or add it to the build-depends for this package."; \
136                 exit 1; \
137         fi; \
138         if $(QUILT) next >/dev/null 2>&1; then \
139           echo -n "Applying patches..."; \
140           if $(QUILT) push -a -v >$(STAMP_DIR)/log/patch 2>&1; then \
141             cat $(STAMP_DIR)/log/patch; \
142             echo "successful."; \
143           else \
144             cat $(STAMP_DIR)/log/patch; \
145             echo "failed! (check $(STAMP_DIR)/log/patch for details)"; \
146             exit 1; \
147           fi; \
148         else \
149           echo "No patches to apply"; \
150         fi; \
151         >$@
152
153 # Revert all patches to the upstream source.
154 .PHONY: unpatch
155 unpatch: $(STAMP_DIR)/prepare
156         rm -f $(STAMP_DIR)/patch
157         @echo -n "Unapplying patches..."; \
158         if $(QUILT) applied >/dev/null 2>/dev/null; then \
159           if $(QUILT) pop -a -v >$(STAMP_DIR)/log/unpatch 2>&1; then \
160             cat $(STAMP_DIR)/log/unpatch; \
161             echo "successful."; \
162           else \
163             cat $(STAMP_DIR)/log/unpatch; \
164             echo "failed! (check $(STAMP_DIR)/log/unpatch for details)"; \
165             exit 1; \
166           fi; \
167         else \
168           echo "nothing to do."; \
169         fi
170
171 # Clean the generated maintainer scripts.
172 .PHONY: cleanscripts
173 cleanscripts:
174         rm -f $(STAMP_DIR)/genscripts
175         rm -f debian/*.config \
176               debian/*.postinst \
177               debian/*.postrm \
178               debian/*.preinst \
179               debian/*.prerm
180
181 # Clean the package build tree.
182 .PHONY: xsfclean
183 xsfclean: cleanscripts unpatch
184         dh_testdir
185         rm -rf .pc
186         rm -rf $(STAMP_DIR) $(SOURCE_DIR)
187         rm -rf imports
188         dh_clean debian/shlibs.local \
189                  debian/po/pothead
190
191 # Generate the debconf templates POT file header.
192 debian/po/pothead: debian/po/pothead.in
193         sed -e 's/SOURCE_VERSION/$(SOURCE_VERSION)/' \
194           -e 's/DATE/$(shell date "+%F %X%z"/)' <$< >$@
195
196 # Update POT and PO files.
197 .PHONY: updatepo
198 updatepo: debian/po/pothead
199         debian/scripts/debconf-updatepo --pot-header=pothead --verbose
200
201 # Remove files from the upstream source tree that we don't need, or which have
202 # licensing problems.  It must be run before creating the .orig.tar.gz.
203 #
204 # Note: This rule is for Debian package maintainers' convenience, and is not
205 # needed for conventional build scenarios.
206 .PHONY: prune-upstream-tree
207 prune-upstream-tree:
208         # Ensure we're in the correct directory.
209         dh_testdir
210         grep -rvh '^#' debian/prune/ | xargs --no-run-if-empty rm -rf
211
212 # Verify that there are no offsets or fuzz in the patches we apply.
213 #
214 # Note: This rule is for Debian package maintainers' convenience, and is not
215 # needed for conventional build scenarios.
216 .PHONY: patch-audit
217 patch-audit: prepare unpatch
218         @echo -n "Auditing patches..."; \
219         >$(STAMP_DIR)/log/patch; \
220         FUZZY=; \
221         while [ -n "$$($(QUILT) next)" ]; do \
222           RESULT=$$($(QUILT) push -v | tee -a $(STAMP_DIR)/log/patch | grep ^Hunk | sed 's/^Hunk.*\(succeeded\|FAILED\).*/\1/');\
223           case "$$RESULT" in \
224             succeeded) \
225               echo "fuzzy patch: $$($(QUILT) top)" \
226                 | tee -a $(STAMP_DIR)/log/$$($(QUILT) top); \
227               FUZZY=yes; \
228               ;; \
229             FAILED) \
230               echo "broken patch: $$($(QUILT) next)" \
231                 | tee -a $(STAMP_DIR)/log/$$($(QUILT) next); \
232               exit 1; \
233               ;; \
234           esac; \
235         done; \
236         if [ -n "$$FUZZY" ]; then \
237           echo "there were fuzzy patches; please fix."; \
238           exit 1; \
239         else \
240           echo "done."; \
241         fi
242
243 # Generate the maintainer scripts.
244 .PHONY: genscripts
245 stampdir_targets+=genscripts
246 genscripts: $(STAMP_DIR)/genscripts
247 $(STAMP_DIR)/genscripts: $(STAMP_DIR)/stampdir
248         for FILE in debian/*.config.in \
249                     debian/*.postinst.in \
250                     debian/*.postrm.in \
251                     debian/*.preinst.in \
252                     debian/*.prerm.in; do \
253           if [ -e "$$FILE" ]; then \
254             MAINTSCRIPT=$$(echo $$FILE | sed 's/.in$$//'); \
255             sed -n '1,/^#INCLUDE_SHELL_LIB#$$/p' <$$FILE \
256               | sed -e '/^#INCLUDE_SHELL_LIB#$$/d' >$$MAINTSCRIPT.tmp; \
257             cat debian/xsfbs/xsfbs.sh >>$$MAINTSCRIPT.tmp; \
258             sed -n '/^#INCLUDE_SHELL_LIB#$$/,$$p' <$$FILE \
259               | sed -e '/^#INCLUDE_SHELL_LIB#$$/d' >>$$MAINTSCRIPT.tmp; \
260             sed -e 's/@SOURCE_VERSION@/$(SOURCE_VERSION)/' \
261                 -e 's/@OFFICIAL_BUILD@/$(OFFICIAL_BUILD)/' \
262                 -e 's/@DEFAULT_DCRESOLUTIONS@/$(DEFAULT_DCRESOLUTIONS)/' \
263               <$$MAINTSCRIPT.tmp >$$MAINTSCRIPT; \
264             rm $$MAINTSCRIPT.tmp; \
265           fi; \
266         done
267         # Validate syntax of generated shell scripts.
268         #sh debian/scripts/validate-posix-sh debian/*.config \
269         #                                    debian/*.postinst \
270         #                                    debian/*.postrm \
271         #                                    debian/*.preinst \
272         #                                    debian/*.prerm
273         >$@
274
275 # Generate the shlibs.local file.
276 debian/shlibs.local:
277         cat debian/*.shlibs >$@
278
279 SERVERMINVERS = $(shell cat /usr/share/xserver-xorg/serverminver 2>/dev/null)
280 VIDEOABI = $(shell cat /usr/share/xserver-xorg/videoabiver 2>/dev/null)
281 INPUTABI = $(shell cat /usr/share/xserver-xorg/inputabiver 2>/dev/null)
282 SERVER_DEPENDS = xserver-xorg-core (>= $(SERVERMINVERS))
283 VIDDRIVER_PROVIDES = xserver-xorg-video-$(VIDEOABI)
284 INPDRIVER_PROVIDES = xserver-xorg-input-$(INPUTABI)
285 ifeq ($(PACKAGE),)
286 PACKAGE=$(shell awk '/^Package:/ { print $$2; exit }' < debian/control)
287 endif
288
289 .PHONY: serverabi
290 serverabi: install
291 ifeq ($(SERVERMINVERS),)
292         @echo error: xserver-xorg-dev needs to be installed
293         @exit 1
294 else
295         echo "xserver:Depends=$(SERVER_DEPENDS)" >> debian/$(PACKAGE).substvars
296         echo "xviddriver:Provides=$(VIDDRIVER_PROVIDES)" >> debian/$(PACKAGE).substvars
297         echo "xinpdriver:Provides=$(INPDRIVER_PROVIDES)" >> debian/$(PACKAGE).substvars
298 endif
299
300 # vim:set noet ai sts=8 sw=8 tw=0: