File: Makefile

package info (click to toggle)
cernlib 2004.11.04.dfsg-0sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 29,292 kB
  • ctags: 1,159
  • sloc: ansic: 2,285; sh: 840; makefile: 582
file content (544 lines) | stat: -rw-r--r-- 19,550 bytes parent folder | download
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
# Variables for installation directories, conforming to GNU standards
prefix		= /usr/local
exec_prefix	= $(prefix)
bindir		= $(exec_prefix)/bin
sbindir		= $(exec_prefix)/sbin
datadir		= $(prefix)/share
sysconfdir	= $(prefix)/etc
libdir		= $(exec_prefix)/lib
includedir	= $(prefix)/include
mandir		= $(prefix)/man
man1dir		= $(mandir)/man1
man8dir		= $(mandir)/man8
srcdir		= .
abssrcdir	= $(strip $(shell cd $(srcdir) && pwd))

# Other variables important to Cernlib compilation
export ARCH	      = $(strip $(shell uname -s))
export CERN	      = $(shell pwd)
export CERN_LEVEL     = $(strip $(shell \
			tar tzf $(abssrcdir)/upstream/src_Imakefile.tar.gz \
			| cut -d / -f 1))
export CERN_ROOT      = $(CERN)
export CVSCOSRC	      = $(CERN_ROOT)/src
export CERN_DOCDIR    = $(CERN_ROOT)/doc
export CERN_BINDIR    = $(CERN_ROOT)/bin
export CERN_LIBDIR    = $(CERN_ROOT)/lib
export CERN_SHLIBDIR  = $(CERN_ROOT)/shlib
export CERN_BUILDDIR  = $(CERN_ROOT)/build

export SHELL	      = /bin/sh
export PATCHDIR	      = $(abssrcdir)/debian/generic
export LIB_SONAME     = 1
export PATH	     := $(CERN_BINDIR):$(PATCHDIR)/bin:${PATH}
export INSTALL_OPTS   = -s
export CC	      ?= gcc
export DEB_BUILD_ARCH ?= $(shell $(CC) -dumpmachine | sed 's/-linux$$//')
LOCAL_DEFINES =

# make sure patches are applied in the right order:
export LANG	      = C
export LC_COLLATE     = C

# DEB_BUILD_OPTIONS support
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	export OPTIMIZED_OPTS=-O0
endif
ifneq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	export INSTALL_OPTS=
endif

# use this to build cernlib with Intel's ifort (formerly ifc) and icc compiler.
# Note that your /etc/ld.so.conf must include the location of the "libimf.so"
# file included with ifort!
ifneq (,$(findstring ifort,$(DEB_BUILD_OPTIONS)))
	export IFORT=yes
endif

# use this to build cernlib faster for debugging, omitting the spdf code
# from libpdflib804 which takes forever to compile
ifneq (,$(findstring nospdf,$(DEB_BUILD_OPTIONS)))
	export NO_SPDF=no_spdf
endif

KUIPC		= $(CERN_BINDIR)/kuipc
NEEDS_MAKEFILE	= cfortran code_motif geant321 graflib kernlib mathlib mclibs \
		  packlib patchy pawlib phtools scripts
BIN_PACKAGES	= packlib graflib pawlib # patchy doesn't compile

# Order here is important!  Packages that depend on other packages must be
# compiled later, or the linker risks picking up stuff in /usr/lib instead
# of $(CERN_SHLIBDIR).
LIB_PACKAGES	= kernlib packlib mathlib graflib code_motif mclibs phtools \
	          pawlib geant321

MCDOC		= $(datadir)/doc/montecarlo-doc
GEANTDOC	= $(datadir)/doc/geant321-doc

all: cernlib-indep cernlib-arch

cernlib-arch: stampdir/cernlib-arch-stamp
cernlib-indep: stampdir/cernlib-indep-stamp
gunzip: stampdir/gunzip-stamp
patch: stampdir/patch-stamp
install: install-indep install-arch

stampdir/cernlib-arch-stamp:
	[ -e stampdir/cernlib-arch-stamp ] || \
		$(MAKE) cernlib-libraries cernlib-programs cernlib-static \
			cernlib-mc-data cernlib-mc-docs
	mkdir -p stampdir
	touch stampdir/cernlib-arch-stamp

stampdir/cernlib-indep-stamp:
	[ -e stampdir/cernlib-indep-stamp ] || \
		$(MAKE) cernlib-geant-data cernlib-geant-docs scripts
	mkdir -p stampdir
	touch stampdir/cernlib-indep-stamp

stampdir/gunzip-stamp:
	chmod a+x $(PATCHDIR)/bin/*
	for x in $(abssrcdir)/upstream/src_*.tar.gz ; do tar xzf $$x ; done
	# get rid of the needless extra directory whose name changes yearly
	mv $(CERN)/$(CERN_LEVEL)/src $(CERN)/
	rmdir $(CERN)/$(CERN_LEVEL)
	mkdir -p stampdir
	touch stampdir/gunzip-stamp

stampdir/patch-stamp: stampdir/gunzip-stamp
	# change all source code files needing cfortran.h to
	# #include <cfortran.h>, and remove it from the source tree since
	# we want to use only the canonical copy in
	# debian/generic/patches/additions
	set -e ; \
	find $(CVSCOSRC)/ -name CVS | xargs rm -rf ; \
	find $(CVSCOSRC)/ -name cfortran.h | xargs rm -f; \
	for file in `find $(CVSCOSRC) -name '*.c' -o -name '*.h'` ; do \
		sed -e 's,["<].*cfortran\.h[">],<cfortran\.h>,g' \
			$$file > $${file}.temp ; \
		mv -f $${file}.temp $$file ; \
	done
	#
	# patch header files to have ifndefs and #include <cfortran.h>
	set -e ; \
	for header in $(CVSCOSRC)/cfortran/*.h ; do \
		$(PATCHDIR)/bin/fixheader $$header ; \
	done
	#
	# set file locations in patches from the make variables
	# and apply the patches
	set -e ; \
	for patch in $(shell ls -1 $(PATCHDIR)/patches/[0-9]*) ; do \
		sed -e 's,PREFIX,$(prefix),g' -e 's,DATADIR,$(datadir),g' \
		$$patch | patch -N -p0 ; \
	done ; \
	awk '{ system("mkdir -p $(CVSCOSRC)/" $$1) }' \
		$(PATCHDIR)/patches/mkdirlist ; \
	awk '{ system("mv -f $(CVSCOSRC)/" $$1 " $(CVSCOSRC)/" $$2) }' \
		$(PATCHDIR)/patches/movelist ; \
	awk '{ system("cp -Rf $(CVSCOSRC)/" $$1 " $(CVSCOSRC)/" $$2) }' \
		$(PATCHDIR)/patches/copylist ; \
	for file in $(shell ls -1 $(PATCHDIR)/patches/additions) ; do \
		cp -Rpf $(PATCHDIR)/patches/additions/$$file \
			$(CVSCOSRC)/`echo $$file | tr '+' '/'` ; \
	done ; \
	if [ -n "$(IFORT)" ] ; then \
		patch -N -p0 < $(PATCHDIR)/patches/ifort.patch ; \
	fi ; \
	for conffile in linux MacOSX ; do \
		CONFFILE="$(CVSCOSRC)/config/$$conffile.cf" ; \
		mv "$$CONFFILE" "$${CONFFILE}.tmp" ; \
		if [ -n "$(OPTIMIZED_OPTS)" ] ; then \
			echo '#define OptimizationLevel $(OPTIMIZED_OPTS)' \
				> "$$CONFFILE" ; \
		fi ; \
		echo '#define InstPgmFlags $(INSTALL_OPTS)' >> "$$CONFFILE" ; \
		echo '#define CernlibLocalDefines $(LOCAL_DEFINES)' \
			>> "$$CONFFILE" ; \
		if [ -n "$(IFORT)" ] ; then \
			echo '#define HasIntelifc YES' >> "$$CONFFILE" ; \
		fi ; \
		cat "$${CONFFILE}.tmp" >> "$$CONFFILE" ; \
		rm -f "$${CONFFILE}.tmp" ; \
	done ; \
	rm -f options ; \
	if [ "$(NO_SPDF)" ] ; then \
		sed 's/spdf//g' $(CVSCOSRC)/mclibs/pdf/Imakefile > \
			$(CVSCOSRC)/mclibs/pdf/Imakefile.tmp ; \
		mv -f $(CVSCOSRC)/mclibs/pdf/Imakefile.tmp \
			$(CVSCOSRC)/mclibs/pdf/Imakefile ; \
	fi ; \
	mkdir -p stampdir ; \
	touch stampdir/patch-stamp

buildtree:
	mkdir -p $(CERN_BUILDDIR)/log
	cd $(CERN_BUILDDIR) && $(CVSCOSRC)/config/imake_boot

$(KUIPC): buildtree patch
	cd $(CERN_BUILDDIR) && $(MAKE) MAKEOVERRIDES= bin/kuipc

# we need to do this rather than using the scripts Makefile,
# which (stupidly) calls install -s [strip] on shell scripts
scripts: patch
	set -e ; \
	mkdir -p $(CERN_BINDIR) ; \
	for script in gxint paw ; do \
		install -p -m 0755 $(CVSCOSRC)/scripts/$$script $(CERN_BINDIR);\
	done
	# also, we want to use a completely rewritten cernlib script
	sed -e 's,LIBPREFIX,$(libdir),g' -e 's,PREFIX,$(prefix),g' \
		$(PATCHDIR)/bin/cernlib > $(CERN_BINDIR)/cernlib && \
		chmod a+x $(CERN_BINDIR)/cernlib
	# and add a paw-demos script
	sed -e 's,DATADIR,$(datadir),g' $(PATCHDIR)/bin/paw-demos \
		> $(CERN_BINDIR)/paw-demos && \
		chmod a+x $(CERN_BINDIR)/paw-demos

# build libraries (currently I can get shared libraries to compile only
# on Linux)
cernlib-libraries: patch $(KUIPC) scripts
	set -e ; \
	for package in $(NEEDS_MAKEFILE) ; do \
		cd $(CERN_BUILDDIR)/ && $(MAKE) MAKEOVERRIDES= \
			$$package/Makefile ; \
	done ; \
	for package in $(LIB_PACKAGES) ; do \
		cd $(CERN_BUILDDIR)/$$package && $(MAKE) MAKEOVERRIDES= \
			install.lib ; \
		if [ "$(ARCH)" = "Linux" ] ; then \
		cd $(CERN_BUILDDIR)/$$package && $(MAKE) MAKEOVERRIDES= \
			install.shlib ; \
		fi ; \
	done ; \
	for file in $(CERN_LIBDIR)/lib*-shift.a ; do \
		if [ -L $$file ] ; then rm -f $$file ; fi ; \
	done

# build programs
cernlib-programs:
	set -e ; \
	rm -f $(CVSCOSRC)/pawlib/paw/programs/comis && \
	ln -sf ../../comis/comis $(CVSCOSRC)/pawlib/paw/programs/comis ; \
	for package in $(BIN_PACKAGES) ; do \
		cd $(CERN_BUILDDIR)/$$package && $(MAKE) MAKEOVERRIDES= \
			install.bin ; \
	done

# now build statically linked programs for *-static packages.
# these will be linked dynamically against system libraries, but
# statically against cernlib libraries.
# This is not necessary on non-Linux archs where I can't yet compile shlibs
# so everything is statically linked anyway.
cernlib-static:
	set -e ; \
	[ -d $(CERN_SHLIBDIR) ] || exit 0 ; \
	g77 $(CERN_BUILDDIR)/pawlib/paw/programs/0pamain.o \
		$(CERN_BUILDDIR)/code_motif/archive/kuwhag.o \
		$(CERN_LIBDIR)/libpawlib.a `cernlib graflib mathlib` -Wl,-E \
		-o $(CERN_BINDIR)/pawX11.static ; \
	g77 $(CERN_BUILDDIR)/pawlib/paw/programs/0pamainm.o \
		`cernlib -G Motif pawlib` -Wl,-E -o $(CERN_BINDIR)/paw++.static

# these targets build only the arch-independent data files
cernlib-geant-data: patch buildtree
	$(MAKE) -C $(CERN_BUILDDIR) MAKEOVERRIDES= geant321/Makefile
	$(MAKE) -C $(CERN_BUILDDIR)/geant321 MAKEOVERRIDES= gxint/Makefile
	$(MAKE) -C $(CERN_BUILDDIR)/geant321/gxint \
		MAKEOVERRIDES= $(CERN_LIBDIR)/gxint321.f

cernlib-mc-data: patch buildtree
	$(MAKE) -C $(CERN_BUILDDIR) MAKEOVERRIDES= mclibs/Makefile
	$(MAKE) -C $(CERN_BUILDDIR)/mclibs MAKEOVERRIDES= \
		cojets/Makefile eurodec/Makefile
	$(MAKE) -C $(CERN_BUILDDIR)/mclibs/cojets MAKEOVERRIDES= \
		$(CERN_LIBDIR)/cojets.dat
	$(MAKE) -C $(CERN_BUILDDIR)/mclibs/eurodec MAKEOVERRIDES= \
		$(CERN_LIBDIR)/eurodec.dat
	if [ "$(DEB_BUILD_ARCH)" != m68k ] ; then \
	    $(MAKE) -C $(CERN_BUILDDIR)/mclibs MAKEOVERRIDES= isajet/Makefile ;\
	    $(MAKE) -C $(CERN_BUILDDIR)/mclibs/isajet MAKEOVERRIDES= \
	    	$(CERN_LIBDIR)/isajet.dat ; \
	fi

# now build some documentation that isn't created automatically.
# Unfortunately, the cernlib authors weren't thoughtful enough to
# give any indication of the order in which chapters go from their
# filenames.
cernlib-mc-docs: patch
	mkdir -p $(CERN_DOCDIR)
	#
	# cojets
	set -e ; \
	cd $(CVSCOSRC)/mclibs/cojets/doc ; \
	cat title.doc intro.doc physics.doc usage.doc backward.doc patchy.doc \
		external.doc iocon.doc ioconfor.doc ioconinp.doc ioconout.doc \
		ioisa.doc ioisafor.doc ioisainp.doc ioisaout.doc taperead.doc \
		table.doc | sed -e '/^\*$$/d' -e '/^\* .*$$/d' > \
		$(CERN_DOCDIR)/cojets.txt
	# isajet
	set -e ; \
	cd $(CVSCOSRC)/mclibs/isajet/doc ; \
	sed '/^\*.*$$/d' ztext.doc > $(CERN_DOCDIR)/isajet-zebra.txt ; \
	sed '/^\*.*$$/d' isassdoc.doc > $(CERN_DOCDIR)/isasusy.txt ; \
	cat intro.doc physics.doc sample.doc patchy.doc main.doc \
		input.doc output.doc tape.doc decay.doc ident.doc \
		higher.doc susy.doc changes.doc > $(CERN_DOCDIR)/isajet.tex; \
	cd $(CERN_DOCDIR) ; \
	latex isajet.tex ; \
	latex isajet.tex ; \
	dvips isajet.dvi -o isajet.ps
	# eurodec
	set -e ; \
	cd $(CVSCOSRC)/mclibs/eurodec/doc ; \
	sed -e '/^\*.*$$/d' -e 's/C\.//g' eudtxt > $(CERN_DOCDIR)/eurodec.txt

# geant321
cernlib-geant-docs: patch
	set -e ; \
	mkdir -p $(CERN_DOCDIR) ; \
	rm -f $(CERN_DOCDIR)/geant321.txt; \
	cd $(CVSCOSRC)/geant321 ; \
	for x in gbase gcons gdraw ggeom ghits giopa gkine gphys gtrak ; do \
		( echo && echo -n "                                 [" && \
		  echo -n $$x | cut -b 2-5 | tr '[a-z]' '[A-Z]' |xargs echo -n\
		  && echo "]"&& echo && \
		  sed -e '/^\#.*$$/d' -e '1,/^\*-- Author/d' \
			-e '/^\*$$/d' $$x/$$x.doc ) >> \
			$(CERN_DOCDIR)/geant321.txt ; \
	done ; \
	cd doc ; \
	( echo "                              ERTRAK Documentation" && \
	  echo "                              ====================" && \
	  sed -e '/^\*/d' gedoc ) > $(CERN_DOCDIR)/ertrak.txt ; \
	mkdir -p $(CERN_DOCDIR)/gheisha ; \
	cd ghdoc ; \
	for x in `ls *.doc | sed 's/.doc$$//g'` ; do \
		sed -e '/^\*/d' -e 's/^C\*\*//g' $$x.doc > \
		$(CERN_DOCDIR)/gheisha/$$x.txt;\
	done

# target to install include files for development packages
install-includes:
	install -d -m 0755 $(includedir) $(includedir)/geant

	# install them all (patching includes, e.g. #include "ksys.h"
	# -> #include <kuip/ksys.h> )
	for dir in `cat $(PATCHDIR)/patches/includelist` ; do \
		basedir=`basename $$dir` ; \
		rm -rf $(includedir)/$$basedir ; \
		cp -Rp $(CVSCOSRC)/$$dir $(includedir) ; \
		ls -1 $(includedir)/$$basedir/* | egrep -v '\.(h|inc)$$' \
			| xargs rm -rf ; \
		for file in `ls -1 $(includedir)/$$basedir/*` ; do \
		if [ -f $$file ] ; then \
	sed -e 's,^\([ ]*#[ ]*include\)[ 	]*"\([^"/]*\)",\1 <'$$basedir/'\2>,g' \
		-e 's,^\([ ]*#[ ]*include\)[ 	]*"\([^"]*\)",\1 <\2>,g' \
		$$file > $$file.tmp ; \
	mv -f $$file.tmp $$file ; \
	fi ; \
	done ; \
	done

	# move $(includedir)/ntuple to $(includedir)/paw/ntuple
	rm -rf $(includedir)/paw/ntuple
	mv -f $(includedir)/ntuple $(includedir)/paw/
	for file in `ls -1 $(includedir)/paw/ntuple/*` ; do \
		sed -e 's,<ntuple/\([^>]*\)>,<paw/ntuple/\1>,g' $$file \
			> $$file.tmp ; \
		mv -f $$file.tmp $$file ; \
	done

	# install some symlinks, e.g. herwig$$version -> herwig
	rm -f $(includedir)/herwig && ln -sf herwig59 $(includedir)/herwig
	rm -rf $(includedir)/isajet758
	mv $(includedir)/isajet $(includedir)/isajet758
	ln -sf isajet758 $(includedir)/isajet
	rm -rf $(includedir)/pdf804
	mv $(includedir)/pdf $(includedir)/pdf804
	ln -sf pdf804 $(includedir)/pdf
	
	# install cfortran.h (if it exists; for Debian packaging we deleted
	# it earlier)
	set -e ; \
	if [ -e $(CVSCOSRC)/include/cfortran.h ] ; then \
		install -p -m 0644 $(CVSCOSRC)/include/cfortran.h \
			$(includedir)/ ; \
		install -d -m 0755 $(datadir)/doc/cfortran ; \
		install -p -m 0644 $(CVSCOSRC)/include/cfortran.doc \
			$(datadir)/doc/cfortran/ ; \
	fi	

	# install still more include files
	install -p -m 0644 $(CVSCOSRC)/cfortran/*.h $(includedir)/
	install -p -m 0644 $(CVSCOSRC)/car/*.car $(includedir)/
	rm -f $(includedir)/geanh.car && \
		ln -sf geanh321.car $(includedir)/geanh.car
	rm -f $(includedir)/geant.car && \
		ln -sf geant321.car $(includedir)/geant.car
	( cd $(includedir)/geant/ && ln -sf ../geant321 gcdes )

	# a few more needed patches
	sed 's,REAL,DOUBLE PRECISION,g' $(includedir)/isajet/hepevt.inc \
		> $(includedir)/isajet/hepevt.inc.tmp && \
	mv -f $(includedir)/isajet/hepevt.inc.tmp $(includedir)/isajet/hepevt.inc
	sed '/^#include/s,../comis/,,' $(includedir)/paw/pawsiz.inc \
		> $(includedir)/paw/pawsiz.inc.tmp && \
	mv -f $(includedir)/paw/pawsiz.inc.tmp $(includedir)/paw/pawsiz.inc
	sed '/^#include/s,tree,paw,' $(includedir)/paw/tree.h \
		> $(includedir)/paw/tree.h.tmp && \
	mv -f $(includedir)/paw/tree.h.tmp $(includedir)/paw/tree.h

# target to install files in arch-dependent packages
install-arch: install-includes
	install -d -m 0755 $(bindir) $(sbindir) $(libdir) \
		$(datadir)/montecarlo-data $(datadir)/pixmaps \
		$(sysconfdir)/X11/app-defaults $(man1dir) $(man8dir)
	
	# rename some files that conflict with the cdbackup package
	set -e ; \
	for file in backup make move serv ; do \
		[ -x $(CERN_BINDIR)/cd$$file ] && \
		mv $(CERN_BINDIR)/cd$$file $(CERN_BINDIR)/hep$$file || true ; \
	done
	
	# install binaries
	for binary in dzedit dzeX11 fatback fatmen fatnew fatsend fatsrv \
		hepbackup hepdb hepmake hepmove hepserv kuesvr kuipc kxterm \
		paw++ pawX11 zftp ; do \
		install -p -m 0755 $(CERN_BINDIR)/$$binary $(bindir)/ ; \
	done
	for binary in zserv ; do \
		install -p -m 0755 $(CERN_BINDIR)/$$binary $(sbindir)/ ; \
	done
	[ -z "`diff $(sbindir)/zserv $(CERN_BINDIR)/pawserv`" ] \
		&& ln -sf zserv $(sbindir)/pawserv \
		|| install -p $(CERN_BINDIR)/pawserv $(sbindir)/
	
	# install libraries
	install -p -m 0644 $(CERN_LIBDIR)/*.a $(libdir)/
	# we go through the following rigmarole because "install" dereferences
	# symlinks and older GNU versions of "cp" have inconsistent
	# syntax for the short form of the --no-dereference flag
	set -e ; \
	if [ -d $(CERN_SHLIBDIR) ] ; then \
	( abslibdir="`cd $(libdir)/ && pwd`" ; \
	  cd $(CERN_SHLIBDIR)/ ; \
	  for file in `ls | grep 'lib.*\..*\..*\.'` ; do \
		basename=`echo $$file | cut -f 1 -d .` ; \
		install -p -m 0644 $$file "$$abslibdir/" ; \
		for link in `ls $$basename* | grep -v 'lib.*\..*\..*\.'` ; do \
			ln -sf $$file "$$abslibdir"/$$link ; \
		done ; \
	  done ) ; \
	fi

	# install Monte Carlo data files
	install -p -m 0644 $(CERN_LIBDIR)/cojets.dat $(CERN_LIBDIR)/eurodec.dat\
		$(datadir)/montecarlo-data/
	if [ "$(DEB_BUILD_ARCH)" != m68k ] ; then \
		install -p -m 0644 $(CERN_LIBDIR)/isajet.dat \
			$(datadir)/montecarlo-data/ ; \
	fi
	
	# install KXterm app-defaults
	install -p -m 0644 $(PATCHDIR)/app-defaults/KXterm \
		$(sysconfdir)/X11/app-defaults/
	
	# install KXterm icon
	install -p -m 0644 $(PATCHDIR)/icons/kxterm*.xpm $(datadir)/pixmaps/
	
	# install man pages
	for binary in dzedit dzeX11 kuesvr kuipc kxterm paw paw++ pawX11 zftp ;\
	do \
		install -p -m 0644 $(PATCHDIR)/manpages/$$binary.1 \
			$(man1dir)/ ; \
	done
	for binary in pawserv zserv ; do \
		install -p -m 0644 $(PATCHDIR)/manpages/$$binary.8 \
			$(man8dir)/ ; \
	done

	# ... and mclibs documentation
	for dir in cojets eurodec herwig isajet pdflib ; do \
		install -d -m 0755 $(MCDOC)/$$dir ; \
	done
	install -p -m 0644 $(CERN_DOCDIR)/cojets.txt $(MCDOC)/cojets/
	install -p -m 0644 $(CERN_DOCDIR)/isa* $(MCDOC)/isajet/
	install -p -m 0644 $(CERN_DOCDIR)/eurodec.txt $(MCDOC)/eurodec/
	install -p -m 0644 $(CVSCOSRC)/mclibs/herwig/doc/herwig59 \
		$(MCDOC)/herwig/herwig59.txt
	install -p -m 0644 $(CVSCOSRC)/mclibs/pdf/dpdf/pdfdoc.doc \
		$(MCDOC)/pdflib/pdfdoc.txt

	# separate static and dynamically linked binaries
	set -e ; \
	for prog in pawX11 paw++ ; do \
		if [ -x $(CERN_BINDIR)/$$prog.static ] ; then \
			mv -f $(bindir)/$$prog $(bindir)/$$prog.dynamic ; \
			install -p $(CERN_BINDIR)/$$prog.static \
				$(bindir)/$$prog.static ; \
			ln -sf $$prog.static $(bindir)/$$prog ; \
		fi ; \
	done

# target to install files in arch-independent packages
install-indep:
	install -d -m 0755 $(bindir) $(sysconfdir)/X11/app-defaults \
		$(datadir)/geant321 $(datadir)/doc/geant321-doc $(includedir) \
		$(datadir)/geant321-data $(datadir)/paw-demos \
		$(datadir)/pixmaps $(datadir)/aclocal $(man1dir)
	
	# install some include files for montecarlo-base package
	install -p -m 0644 $(CVSCOSRC)/cfortran/jetset74.h \
		$(CVSCOSRC)/cfortran/lepto62.h $(includedir)/
	
	# install Geant data file into /usr/share directories
	install -p -m 0644 $(CVSCOSRC)/geant321/data/xsneut95.dat \
		$(datadir)/geant321-data/
	rm -f $(CERN_LIBDIR)/xsneut95.dat

	# ... and likewise the gxint.f file used by geant
	# (forcing it to call the Lesstif version of Paw)
	sed 's/CALL GPAW/CALL GPAWPP/g' $(CERN_LIBDIR)/gxint321.f \
		> $(datadir)/geant321/gxint321.f
	ln -sf gxint321.f $(datadir)/geant321/gxint.f
	
	# ... and Geant documentation
	install -p -m 0644 $(CERN_DOCDIR)/geant321.txt \
		$(CERN_DOCDIR)/ertrak.txt $(GEANTDOC)/
	install -d -m 0755 $(GEANTDOC)/gheisha
	install -p -m 0644 $(CERN_DOCDIR)/gheisha/* $(GEANTDOC)/gheisha/
	
	# ... and paw demos
	install -p -m 0644 $(CVSCOSRC)/pawlib/paw/demo/* $(datadir)/paw-demos/
	install -p -m 0755 $(PATCHDIR)/bin/clean_demo $(datadir)/paw-demos/
	
	# ... and X11 app-defaults
	install -p -m 0644 $(PATCHDIR)/app-defaults/*++ \
		$(sysconfdir)/X11/app-defaults/
	
	# ... and PAW icon
	install -p -m 0644 $(PATCHDIR)/icons/paw*.xpm $(datadir)/pixmaps/
	
	# ... and scripts + man pages
	for script in cernlib gxint paw paw-demos ; do \
		install -p -m 0755 $(CERN_BINDIR)/$$script $(bindir)/ ; \
	done
	for manpage in cernlib gxint paw paw-demos paw++ pawX11 ; do \
		install -p -m 0644 $(PATCHDIR)/manpages/$$manpage.1 \
			$(man1dir)/ ; \
	done

	# Contributed Autoconf macros
	install -p -m 0644 $(PATCHDIR)/misc/cernlib.m4 $(datadir)/aclocal/

clean:
	rm -rf stampdir src doc bin lib shlib build 200?

.PHONY: all gunzip patch buildtree scripts \
	cernlib-arch cernlib-libraries cernlib-programs cernlib-static \
	cernlib-indep cernlib-geant-data cernlib-mc-data \
	cernlib-geant-docs cernlib-mc-docs \
	install install-arch install-includes install-indep clean