summaryrefslogtreecommitdiff
path: root/packaging/redhat/Makefile
blob: 45f7757348b64ff63f4dd1859df298031eac1462 (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
# FreeS/WAN RedHat RPM makefile
# Copyright (C) 2002  Michael Richardson <mcr@freeswan.org>
# 
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# RCSID $Id: Makefile,v 1.1 2004/03/15 20:35:27 as Exp $

FREESWANSRCDIR=$(shell cd ../.. && pwd)
include ${FREESWANSRCDIR}/Makefile.inc
include ${FREESWANSRCDIR}/Makefile.ver


# temporary directory to be used when building RPMs, and where to put the
# resulting RPM tree
RPMKERNDIR := $(shell echo `pwd`/tmp.rpmkernel)
RPMTMPDIR=$(shell echo `pwd`/tmp.rpmbuild)
RPMDEST := $(shell echo `pwd`/rpms)

# definitions from main Makefile that may be relevant

KERNELKLIPS=$(KERNELSRC)/net/ipsec
KERNELCRYPTODES=$(KERNELSRC)/crypto/ciphers/des
KERNELLIBFREESWAN=$(KERNELSRC)/lib/libfreeswan
KERNELLIBZLIB=$(KERNELSRC)/lib/zlib
KERNELINCLUDE=$(KERNELSRC)/include

MAKEUTILS=${FREESWANSRCDIR}/packaging/utils
ERRCHECK=${MAKEUTILS}/errcheck
KVUTIL=${MAKEUTILS}/kernelversion
KVSHORTUTIL=${MAKEUTILS}/kernelversion-short


clean:	
	rm -rf $(shell echo `pwd`/BUILD.*)
	rm -rf ${RPMTMPDIR}
	rm -rf ${RPMDEST} 
	rm -f $(shell echo `pwd`/rpm.spec)

rpm:	rpm_userland rpm_modules rpm.spec final_rpm

# RPM-build userland install in temporary directory
rpm_userland: clean
	mkdir -p $(RPMTMPDIR)
	(cd ${FREESWANSRCDIR} && $(MAKE) programs install DESTDIR=$(RPMTMPDIR) && cd `pwd`)
	for extras in README CHANGES ; do \
		cp -f $(FREESWANSRCDIR)/$$extras $(RPMTMPDIR)$(FINALEXAMPLECONFDIR)/ ; \
	done

rpm_modules:
	@if [ ! -d ${RH_KERNELSRC}/configs ]; then echo "Please fix RH_KERNELSRC in Makefile.inc (${RH_KERNELSRC})"; exit 1; fi
	@KV=`${KVUTIL} $(RH_KERNELSRC)/Makefile | sed -e 's/custom//'` ; \
	MD=${RPMTMPDIR}/lib/modules/$$KV/kernel/net/ipsec; mkdir -p $$MD; \
	echo Installing into $$MD for $$KV; \
	rm -rf BUILD.*; \
	cat kernel-list.txt | while read kerneltype arch subarch; \
	do \
	    mkdir -p BUILD.$$kerneltype; \
	    if [ -z "$$subarch" ]; then subarch=$$arch; fi; \
	    BUILDDIR=`pwd`/BUILD.$$kerneltype; \
	    HERE=`pwd` ;\
	    echo Building $$KV-$$kerneltype in $$BUILDDIR; \
	    ${MAKE} -C ${FREESWANSRCDIR} MODBUILDDIR=$$BUILDDIR KERNELSRC=${RH_KERNELSRC} ARCH=$$arch SUBARCH=$$subarch MODULE_DEF_INCLUDE=$$HERE/config-$$kerneltype.h module;\
	    cp $$BUILDDIR/ipsec.o $$MD/ipsec.o-$$kerneltype; \
	    goo="`nm -ao $$BUILDDIR/ipsec.o | ${FREESWANSRCDIR}/programs/calcgoo/calcgoo`"; \
	    (cd $$MD && ln -f ipsec.o-$$kerneltype $$goo); \
	done

# build spec file for building RPMs
rpm.spec:	rpm.in $(RH_KERNELSRC)/Makefile
	KVORIG=`${KVUTIL} $(RH_KERNELSRC)/Makefile | sed -e 's/custom//'` ; \
	KV=`echo $$KVORIG | sed -e 's/-/_/g' ` ; \
	IPSECVERSIONFIXED=`echo ${IPSECVERSION} | sed -e 's/-/_/g'`; \
	echo KVORIG: $$KVORIG KV: $$KV IV: $$IPSECVERSIONFIXED; \
	sed -e "/@KERNELVERSION@/s;;$$KV;" \
		-e "/@KERNELVERSIONORIG@/s;;$$KVORIG;" \
		-e "/@IPSECVERSION@/s;;$$IPSECVERSIONFIXED;" \
		-e '/@PUBDIR@/s;;$(PUBDIR);' \
		-e '/@FINALBINDIR@/s;;$(FINALBINDIR);' \
		-e '/@FINALLIBDIR@/s;;$(FINALLIBDIR);' \
		-e '/@FINALCONFDDIR@/s;;$(FINALCONFDDIR);' \
		-e '/@FINALCONFDIR@/s;;$(FINALCONFDIR);' \
		-e '/@FINALEXAMPLECONFDIR@/s;;$(FINALEXAMPLECONFDIR);' \
		-e '/@MANTREE@/s;;$(MANTREE);' rpm.in > rpm.spec

# build RPMs
final_rpm:	rpm.spec
	mkdir -p $(RPMDEST)
	cd $(RPMDEST) ; mkdir -p SRPMS BUILD RPMS SPECS SOURCES
	cd $(RPMDEST)/RPMS ; mkdir -p $(ARCH) noarch
	$(RPMBUILD) -bb --define "buildroot $(RPMTMPDIR)" \
		--define "_topdir $(RPMDEST)" rpm.spec
	# that has, incidentally, gotten rid of $(RPMTMPDIR)