summaryrefslogtreecommitdiff
path: root/install/debian/rules
blob: db67d59273c4a18be85154cb825282c2da6d0511 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#!/usr/bin/make -f
# debian/rules for Free Pascal

DEB_PACKAGE_NAME = fpc
DEB_DH_BUILDDEB_ARGS := -- -Z bzip2
export DH_ALWAYS_EXCLUDE := COPYING:LICENSE
export LANG:=C

# Documentation type to use pdf/html
ifeq (${DEBDOCTYPE},)
DOCTYPE=html
# HTML Converter l2h/4ht/hevea or html for (default)
CONVERTER=hevea
else
DOCTYPE=${DEBDOCTYPE}
CONVERTER=${DOCTYPE}
endif
# Undefine FPC if it was set
unexport FPC

# Detect name of new compiler, take care that debian uses amd64 instead of x86_64
CPU_SOURCE := $(subst amd64,x86_64,$(shell dpkg-architecture -qDEB_BUILD_ARCH_CPU))
CPU_TARGET := $(subst amd64,x86_64,$(shell dpkg-architecture -qDEB_HOST_ARCH_CPU))

ifeq ($(CPU_TARGET),m68k)
PPSUF=68k
endif
ifeq ($(CPU_TARGET),i386)
PPSUF=386
endif
ifeq ($(CPU_TARGET),x86_64)
PPSUF=x64
endif
ifeq ($(CPU_TARGET),powerpc)
PPSUF=ppc
endif
ifeq ($(CPU_TARGET),alpha)
PPSUF=axp
endif
ifeq ($(CPU_TARGET),arm)
PPSUF=arm
endif
ifeq ($(CPU_TARGET),sparc)
PPSUF=sparc
endif

ifneq ($(CPU_SOURCE),$(CPU_TARGET))
PPPRE=ppcross
else
PPPRE=ppc
endif

PPNEW=$(PPPRE)$(PPSUF)

FPCTARGET=$(CPU_TARGET)-linux
# Get version information from changelog file
DEB_VERSION:=$(shell dpkg-parsechangelog | grep '^Version:' | cut -f 2 -d ' ')
DEB_UPSTREAM_VERSION:=$(shell echo $(DEB_VERSION) | cut -f 1 -d -)
DEB_UPSTREAM_MAIN_VERSION:=$(shell echo ${DEB_UPSTREAM_VERSION} | sed -e 's/^\([0-9\.]*\).*/\1/')
DEB_BUILD=$(lastword $(subst -, ,${DEB_VERSION}))
ifndef PACKAGESUFFIX
export PACKAGESUFFIX=-${DEB_UPSTREAM_MAIN_VERSION}
endif
# Get directories
BUILD_DIR:=$(shell pwd)
INSTALL_DIR=${BUILD_DIR}/debian/tmp
BIN_DIR=${INSTALL_DIR}/usr/bin
LIB_DIR=${INSTALL_DIR}/usr/lib/${DEB_PACKAGE_NAME}/${DEB_UPSTREAM_MAIN_VERSION}
DOC_DIR=${INSTALL_DIR}/usr/share/doc
SRC_DIR=${INSTALL_DIR}/usr/share/fpcsrc/${DEB_UPSTREAM_MAIN_VERSION}
EXAMPLE_TEMP=${INSTALL_DIR}/usr/share/doc/fpc-${DEB_UPSTREAM_MAIN_VERSION}
STY_DIR=${INSTALL_DIR}/usr/share/texmf/tex/latex/fpc-${DEB_UPSTREAM_MAIN_VERSION}
# Get utils
ifndef MKDIR
MKDIR=mkdir -p
endif
ifndef CP
CP=cp -Rfpl
endif
ifndef MV
MV=mv
endif
RM:=rm -rf
# Get fpcmake from path if none is specified.
ifndef FPCMAKE
FPCMAKE=fpcmake
endif
# Undefine FPCDIR if it was set
unexport FPCDIR
NEWPP=$(BUILD_DIR)/fpcsrc/compiler/$(PPNEW)
NEWFPDOC=$(BUILD_DIR)/fpcsrc/utils/fpdoc/fpdoc
# Set default compilation options
BUILDOPTS=PP=$(NEWPP)
ifdef CROSSOPT
BUILDOPTS+= CROSSOPT=${CROSSOPT}
endif
INSTALLOPTS=INSTALL_PREFIX=$(INSTALL_DIR)/usr PP=$(NEWPP)

export GDBLIBDIR=/usr/lib

#specify arm variant explicitly so we can use a starting
#compiler from a different arm variant (for bootstrapping)
ifeq ($(CPU_TARGET),arm)
  DEBIANARCH := $(shell dpkg-architecture -qDEB_HOST_ARCH)
  ifeq ($(DEBIANARCH),arm)
    CYCLEOPTS := OPT='-dFPC_OARM'
  else
    CYCLEOPTS := OPT='-dFPC_$(DEBIANARCH)'
  endif
else
  CYCLEOPTS=
endif

#export DH_VERBOSE=1

###################
# Clean
#

clean: configure clean-patched
	${RM} build-arch-stamp install-arch-stamp arrange-arch-stamp configure-stamp
	${RM} install-man-stamp
	${RM} build-doc-stamp install-doc-stamp
	${RM} build-indep-stamp install-indep-stamp
	${RM} install-source-stamp
	${RM} debian/*.install
	${RM} debian/*.config
	${RM} debian/*.doc-base
	${RM} debian/*.links
	${RM} debian/*.manpages
	${RM} debian/*.preinst
	${RM} debian/*.prerm
	${RM} debian/*.templates
	${RM} debian/README*.Debian
	${RM} debian/copyright
	${RM} debian/fpc-depends
	${RM} debian-files-stamp
	${RM} debian/files debian/docs debian/dirs debian/*.files debian/*.docs debian/*.examples debian/*.postinst debian/*.postrm
	${RM} debian/fpc-depends-${DEB_UPSTREAM_MAIN_VERSION}.1
	# Remove auto-generated version file.
	${RM} fpcsrc/compiler/version.inc
	#remove some stuff that seems to get left behind by the upstream build
	${RM} fpcsrc/compiler/utils/msg2inc
	${RM} fpcdocs/fpdoc.haux
	${RM} fpcdocs/prog.haux
	${RM} fpcdocs/ref.haux
	${RM} fpcdocs/ref.hind
	${RM} fpcdocs/user.haux
	dh_clean

clean-patched:
	@echo "--- Cleaning"
	dh_testdir
	dh_testroot
	$(MAKE) -C fpcsrc compiler_distclean
	$(MAKE) -C fpcsrc rtl_distclean
	$(MAKE) -C fpcsrc packages_distclean
	$(MAKE) -C fpcsrc ide_distclean
	$(MAKE) -C fpcsrc utils_distclean
	$(MAKE) -C fpcdocs clean
	find -regex '.*\.\(a\|or?\|so\.*\|ppu\)' -delete
	dh_prep

###################
# Debian files
#

debian-files: debian-files-stamp
debian-files-stamp:
	@echo "--- Creating/fixing *.install files"
	/bin/bash debian/fixdeb debian $(FPCTARGET) $(PPNEW)
	touch debian-files-stamp

###################
# Arch packages
#

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Remove auto-generated version file.
	${RM} fpcsrc/compiler/version.inc
	# Add version.inc:
	echo \'$(DEB_VERSION)\' > fpcsrc/compiler/version.inc
	touch configure-stamp

build-arch: debian-files configure build-arch-stamp
build-arch-stamp:
	@echo "--- Building"
	dh_testdir
	# First make a new Compiler using a make cycle
	$(MAKE) -C fpcsrc compiler_cycle $(CYCLEOPTS)
	# Then build RTL using new compiler
	$(MAKE) -C fpcsrc rtl_clean rtl_smart $(BUILDOPTS)
	# Finally build packages and tools using new compiler and new RTL
	$(MAKE) -C fpcsrc packages_smart $(BUILDOPTS)
	$(MAKE) -C fpcsrc ide_all $(BUILDOPTS)
	$(MAKE) -C fpcsrc utils_all $(BUILDOPTS)
	touch build-arch-stamp

install-arch: build-arch install-arch-stamp
install-arch-stamp:
	@echo "--- Installing"
	dh_testdir
	dh_testroot
	dh_installdirs
	# create all necessary directories
	${MKDIR} ${BIN_DIR}
	${MKDIR} ${LIB_DIR}
	${MKDIR} ${STY_DIR}
	# Specify the compiler to use so installing will use the correct versioned dir
	$(MAKE) -C fpcsrc compiler_distinstall $(INSTALLOPTS)
	$(MAKE) -C fpcsrc rtl_distinstall $(INSTALLOPTS)
	$(MAKE) -C fpcsrc packages_distinstall $(INSTALLOPTS)
	$(MAKE) -C fpcsrc ide_distinstall $(INSTALLOPTS) INSTALL_DOCDIR=$(DOC_DIR)/fp-ide/${DEB_UPSTREAM_MAIN_VERSION}
	$(MAKE) -C fpcsrc utils_distinstall $(INSTALLOPTS)
	${MV} -t ${LIB_DIR} ${INSTALL_DIR}/usr/lib/fpc/lexyacc
	${CP} -t  ${BIN_DIR} debian/fpc-depends
	# Copy examples to the correct doc dir
	/bin/bash debian/moveexamples ${EXAMPLE_TEMP} ${DOC_DIR} ${DEB_UPSTREAM_MAIN_VERSION}
	# Rename executables
	for f in  ${BIN_DIR}/* ; do ${MV} $$f $${f}-${DEB_UPSTREAM_MAIN_VERSION} ; done
	# Install RTL demos
	$(MAKE) -C demo sourceinstall $(INSTALLOPTS) INSTALL_SOURCEDIR=$(DOC_DIR)/fp-compiler/${DEB_UPSTREAM_MAIN_VERSION}
	# Install whatsnew and readme
	$(MAKE) -C install/doc installdoc $(INSTALLOPTS) INSTALL_DOCDIR=$(DOC_DIR)/fp-compiler/${DEB_UPSTREAM_MAIN_VERSION}
	# Install fpdoc latex styles
	${CP} -t ${STY_DIR} \
		${BUILD_DIR}/fpcdocs/*.sty
	# Install lintian override files
	set -x -e ; cd debian/overrides ; for PACKAGE in * ; do \
	  if [ -d ../$${PACKAGE}${PACKAGESUFFIX} ] ; \
	  then \
	  	${MKDIR} ../$${PACKAGE}${PACKAGESUFFIX}/usr/share/lintian/overrides ; \
	    sed -e "s/$${PACKAGE}/&${PACKAGESUFFIX}/g" $${PACKAGE} > ../$${PACKAGE}${PACKAGESUFFIX}/usr/share/lintian/overrides/$${PACKAGE}${PACKAGESUFFIX} ; \
	  fi ; \
	done
ifeq (${DEB_BUILD},0)
	# We are building upstream debs, install override files for build = 0
	set -x -e ; cd debian ; for PACKAGE in `sed -n -e 's/Package: \(.*\)/\1/p' control` ; do \
	  if [ -d $${PACKAGE} ] ; \
	  then \
	    ${MKDIR} $${PACKAGE}/usr/share/lintian/overrides ; \
	    echo "$${PACKAGE}: debian-revision-should-not-be-zero" >> $${PACKAGE}/usr/share/lintian/overrides/$${PACKAGE} ; \
	  fi ; \
	done
endif
	find ${INSTALL_DIR} -empty -delete
	touch install-arch-stamp

arrange-arch: install-arch arrange-arch-stamp install-man
arrange-arch-stamp:
	dh_testdir
	dh_testroot
	dh_install -s --sourcedir=debian/tmp --list-missing
	touch arrange-arch-stamp

build-indep:
install-indep:
	touch install-indep-stamp

install-man: install-man-stamp
install-man-stamp:
	# Install man pages
	$(MAKE) -C install/man installman $(INSTALLOPTS)
	for s in ${INSTALL_DIR}/usr/man/man[1-9] ; do cd $${s} && ( gzip -d *.gz || true ) && for f in *.[1-9] ; do ${MV} $${f} $${f%%.*}-${DEB_UPSTREAM_MAIN_VERSION}."$${f#*.}" ; done ; done || true
	pod2man -c 'Free pascal for Debian GNU/Linux' debian/fpc-depends > debian/fpc-depends-${DEB_UPSTREAM_MAIN_VERSION}.1
	dh_installman -s
	${RM} ${INSTALL_DIR}/usr/man
	touch install-man-stamp

###################
# Documentation
#

build-doc: debian-files build-doc-stamp
build-doc-stamp:
	@echo "--- Building Documentation"
	dh_testdir
	${MKDIR} fpcsrc/compiler/utils/units/${FPCTARGET}
	$(MAKE) -C fpcdocs $(CONVERTER)
	touch build-doc-stamp

install-doc: build-doc install-doc-stamp
install-doc-stamp:
	@echo "--- Installing Documentation"
	dh_testdir
	dh_testroot
	${MAKE} -C fpcdocs ${DOCTYPE}install INSTALL_PREFIX=${INSTALL_DIR}/usr INSTALL_DOCDIR=${DOC_DIR}/fp-docs/${DEB_UPSTREAM_MAIN_VERSION}
	touch install-doc-stamp

###################
# Source
#

install-source: install-source-stamp
install-source-stamp: 
	@echo "--- Cleaning the tree and copying the source code"
	dh_testdir
	dh_testroot
	${MKDIR} ${SRC_DIR}
	${CP} -t ${SRC_DIR} \
	$(BUILD_DIR)/fpcsrc/compiler \
	$(BUILD_DIR)/fpcsrc/packages \
	$(BUILD_DIR)/fpcsrc/rtl
	touch install-source-stamp

###################
# Generic
#

build: build-arch build-indep
install: install-arch install-indep
binary: binary-arch binary-indep


###################
# Deb building
#

binary-indep: clean-patched build-doc install-doc install-source debian-files
	@echo "--- Building: arch-indep packages"
	dh_testdir
	dh_testroot
	dh_installdocs -i -X.in
	dh_installchangelogs -i
	dh_install -i --sourcedir=debian/tmp --list-missing
	find debian/fpc-source${PACKAGESUFFIX}/usr/share/fpcsrc/ -type f \
	  -not -regex '.*\.\(fpc\|inc\|pas\|pp\)' -delete
	find debian/fpc-source${PACKAGESUFFIX}/usr/share/fpcsrc/ -type d \
	  -empty -delete
	# Install lintian override files
	set -x -e ; cd debian/overrides ; for PACKAGE in * ; do \
	  if [ -d ../$${PACKAGE}${PACKAGESUFFIX} ] ; \
	  then \
	  	${MKDIR} ../$${PACKAGE}${PACKAGESUFFIX}/usr/share/lintian/overrides ; \
	    sed -e "s/$${PACKAGE}/&${PACKAGESUFFIX}/g" $${PACKAGE} > ../$${PACKAGE}${PACKAGESUFFIX}/usr/share/lintian/overrides/$${PACKAGE}${PACKAGESUFFIX} ; \
	  fi ; \
	done
ifeq (${DEB_BUILD},0)
	# We are building upstream debs, install override files for build = 0
	set -x -e ; cd debian ; for PACKAGE in `sed -n -e 's/Package: \(.*\)/\1/p' control` ; do \
	  if [ -d $${PACKAGE} ] ; \
	  then \
	    ${MKDIR} $${PACKAGE}/usr/share/lintian/overrides ; \
	    echo "$${PACKAGE}: debian-revision-should-not-be-zero" >> $${PACKAGE}/usr/share/lintian/overrides/$${PACKAGE} ; \
	  fi ; \
	done
endif
	dh_compress -i -X.pdf
	dh_fixperms -i
	dh_installdebconf -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i $(DEB_DH_BUILDDEB_ARGS)

binary-arch: arrange-arch
	@echo "--- Building: arch packages"
	dh_testdir
	dh_testroot
	dh_link
	dh_installdocs -a -X.in
	dh_installchangelogs -a
	dh_installexamples -a
	dh_strip -s
	dh_compress -a
	dh_fixperms -a
	dh_installdebconf -a
	dh_installdeb -a
	dh_shlibdeps -s
	dh_gencontrol -s
	dh_md5sums -s
	dh_builddeb -s $(DEB_DH_BUILDDEB_ARGS)

.PHONY: build clean binary binary-arch \
	binary-indep debian-files build-arch \
	install install-indep install-arch \
	configure

get-orig-source:
	-uscan --upstream-version=0 --rename