You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

973 lines
36 KiB

  1. From 010a9f2bbdaa97024933be04eff1a48ff1f9b657 Mon Sep 17 00:00:00 2001
  2. From: Andrew Cagney <cagney@gnu.org>
  3. Date: Thu, 25 Oct 2018 21:00:59 -0400
  4. Subject: [PATCH] building: move kernel (klips) rules to mk/kernel.mk
  5. ---
  6. Makefile | 448 +-----------------------------------------------
  7. mk/kernel.mk | 468 +++++++++++++++++++++++++++++++++++++++++++++++++++
  8. 2 files changed, 474 insertions(+), 442 deletions(-)
  9. create mode 100644 mk/kernel.mk
  10. diff --git a/Makefile b/Makefile
  11. index b706defd0f..0b070966e6 100644
  12. --- a/Makefile
  13. +++ b/Makefile
  14. @@ -97,119 +97,14 @@ KERNELREL=$(shell ${KVSHORTUTIL} ${KERNELSRC}/Makefile)
  15. # directories visited by all recursion
  16. -# declaration for make's benefit
  17. -.PHONY: def insert kpatch patches _patches _patches2.4 \
  18. - klipsdefaults programs man install \
  19. - precheck verset confcheck kernel \
  20. - module module24 module26 kinstall minstall minstall24 minstall26 \
  21. - moduleclean mod24clean module24clean mod26clean module26clean \
  22. - backup unpatch uninstall \
  23. - check \
  24. -
  25. -kpatch: unapplypatch applypatch klipsdefaults
  26. -npatch: unapplynpatch applynpatch
  27. -sarefpatch: unapplysarefpatch applysarefpatch
  28. -
  29. -unapplypatch:
  30. - @echo "info: making unapplypatch in `pwd` and KERNELSRC=\"${KERNELSRC}\";"
  31. - -@if [ -f ${KERNELSRC}/libreswan.patch ]; then \
  32. - echo Undoing previous patches; \
  33. - cat ${KERNELSRC}/libreswan.patch | (cd ${KERNELSRC} && patch -p1 -R --force -E -z .preipsec --reverse --ignore-whitespace ); \
  34. - fi
  35. -
  36. -applypatch:
  37. - @echo "info: Now performing forward patches in `pwd`";
  38. - ${MAKE} kernelpatch${KERNELREL} | tee ${KERNELSRC}/libreswan.patch | (cd ${KERNELSRC} && patch -p1 -b -z .preipsec --forward --ignore-whitespace )
  39. -
  40. -unapplynpatch:
  41. - @echo "info: making unapplynpatch (note the second N) in `pwd`";
  42. - -@if [ -f ${KERNELSRC}/natt.patch ]; then \
  43. - echo Undoing previous NAT patches; \
  44. - cat ${KERNELSRC}/natt.patch | (cd ${KERNELSRC} && patch -p1 -R --force -E -z .preipsec --reverse --ignore-whitespace ); \
  45. - fi
  46. -
  47. -applynpatch:
  48. - @echo "info: Now performing forward NAT patches in `pwd`";
  49. - ${MAKE} nattpatch${KERNELREL} | tee ${KERNELSRC}/natt.patch | (cd ${KERNELSRC} && patch -p1 -b -z .preipsec --forward --ignore-whitespace )
  50. -
  51. -unapplysarefpatch:
  52. - @echo "info: making unapplysarefpatch in `pwd`";
  53. - -@if [ -f ${KERNELSRC}/saref.patch ]; then \
  54. - echo Undoing previous saref patches; \
  55. - cat ${KERNELSRC}/saref.patch | (cd ${KERNELSRC} && patch -p1 -R --force -E -z .preng --reverse --ignore-whitespace ); \
  56. - fi
  57. -
  58. -applysarefpatch:
  59. - @echo "info: Now performing SAref patches in `pwd`";
  60. - ${MAKE} sarefpatch${KERNELREL} | tee ${KERNELSRC}/klipsng.patch | (cd ${KERNELSRC} && patch -p1 -b -z .preng --forward --ignore-whitespace )
  61. -
  62. -# patch kernel
  63. -PATCHER=packaging/utils/patcher
  64. -
  65. -_patches:
  66. - echo "===============" >>out.kpatch
  67. - echo "`date` `cd $(KERNELSRC) ; pwd`" >>out.kpatch
  68. - $(MAKE) __patches$(KERNELREL) >>out.kpatch
  69. -
  70. -# Linux-2.4.0 version
  71. -__patches2.4:
  72. - @$(PATCHER) -v -c $(KERNELSRC) Documentation/Configure.help \
  73. - 'CONFIG_KLIPS' $(PATCHES)/Documentation/Configure.help.fs2_2.patch
  74. - @$(PATCHER) -v $(KERNELSRC) net/Config.in \
  75. - 'CONFIG_KLIPS' $(PATCHES)/net/Config.in.fs2_4.patch
  76. - @$(PATCHER) -v $(KERNELSRC) net/Makefile \
  77. - 'CONFIG_KLIPS' $(PATCHES)/net/Makefile.fs2_4.patch
  78. - @$(PATCHER) -v $(KERNELSRC) net/ipv4/af_inet.c \
  79. - 'CONFIG_KLIPS' $(PATCHES)/net/ipv4/af_inet.c.fs2_4.patch
  80. - @$(PATCHER) -v $(KERNELSRC) net/ipv4/udp.c \
  81. - 'CONFIG_KLIPS' $(PATCHES)/net/ipv4/udp.c.fs2_4.patch
  82. - @$(PATCHER) -v $(KERNELSRC) include/net/sock.h \
  83. - 'CONFIG_KLIPS' $(PATCHES)/include/net/sock.h.fs2_4.patch
  84. -# Removed patches, will unpatch automatically.
  85. - @$(PATCHER) -v $(KERNELSRC) include/linux/proc_fs.h
  86. - @$(PATCHER) -v $(KERNELSRC) net/core/dev.c
  87. - @$(PATCHER) -v $(KERNELSRC) net/ipv4/protocol.c
  88. - @$(PATCHER) -v $(KERNELSRC) drivers/net/Space.c
  89. - @$(PATCHER) -v $(KERNELSRC) include/linux/netlink.h
  90. - @$(PATCHER) -v $(KERNELSRC) net/netlink/af_netlink.c
  91. - @$(PATCHER) -v $(KERNELSRC) net/netlink/netlink_dev.c
  92. - @$(PATCHER) -v $(KERNELSRC) drivers/isdn/isdn_net.c
  93. -
  94. -klipsdefaults:
  95. - @KERNELDEFCONFIG=$(KERNELSRC)/arch/$(ARCH)/defconfig ; \
  96. - KERNELCONFIG=$(KCFILE) ; \
  97. - if ! egrep -q 'CONFIG_KLIPS' $$KERNELDEFCONFIG ; \
  98. - then \
  99. - set -x ; \
  100. - cp -a $$KERNELDEFCONFIG $$KERNELDEFCONFIG.orig ; \
  101. - chmod u+w $$KERNELDEFCONFIG ; \
  102. - cat $$KERNELDEFCONFIG $(KERNELKLIPS)/defconfig \
  103. - >$$KERNELDEFCONFIG.tmp ; \
  104. - rm -f $$KERNELDEFCONFIG ; \
  105. - cp -a $$KERNELDEFCONFIG.tmp $$KERNELDEFCONFIG ; \
  106. - rm -f $$KERNELDEFCONFIG.tmp ; \
  107. - fi ; \
  108. - if ! egrep -q 'CONFIG_KLIPS' $$KERNELCONFIG ; \
  109. - then \
  110. - set -x ; \
  111. - cp -a $$KERNELCONFIG $$KERNELCONFIG.orig ; \
  112. - chmod u+w $$KERNELCONFIG ; \
  113. - cat $$KERNELCONFIG $(KERNELKLIPS)/defconfig \
  114. - >$$KERNELCONFIG.tmp ; \
  115. - rm -f $$KERNELCONFIG ; \
  116. - cp -a $$KERNELCONFIG.tmp $$KERNELCONFIG ; \
  117. - rm -f $$KERNELCONFIG.tmp ; \
  118. - fi
  119. -
  120. -
  121. -
  122. # programs
  123. ABSOBJDIR:=$(shell mkdir -p ${OBJDIR}; cd ${OBJDIR} && pwd)
  124. OBJDIRTOP=${ABSOBJDIR}
  125. # Recursive clean dealt with elsewhere.
  126. -local-clean-base: moduleclean
  127. +.PHONY: local-clean-base
  128. +local-clean-base:
  129. $(foreach file,$(RPMTMPDIR) $(RPMDEST) out.*build out.*install, \
  130. rm -rf $(file) ; ) # but leave out.kpatch
  131. @@ -219,339 +114,13 @@ local-clean-base: moduleclean
  132. # $(OBJDIR), "distclean" does not depend on it. If it did, "make
  133. # distclean" would have the quirky behaviour of first creating
  134. # $(OBJDIR) only to then delete it.
  135. -distclean: moduleclean module24clean module26clean clean-kvm-keys
  136. +.PHONY: distclean
  137. +distclean: clean-kvm-keys
  138. rm -f $(RPMTMPDIR) $(RPMDEST) out.*
  139. rm -rf testing/pluto/*/OUTPUT*
  140. rm -rf OBJ.* $(OBJDIR)
  141. rm -rf BACKUP
  142. -# proxies for major kernel make operations
  143. -
  144. -# do-everything entries
  145. -KINSERT_PRE=precheck verset insert
  146. -PRE=precheck verset kpatch
  147. -POST=confcheck programs kernel install
  148. -MPOST=confcheck programs module install
  149. -
  150. -# preliminaries
  151. -precheck:
  152. - @if test ! -d $(KERNELSRC) -a ! -L $(KERNELSRC) ; \
  153. - then \
  154. - echo '*** cannot find directory "$(KERNELSRC)"!!' ; \
  155. - echo '*** may be necessary to add symlink to kernel source' ; \
  156. - exit 1 ; \
  157. - fi
  158. - @if ! cd $(KERNELSRC) ; \
  159. - then \
  160. - echo '*** cannot "cd $(KERNELSRC)"!!' ; \
  161. - echo '*** may be necessary to add symlink to kernel source' ; \
  162. - exit 1 ; \
  163. - fi
  164. - @if test ! -f $(KCFILE) ; \
  165. - then \
  166. - echo '*** cannot find "$(KCFILE)"!!' ; \
  167. - echo '*** perhaps kernel has never been configured?' ; \
  168. - echo '*** please do that first; the results are necessary.' ; \
  169. - exit 1 ; \
  170. - fi
  171. - @if test ! -f $(VERFILE) ; \
  172. - then \
  173. - echo '*** cannot find "$(VERFILE)"!!' ; \
  174. - echo '*** perhaps kernel has never been compiled?' ; \
  175. - echo '*** please do that first; the results are necessary.' ; \
  176. - exit 1 ; \
  177. - fi
  178. -
  179. -# configuring (exit statuses disregarded, something fishy here sometimes)
  180. -xcf:
  181. - -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) xconfig
  182. -mcf:
  183. - -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) menuconfig
  184. -pcf:
  185. - -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) config
  186. -
  187. -ocf:
  188. - -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) oldconfig
  189. -
  190. -rcf:
  191. - cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) ${NONINTCONFIG} </dev/null
  192. - cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) dep >/dev/null
  193. -
  194. -kclean:
  195. - -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) clean
  196. -
  197. -confcheck:
  198. - @if test ! -f $(KCFILE) ; \
  199. - then echo '*** no kernel configuration file written!!' ; exit 1 ; \
  200. - fi
  201. - @if ! egrep -q '^CONFIG_KLIPS=[my]' $(KCFILE) ; \
  202. - then echo '*** IPsec not in kernel config ($(KCFILE))!!' ; exit 1 ; \
  203. - fi
  204. - @if ! egrep -q 'CONFIG_KLIPS[ ]+1' $(ACFILE) && \
  205. - ! egrep -q 'CONFIG_KLIPS_MODULE[ ]+1' $(ACFILE) ; \
  206. - then echo '*** IPsec in kernel config ($(KCFILE)),' ; \
  207. - echo '*** but not in config header file ($(ACFILE))!!' ; \
  208. - exit 1 ; \
  209. - fi
  210. - @if egrep -q '^CONFIG_KLIPS=m' $(KCFILE) && \
  211. - ! egrep -q '^CONFIG_MODULES=y' $(KCFILE) ; \
  212. - then echo '*** IPsec configured as module in kernel with no module support!!' ; exit 1 ; \
  213. - fi
  214. - @if ! egrep -q 'CONFIG_KLIPS_AH[ ]+1' $(ACFILE) && \
  215. - ! egrep -q 'CONFIG_KLIPS_ESP[ ]+1' $(ACFILE) ; \
  216. - then echo '*** IPsec configuration must include AH or ESP!!' ; exit 1 ; \
  217. - fi
  218. -
  219. -# kernel building, with error checks
  220. -kernel:
  221. - rm -f out.kbuild out.kinstall
  222. - # undocumented kernel folklore: clean BEFORE dep.
  223. - # we run make dep separately, because there is no point in running ERRCHECK
  224. - # on the make dep output.
  225. - # see LKML thread "clean before or after dep?"
  226. - ( cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) $(KERNCLEAN) $(KERNDEP) )
  227. - ( cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) $(KERNEL) ) 2>&1 | tee out.kbuild
  228. - @if egrep -q '^CONFIG_MODULES=y' $(KCFILE) ; \
  229. - then set -x ; \
  230. - ( cd $(KERNELSRC) ; \
  231. - $(MAKE) $(KERNMAKEOPTS) modules 2>&1 ) | tee -a out.kbuild ; \
  232. - fi
  233. - ${ERRCHECK} out.kbuild
  234. -
  235. -# module-only building, with error checks
  236. -ifneq ($(strip $(MOD24BUILDDIR)),)
  237. -${MOD24BUILDDIR}/Makefile : ${LIBRESWANSRCDIR}/packaging/makefiles/module24.make
  238. - mkdir -p ${MOD24BUILDDIR}
  239. - cp ${LIBRESWANSRCDIR}/packaging/makefiles/module24.make ${MOD24BUILDDIR}/Makefile
  240. -
  241. -module:
  242. - @if [ -f ${KERNELSRC}/README.libreswan-2 ] ; then \
  243. - echo "WARNING: Kernel source ${KERNELSRC} has already been patched with libreswan-2, out of tree build might fail!"; \
  244. - fi;
  245. - @if [ -f ${KERNELSRC}/README.openswan ] ; then \
  246. - echo "WARNING: Kernel source ${KERNELSRC} has already been patched with openswan, out of tree build might fail!"; \
  247. - fi;
  248. - @if [ -f ${KERNELSRC}/README.openswan-2 ] ; then \
  249. - echo "WARNING: Kernel source ${KERNELSRC} has already been patched with openswan-2, out of tree build might fail!"; \
  250. - fi;
  251. - @if [ -f ${KERNELSRC}/README.freeswan ] ; then \
  252. - echo "ERROR: Kernel source ${KERNELSRC} has already been patched with freeswan, out of tree build will fail!"; \
  253. - fi;
  254. - @if [ -f ${KERNELSRC}/Rules.make ] ; then \
  255. - echo "Building module for a 2.4 kernel"; ${MAKE} module24 ; \
  256. - else echo "Building module for a 2.6 kernel"; ${MAKE} module26; \
  257. - fi;
  258. -
  259. -modclean moduleclean:
  260. - @if [ -f ${KERNELSRC}/Rules.make ] ; then \
  261. - echo "Cleaning module for a 2.4 kernel"; ${MAKE} module24clean ; \
  262. - else echo "Cleaning module for a 2.6 kernel"; ${MAKE} module26clean; \
  263. - fi;
  264. -
  265. -module24:
  266. - @if [ ! -f ${KERNELSRC}/Rules.make ] ; then \
  267. - echo "Warning: Building for a 2.4 kernel in what looks like a 2.6 tree"; \
  268. - fi ; \
  269. - ${MAKE} ${MOD24BUILDDIR}/Makefile
  270. - ${MAKE} -C ${MOD24BUILDDIR} LIBRESWANSRCDIR=${LIBRESWANSRCDIR} ARCH=${ARCH} V=${V} ${MODULE_FLAGS} MODULE_DEF_INCLUDE=${MODULE_DEF_INCLUDE} TOPDIR=${KERNELSRC} -f Makefile ipsec.o
  271. - @echo
  272. - @echo '========================================================='
  273. - @echo
  274. - @echo 'KLIPS24 module built successfully. '
  275. - @echo ipsec.o is in ${MOD24BUILDDIR}
  276. - @echo
  277. - @(cd ${MOD24BUILDDIR}; ls -l ipsec.o)
  278. - @(cd ${MOD24BUILDDIR}; size ipsec.o)
  279. - @echo
  280. - @echo 'use make minstall as root to install it'
  281. - @echo
  282. - @echo '========================================================='
  283. - @echo
  284. -
  285. -mod24clean module24clean:
  286. - rm -rf ${MOD24BUILDDIR}
  287. -
  288. -#autoodetect 2.4 and 2.6
  289. -module_install minstall install-module:
  290. - @if [ -f $(KERNELSRC)/Rules.make ] ; then \
  291. - $(MAKE) minstall24 ; \
  292. - else \
  293. - $(MAKE) minstall26 ; \
  294. - fi;
  295. -
  296. -# Extract the value of MODLIB from the output of $(MAKE). Also hide
  297. -# the sup-process $(MAKE) so that GNU Make doesn't always invoke the
  298. -# target ("make -n" ignored).
  299. -#
  300. -# If $(MAKE) directly appears in a target (for instance in minstall26)
  301. -# then GNU Make will assume that it is a recursive make invocation and
  302. -# invoke the target regardless of -n.
  303. -#
  304. -# XXX: minstall24 should also use this.
  305. -
  306. -osmodlib-from-make = \
  307. - OSMODLIB=$$($(MAKE) $(1) 2>/dev/null | sed -n -e 's/^MODLIB[ :=]*\([^;]*\).*/\1/p' | head -1) ; \
  308. - test -z "$$OSMODLIB" || echo "OSMODLIB=$$OSMODLIB ($(MAKE) $(1))"
  309. -
  310. -# module-only install, with error checks
  311. -minstall24:
  312. - ( OSMODLIB=`${MAKE} -C $(KERNELSRC) -p dummy | ( sed -n -e '/^MODLIB/p' -e '/^MODLIB/q' ; cat > /dev/null ) | sed -e 's/^MODLIB[ :=]*\([^;]*\).*/\1/'` ; \
  313. - if [ -z "$$OSMODLIB" ] ; then \
  314. - OSMODLIB=`${MAKE} -C $(KERNELSRC) -n -p modules_install | ( sed -n -e '/^MODLIB/p' -e '/^MODLIB/q' ; cat > /dev/null ) | sed -e 's/^MODLIB[ :=]*\([^;]*\).*/\1/'` ; \
  315. - fi ; \
  316. - if [ -z "$$OSMODLIB" ] ; then \
  317. - echo "No known place to install module. Aborting." ; \
  318. - exit 93 ; \
  319. - fi ; \
  320. - set -x ; \
  321. - mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  322. - cp $(MOD24BUILDDIR)/ipsec.o $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  323. - if [ -f /sbin/depmod ] ; then /sbin/depmod -a ; fi; \
  324. - if [ -n "$(OSMOD_DESTDIR)" ] ; then \
  325. - mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  326. - if [ -f $$OSMODLIB/kernel/ipsec.o -a -f $$OSMODLIB/kernel/$(OSMOD_DESTDIR)/ipsec.o ] ; then \
  327. - echo "WARNING: two ipsec.o modules found in $$OSMODLIB/kernel:" ; \
  328. - ls -l $$OSMODLIB/kernel/ipsec.o $$OSMODLIB/kernel/$(OSMOD_DESTDIR)/ipsec.o ; \
  329. - exit 1; \
  330. - fi ; \
  331. - fi ; \
  332. - set -x ) ;
  333. -
  334. -
  335. -else
  336. -module:
  337. - echo 'Building in place is no longer supported. Please set MOD24BUILDDIR='
  338. - exit 1
  339. -
  340. -endif
  341. -
  342. -# module-only building, with error checks
  343. -ifneq ($(strip $(MODBUILDDIR)),)
  344. -${MODBUILDDIR}/Makefile : ${LIBRESWANSRCDIR}/packaging/makefiles/module.make
  345. - mkdir -p ${MODBUILDDIR}
  346. - echo ln -s -f ${LIBRESWANSRCDIR}/linux/net/ipsec/des/*.S ${MODBUILDDIR}
  347. - (rm -f ${MODBUILDDIR}/des; mkdir -p ${MODBUILDDIR}/des && cd ${MODBUILDDIR}/des && ln -s -f ${LIBRESWANSRCDIR}/linux/net/ipsec/des/* . && ln -s -f Makefile.fs2_6 Makefile)
  348. - (rm -f ${MODBUILDDIR}/aes; mkdir -p ${MODBUILDDIR}/aes && cd ${MODBUILDDIR}/aes && ln -s -f ${LIBRESWANSRCDIR}/linux/net/ipsec/aes/* . && ln -s -f Makefile.fs2_6 Makefile)
  349. - mkdir -p ${MODBUILDDIR}/aes
  350. - cp ${LIBRESWANSRCDIR}/packaging/makefiles/module.make ${MODBUILDDIR}/Makefile
  351. - ln -s -f ${LIBRESWANSRCDIR}/linux/net/ipsec/match*.S ${MODBUILDDIR}
  352. -
  353. -module26:
  354. - @if [ -f ${KERNELSRC}/Rules.make ] ; then \ echo "Warning: Building for a 2.6+ kernel in what looks like a 2.4 tree"; \
  355. - fi ; \
  356. - ${MAKE} ${MODBUILDDIR}/Makefile
  357. - ${MAKE} -C ${KERNELSRC} ${KERNELBUILDMFLAGS} BUILDDIR=${MODBUILDDIR} SUBDIRS=${MODBUILDDIR} INITSYSTEM=$(INITSYSTEM) MODULE_DEF_INCLUDE=${MODULE_DEF_INCLUDE} MODULE_DEFCONFIG=${MODULE_DEFCONFIG} MODULE_EXTRA_INCLUDE=${MODULE_EXTRA_INCLUDE} ARCH=${ARCH} V=${V} modules
  358. - @echo
  359. - @echo '========================================================='
  360. - @echo
  361. - @echo 'KLIPS module built successfully. '
  362. - @echo ipsec.ko is in ${MODBUILDDIR}
  363. - @echo
  364. - @(cd ${MODBUILDDIR}; ls -l ipsec.ko)
  365. - @(cd ${MODBUILDDIR}; size ipsec.ko)
  366. - @echo
  367. - @echo 'use make minstall as root to install it'
  368. - @echo
  369. - @echo '========================================================='
  370. - @echo
  371. -
  372. -mod26clean module26clean:
  373. - rm -rf ${MODBUILDDIR}
  374. -
  375. -# module-only install, with error checks
  376. -minstall26:
  377. - $(call osmodlib-from-make,-C $(KERNELSRC) -p help) ; \
  378. - if [ -z "$$OSMODLIB" ] ; then \
  379. - $(call osmodlib-from-make,-C $(KERNELSRC) -n -p modules_install) ; \
  380. - fi ; \
  381. - if [ -z "$$OSMODLIB" ] ; then \
  382. - echo "No known place to install module. Aborting." ; \
  383. - exit 93 ; \
  384. - fi ; \
  385. - set -x ; \
  386. - mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  387. - cp $(MODBUILDDIR)/ipsec.ko $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  388. - if [ -f /sbin/depmod ] ; then \
  389. - /sbin/depmod -a ; \
  390. - fi ; \
  391. - if [ -n "$(OSMOD_DESTDIR)" ] ; then \
  392. - mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  393. - if [ -f $$OSMODLIB/kernel/ipsec.ko -a -f $$OSMODLIB/kernel/$(OSMOD_DESTDIR)/ipsec.ko ] ; then \
  394. - echo "WARNING: two ipsec.ko modules found in $$OSMODLIB/kernel:" ; \
  395. - ls -l $$OSMODLIB/kernel/ipsec.ko $$OSMODLIB/kernel/$(OSMOD_DESTDIR)/ipsec.ko ; \
  396. - exit 1; \
  397. - fi ; \
  398. - fi
  399. -
  400. -
  401. -else
  402. -module26:
  403. - echo 'Building in place is no longer supported. Please set MODBUILDDIR='
  404. - exit 1
  405. -
  406. -endif
  407. -
  408. -# kernel install, with error checks
  409. -kinstall:
  410. - rm -f out.kinstall
  411. - >out.kinstall
  412. - # undocumented kernel folklore: modules_install must precede install (observed on RHL8.0)
  413. - @if egrep -q '^CONFIG_MODULES=y' $(KCFILE) ; \
  414. - then set -x ; \
  415. - ( cd $(KERNELSRC) ; \
  416. - $(MAKE) $(KERNMAKEOPTS) modules_install 2>&1 ) | tee -a out.kinstall ; \
  417. - fi
  418. - ( cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) install ) 2>&1 | tee -a out.kinstall
  419. - ${ERRCHECK} out.kinstall
  420. -
  421. -kernelpatch3 kernelpatch3.5 kernelpatch2.6 kernelpatch:
  422. - packaging/utils/kernelpatch 2.6
  423. -
  424. -kernelpatch2.4:
  425. - packaging/utils/kernelpatch 2.4
  426. -
  427. -nattpatch:
  428. - if [ -f ${KERNELSRC}/Makefile ]; then \
  429. - ${MAKE} nattpatch${KERNELREL}; \
  430. - else echo "Cannot determine Linux kernel version. Perhaps you need to set KERNELSRC? (eg: export KERNELSRC=/usr/src/linux-`uname -r`/)"; exit 1; \
  431. - fi;
  432. -
  433. -sarefpatch2.6:
  434. - #cat patches/kernel/2.6.38/0001-SAREF-add-support-for-SA-selection-through-sendmsg.patch
  435. - #packaging/utils/sarefpatch 2.6
  436. - echo ""
  437. -
  438. -nattpatch2.6:
  439. - packaging/utils/nattpatch 2.6
  440. -
  441. -nattpatch2.4:
  442. - packaging/utils/nattpatch 2.4
  443. -
  444. -nattupdate:
  445. - (cd UMLPOOL && diff -u plain26/net/ipv4/udp.c.orig plain26/net/ipv4/udp.c; exit 0) >nat-t/net/ipv4/udp.c.os2_6.patch
  446. -
  447. -# take all the patches out of the kernel
  448. -# (Note, a couple of files are modified by non-patch means; they are
  449. -# included in "make backup".)
  450. -unpatch:
  451. - @echo \"make unpatch\" is obsolete. See make unapplypatch.
  452. - exit 1
  453. -
  454. -_unpatch:
  455. - for f in `find $(KERNELSRC)/. -name '*.preipsec' -print` ; \
  456. - do \
  457. - echo "restoring $$f:" ; \
  458. - dir=`dirname $$f` ; \
  459. - core=`basename $$f .preipsec` ; \
  460. - cd $$dir ; \
  461. - mv -f $$core.preipsec $$core ; \
  462. - rm -f $$core.wipsec $$core.ipsecmd5 ; \
  463. - done
  464. -
  465. -# at the moment there is no difference between snapshot and release build
  466. -snapready: buildready
  467. -relready: buildready
  468. -ready: devready
  469. # set up for build
  470. buildready:
  471. @@ -604,13 +173,6 @@ deb:
  472. #debuild -S -sa
  473. @echo "to build optional KLIPS kernel module, run make deb-klips"
  474. -deb-klips:
  475. - sudo module-assistant prepare -u .
  476. - sudo dpkg -i ../libreswan-modules-source_`make -s showdebversion`_all.deb
  477. - sudo module-assistant -u . prepare
  478. - sudo module-assistant -u . build libreswan
  479. -
  480. -
  481. release:
  482. packaging/utils/makerelease
  483. @@ -654,3 +216,5 @@ install-fipshmac:
  484. include ${LIBRESWANSRCDIR}/mk/docker-targets.mk
  485. include ${LIBRESWANSRCDIR}/mk/kvm-targets.mk
  486. include ${LIBRESWANSRCDIR}/mk/web-targets.mk
  487. +include ${LIBRESWANSRCDIR}/mk/kernel.mk
  488. +
  489. diff --git a/mk/kernel.mk b/mk/kernel.mk
  490. new file mode 100644
  491. index 0000000000..187167d440
  492. --- /dev/null
  493. +++ b/mk/kernel.mk
  494. @@ -0,0 +1,468 @@
  495. +# Libreswan master makefile
  496. +#
  497. +# Copyright (C) 1998-2002 Henry Spencer.
  498. +# Copyright (C) 2003-2004 Xelerance Corporation
  499. +# Copyright (C) 2017, Richard Guy Briggs <rgb@tricolour.ca>
  500. +# Copyright (C) 2015-2018 Andrew Cagney
  501. +#
  502. +# This program is free software; you can redistribute it and/or modify it
  503. +# under the terms of the GNU General Public License as published by the
  504. +# Free Software Foundation; either version 2 of the License, or (at your
  505. +# option) any later version. See <https://www.gnu.org/licenses/gpl2.txt>.
  506. +#
  507. +# This program is distributed in the hope that it will be useful, but
  508. +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  509. +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  510. +# for more details.
  511. +#
  512. +
  513. +PATCHES=linux
  514. +# where KLIPS goes in the kernel
  515. +# note, some of the patches know the last part of this path
  516. +KERNELKLIPS=$(KERNELSRC)/net/ipsec
  517. +KERNELCRYPTODES=$(KERNELSRC)/crypto/ciphers/des
  518. +KERNELLIBFREESWAN=$(KERNELSRC)/lib/libfreeswan
  519. +KERNELLIBZLIB=$(KERNELSRC)/lib/zlib
  520. +KERNELINCLUDE=$(KERNELSRC)/include
  521. +
  522. +MAKEUTILS=packaging/utils
  523. +ERRCHECK=${MAKEUTILS}/errcheck
  524. +KVUTIL=${MAKEUTILS}/kernelversion
  525. +KVSHORTUTIL=${MAKEUTILS}/kernelversion-short
  526. +
  527. +# kernel details
  528. +# what variant of our patches should we use, and where is it
  529. +KERNELREL=$(shell ${KVSHORTUTIL} ${KERNELSRC}/Makefile)
  530. +
  531. +# directories visited by all recursion
  532. +
  533. +# declaration for make's benefit
  534. +.PHONY: def insert kpatch patches _patches _patches2.4 \
  535. + klipsdefaults programs man install \
  536. + precheck verset confcheck kernel \
  537. + module module24 module26 kinstall minstall minstall24 minstall26 \
  538. + moduleclean mod24clean module24clean mod26clean module26clean \
  539. + backup unpatch uninstall \
  540. + check \
  541. +
  542. +kpatch: unapplypatch applypatch klipsdefaults
  543. +npatch: unapplynpatch applynpatch
  544. +sarefpatch: unapplysarefpatch applysarefpatch
  545. +
  546. +unapplypatch:
  547. + @echo "info: making unapplypatch in `pwd` and KERNELSRC=\"${KERNELSRC}\";"
  548. + -@if [ -f ${KERNELSRC}/libreswan.patch ]; then \
  549. + echo Undoing previous patches; \
  550. + cat ${KERNELSRC}/libreswan.patch | (cd ${KERNELSRC} && patch -p1 -R --force -E -z .preipsec --reverse --ignore-whitespace ); \
  551. + fi
  552. +
  553. +applypatch:
  554. + @echo "info: Now performing forward patches in `pwd`";
  555. + ${MAKE} kernelpatch${KERNELREL} | tee ${KERNELSRC}/libreswan.patch | (cd ${KERNELSRC} && patch -p1 -b -z .preipsec --forward --ignore-whitespace )
  556. +
  557. +unapplynpatch:
  558. + @echo "info: making unapplynpatch (note the second N) in `pwd`";
  559. + -@if [ -f ${KERNELSRC}/natt.patch ]; then \
  560. + echo Undoing previous NAT patches; \
  561. + cat ${KERNELSRC}/natt.patch | (cd ${KERNELSRC} && patch -p1 -R --force -E -z .preipsec --reverse --ignore-whitespace ); \
  562. + fi
  563. +
  564. +applynpatch:
  565. + @echo "info: Now performing forward NAT patches in `pwd`";
  566. + ${MAKE} nattpatch${KERNELREL} | tee ${KERNELSRC}/natt.patch | (cd ${KERNELSRC} && patch -p1 -b -z .preipsec --forward --ignore-whitespace )
  567. +
  568. +unapplysarefpatch:
  569. + @echo "info: making unapplysarefpatch in `pwd`";
  570. + -@if [ -f ${KERNELSRC}/saref.patch ]; then \
  571. + echo Undoing previous saref patches; \
  572. + cat ${KERNELSRC}/saref.patch | (cd ${KERNELSRC} && patch -p1 -R --force -E -z .preng --reverse --ignore-whitespace ); \
  573. + fi
  574. +
  575. +applysarefpatch:
  576. + @echo "info: Now performing SAref patches in `pwd`";
  577. + ${MAKE} sarefpatch${KERNELREL} | tee ${KERNELSRC}/klipsng.patch | (cd ${KERNELSRC} && patch -p1 -b -z .preng --forward --ignore-whitespace )
  578. +
  579. +# patch kernel
  580. +PATCHER=packaging/utils/patcher
  581. +
  582. +_patches:
  583. + echo "===============" >>out.kpatch
  584. + echo "`date` `cd $(KERNELSRC) ; pwd`" >>out.kpatch
  585. + $(MAKE) __patches$(KERNELREL) >>out.kpatch
  586. +
  587. +# Linux-2.4.0 version
  588. +__patches2.4:
  589. + @$(PATCHER) -v -c $(KERNELSRC) Documentation/Configure.help \
  590. + 'CONFIG_KLIPS' $(PATCHES)/Documentation/Configure.help.fs2_2.patch
  591. + @$(PATCHER) -v $(KERNELSRC) net/Config.in \
  592. + 'CONFIG_KLIPS' $(PATCHES)/net/Config.in.fs2_4.patch
  593. + @$(PATCHER) -v $(KERNELSRC) net/Makefile \
  594. + 'CONFIG_KLIPS' $(PATCHES)/net/Makefile.fs2_4.patch
  595. + @$(PATCHER) -v $(KERNELSRC) net/ipv4/af_inet.c \
  596. + 'CONFIG_KLIPS' $(PATCHES)/net/ipv4/af_inet.c.fs2_4.patch
  597. + @$(PATCHER) -v $(KERNELSRC) net/ipv4/udp.c \
  598. + 'CONFIG_KLIPS' $(PATCHES)/net/ipv4/udp.c.fs2_4.patch
  599. + @$(PATCHER) -v $(KERNELSRC) include/net/sock.h \
  600. + 'CONFIG_KLIPS' $(PATCHES)/include/net/sock.h.fs2_4.patch
  601. +# Removed patches, will unpatch automatically.
  602. + @$(PATCHER) -v $(KERNELSRC) include/linux/proc_fs.h
  603. + @$(PATCHER) -v $(KERNELSRC) net/core/dev.c
  604. + @$(PATCHER) -v $(KERNELSRC) net/ipv4/protocol.c
  605. + @$(PATCHER) -v $(KERNELSRC) drivers/net/Space.c
  606. + @$(PATCHER) -v $(KERNELSRC) include/linux/netlink.h
  607. + @$(PATCHER) -v $(KERNELSRC) net/netlink/af_netlink.c
  608. + @$(PATCHER) -v $(KERNELSRC) net/netlink/netlink_dev.c
  609. + @$(PATCHER) -v $(KERNELSRC) drivers/isdn/isdn_net.c
  610. +
  611. +klipsdefaults:
  612. + @KERNELDEFCONFIG=$(KERNELSRC)/arch/$(ARCH)/defconfig ; \
  613. + KERNELCONFIG=$(KCFILE) ; \
  614. + if ! egrep -q 'CONFIG_KLIPS' $$KERNELDEFCONFIG ; \
  615. + then \
  616. + set -x ; \
  617. + cp -a $$KERNELDEFCONFIG $$KERNELDEFCONFIG.orig ; \
  618. + chmod u+w $$KERNELDEFCONFIG ; \
  619. + cat $$KERNELDEFCONFIG $(KERNELKLIPS)/defconfig \
  620. + >$$KERNELDEFCONFIG.tmp ; \
  621. + rm -f $$KERNELDEFCONFIG ; \
  622. + cp -a $$KERNELDEFCONFIG.tmp $$KERNELDEFCONFIG ; \
  623. + rm -f $$KERNELDEFCONFIG.tmp ; \
  624. + fi ; \
  625. + if ! egrep -q 'CONFIG_KLIPS' $$KERNELCONFIG ; \
  626. + then \
  627. + set -x ; \
  628. + cp -a $$KERNELCONFIG $$KERNELCONFIG.orig ; \
  629. + chmod u+w $$KERNELCONFIG ; \
  630. + cat $$KERNELCONFIG $(KERNELKLIPS)/defconfig \
  631. + >$$KERNELCONFIG.tmp ; \
  632. + rm -f $$KERNELCONFIG ; \
  633. + cp -a $$KERNELCONFIG.tmp $$KERNELCONFIG ; \
  634. + rm -f $$KERNELCONFIG.tmp ; \
  635. + fi
  636. +
  637. +
  638. +local-clean-base: moduleclean
  639. +distclean: moduleclean module24clean module26clean clean-kvm-keys
  640. +
  641. +# proxies for major kernel make operations
  642. +
  643. +# do-everything entries
  644. +KINSERT_PRE=precheck verset insert
  645. +PRE=precheck verset kpatch
  646. +POST=confcheck programs kernel install
  647. +MPOST=confcheck programs module install
  648. +
  649. +# preliminaries
  650. +precheck:
  651. + @if test ! -d $(KERNELSRC) -a ! -L $(KERNELSRC) ; \
  652. + then \
  653. + echo '*** cannot find directory "$(KERNELSRC)"!!' ; \
  654. + echo '*** may be necessary to add symlink to kernel source' ; \
  655. + exit 1 ; \
  656. + fi
  657. + @if ! cd $(KERNELSRC) ; \
  658. + then \
  659. + echo '*** cannot "cd $(KERNELSRC)"!!' ; \
  660. + echo '*** may be necessary to add symlink to kernel source' ; \
  661. + exit 1 ; \
  662. + fi
  663. + @if test ! -f $(KCFILE) ; \
  664. + then \
  665. + echo '*** cannot find "$(KCFILE)"!!' ; \
  666. + echo '*** perhaps kernel has never been configured?' ; \
  667. + echo '*** please do that first; the results are necessary.' ; \
  668. + exit 1 ; \
  669. + fi
  670. + @if test ! -f $(VERFILE) ; \
  671. + then \
  672. + echo '*** cannot find "$(VERFILE)"!!' ; \
  673. + echo '*** perhaps kernel has never been compiled?' ; \
  674. + echo '*** please do that first; the results are necessary.' ; \
  675. + exit 1 ; \
  676. + fi
  677. +
  678. +# configuring (exit statuses disregarded, something fishy here sometimes)
  679. +xcf:
  680. + -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) xconfig
  681. +mcf:
  682. + -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) menuconfig
  683. +pcf:
  684. + -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) config
  685. +
  686. +ocf:
  687. + -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) oldconfig
  688. +
  689. +rcf:
  690. + cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) ${NONINTCONFIG} </dev/null
  691. + cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) dep >/dev/null
  692. +
  693. +kclean:
  694. + -cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) clean
  695. +
  696. +confcheck:
  697. + @if test ! -f $(KCFILE) ; \
  698. + then echo '*** no kernel configuration file written!!' ; exit 1 ; \
  699. + fi
  700. + @if ! egrep -q '^CONFIG_KLIPS=[my]' $(KCFILE) ; \
  701. + then echo '*** IPsec not in kernel config ($(KCFILE))!!' ; exit 1 ; \
  702. + fi
  703. + @if ! egrep -q 'CONFIG_KLIPS[ ]+1' $(ACFILE) && \
  704. + ! egrep -q 'CONFIG_KLIPS_MODULE[ ]+1' $(ACFILE) ; \
  705. + then echo '*** IPsec in kernel config ($(KCFILE)),' ; \
  706. + echo '*** but not in config header file ($(ACFILE))!!' ; \
  707. + exit 1 ; \
  708. + fi
  709. + @if egrep -q '^CONFIG_KLIPS=m' $(KCFILE) && \
  710. + ! egrep -q '^CONFIG_MODULES=y' $(KCFILE) ; \
  711. + then echo '*** IPsec configured as module in kernel with no module support!!' ; exit 1 ; \
  712. + fi
  713. + @if ! egrep -q 'CONFIG_KLIPS_AH[ ]+1' $(ACFILE) && \
  714. + ! egrep -q 'CONFIG_KLIPS_ESP[ ]+1' $(ACFILE) ; \
  715. + then echo '*** IPsec configuration must include AH or ESP!!' ; exit 1 ; \
  716. + fi
  717. +
  718. +# kernel building, with error checks
  719. +kernel:
  720. + rm -f out.kbuild out.kinstall
  721. + # undocumented kernel folklore: clean BEFORE dep.
  722. + # we run make dep separately, because there is no point in running ERRCHECK
  723. + # on the make dep output.
  724. + # see LKML thread "clean before or after dep?"
  725. + ( cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) $(KERNCLEAN) $(KERNDEP) )
  726. + ( cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) $(KERNEL) ) 2>&1 | tee out.kbuild
  727. + @if egrep -q '^CONFIG_MODULES=y' $(KCFILE) ; \
  728. + then set -x ; \
  729. + ( cd $(KERNELSRC) ; \
  730. + $(MAKE) $(KERNMAKEOPTS) modules 2>&1 ) | tee -a out.kbuild ; \
  731. + fi
  732. + ${ERRCHECK} out.kbuild
  733. +
  734. +# module-only building, with error checks
  735. +ifneq ($(strip $(MOD24BUILDDIR)),)
  736. +${MOD24BUILDDIR}/Makefile : ${LIBRESWANSRCDIR}/packaging/makefiles/module24.make
  737. + mkdir -p ${MOD24BUILDDIR}
  738. + cp ${LIBRESWANSRCDIR}/packaging/makefiles/module24.make ${MOD24BUILDDIR}/Makefile
  739. +
  740. +module:
  741. + @if [ -f ${KERNELSRC}/README.libreswan-2 ] ; then \
  742. + echo "WARNING: Kernel source ${KERNELSRC} has already been patched with libreswan-2, out of tree build might fail!"; \
  743. + fi;
  744. + @if [ -f ${KERNELSRC}/README.openswan ] ; then \
  745. + echo "WARNING: Kernel source ${KERNELSRC} has already been patched with openswan, out of tree build might fail!"; \
  746. + fi;
  747. + @if [ -f ${KERNELSRC}/README.openswan-2 ] ; then \
  748. + echo "WARNING: Kernel source ${KERNELSRC} has already been patched with openswan-2, out of tree build might fail!"; \
  749. + fi;
  750. + @if [ -f ${KERNELSRC}/README.freeswan ] ; then \
  751. + echo "ERROR: Kernel source ${KERNELSRC} has already been patched with freeswan, out of tree build will fail!"; \
  752. + fi;
  753. + @if [ -f ${KERNELSRC}/Rules.make ] ; then \
  754. + echo "Building module for a 2.4 kernel"; ${MAKE} module24 ; \
  755. + else echo "Building module for a 2.6 kernel"; ${MAKE} module26; \
  756. + fi;
  757. +
  758. +modclean moduleclean:
  759. + @if [ -f ${KERNELSRC}/Rules.make ] ; then \
  760. + echo "Cleaning module for a 2.4 kernel"; ${MAKE} module24clean ; \
  761. + else echo "Cleaning module for a 2.6 kernel"; ${MAKE} module26clean; \
  762. + fi;
  763. +
  764. +module24:
  765. + @if [ ! -f ${KERNELSRC}/Rules.make ] ; then \
  766. + echo "Warning: Building for a 2.4 kernel in what looks like a 2.6 tree"; \
  767. + fi ; \
  768. + ${MAKE} ${MOD24BUILDDIR}/Makefile
  769. + ${MAKE} -C ${MOD24BUILDDIR} LIBRESWANSRCDIR=${LIBRESWANSRCDIR} ARCH=${ARCH} V=${V} ${MODULE_FLAGS} MODULE_DEF_INCLUDE=${MODULE_DEF_INCLUDE} TOPDIR=${KERNELSRC} -f Makefile ipsec.o
  770. + @echo
  771. + @echo '========================================================='
  772. + @echo
  773. + @echo 'KLIPS24 module built successfully. '
  774. + @echo ipsec.o is in ${MOD24BUILDDIR}
  775. + @echo
  776. + @(cd ${MOD24BUILDDIR}; ls -l ipsec.o)
  777. + @(cd ${MOD24BUILDDIR}; size ipsec.o)
  778. + @echo
  779. + @echo 'use make minstall as root to install it'
  780. + @echo
  781. + @echo '========================================================='
  782. + @echo
  783. +
  784. +mod24clean module24clean:
  785. + rm -rf ${MOD24BUILDDIR}
  786. +
  787. +#autoodetect 2.4 and 2.6
  788. +module_install minstall install-module:
  789. + @if [ -f $(KERNELSRC)/Rules.make ] ; then \
  790. + $(MAKE) minstall24 ; \
  791. + else \
  792. + $(MAKE) minstall26 ; \
  793. + fi;
  794. +
  795. +# Extract the value of MODLIB from the output of $(MAKE). Also hide
  796. +# the sup-process $(MAKE) so that GNU Make doesn't always invoke the
  797. +# target ("make -n" ignored).
  798. +#
  799. +# If $(MAKE) directly appears in a target (for instance in minstall26)
  800. +# then GNU Make will assume that it is a recursive make invocation and
  801. +# invoke the target regardless of -n.
  802. +#
  803. +# XXX: minstall24 should also use this.
  804. +
  805. +osmodlib-from-make = \
  806. + OSMODLIB=$$($(MAKE) $(1) 2>/dev/null | sed -n -e 's/^MODLIB[ :=]*\([^;]*\).*/\1/p' | head -1) ; \
  807. + test -z "$$OSMODLIB" || echo "OSMODLIB=$$OSMODLIB ($(MAKE) $(1))"
  808. +
  809. +# module-only install, with error checks
  810. +minstall24:
  811. + ( OSMODLIB=`${MAKE} -C $(KERNELSRC) -p dummy | ( sed -n -e '/^MODLIB/p' -e '/^MODLIB/q' ; cat > /dev/null ) | sed -e 's/^MODLIB[ :=]*\([^;]*\).*/\1/'` ; \
  812. + if [ -z "$$OSMODLIB" ] ; then \
  813. + OSMODLIB=`${MAKE} -C $(KERNELSRC) -n -p modules_install | ( sed -n -e '/^MODLIB/p' -e '/^MODLIB/q' ; cat > /dev/null ) | sed -e 's/^MODLIB[ :=]*\([^;]*\).*/\1/'` ; \
  814. + fi ; \
  815. + if [ -z "$$OSMODLIB" ] ; then \
  816. + echo "No known place to install module. Aborting." ; \
  817. + exit 93 ; \
  818. + fi ; \
  819. + set -x ; \
  820. + mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  821. + cp $(MOD24BUILDDIR)/ipsec.o $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  822. + if [ -f /sbin/depmod ] ; then /sbin/depmod -a ; fi; \
  823. + if [ -n "$(OSMOD_DESTDIR)" ] ; then \
  824. + mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  825. + if [ -f $$OSMODLIB/kernel/ipsec.o -a -f $$OSMODLIB/kernel/$(OSMOD_DESTDIR)/ipsec.o ] ; then \
  826. + echo "WARNING: two ipsec.o modules found in $$OSMODLIB/kernel:" ; \
  827. + ls -l $$OSMODLIB/kernel/ipsec.o $$OSMODLIB/kernel/$(OSMOD_DESTDIR)/ipsec.o ; \
  828. + exit 1; \
  829. + fi ; \
  830. + fi ; \
  831. + set -x ) ;
  832. +
  833. +
  834. +else
  835. +module:
  836. + echo 'Building in place is no longer supported. Please set MOD24BUILDDIR='
  837. + exit 1
  838. +
  839. +endif
  840. +
  841. +# module-only building, with error checks
  842. +ifneq ($(strip $(MODBUILDDIR)),)
  843. +${MODBUILDDIR}/Makefile : ${LIBRESWANSRCDIR}/packaging/makefiles/module.make
  844. + mkdir -p ${MODBUILDDIR}
  845. + echo ln -s -f ${LIBRESWANSRCDIR}/linux/net/ipsec/des/*.S ${MODBUILDDIR}
  846. + (rm -f ${MODBUILDDIR}/des; mkdir -p ${MODBUILDDIR}/des && cd ${MODBUILDDIR}/des && ln -s -f ${LIBRESWANSRCDIR}/linux/net/ipsec/des/* . && ln -s -f Makefile.fs2_6 Makefile)
  847. + (rm -f ${MODBUILDDIR}/aes; mkdir -p ${MODBUILDDIR}/aes && cd ${MODBUILDDIR}/aes && ln -s -f ${LIBRESWANSRCDIR}/linux/net/ipsec/aes/* . && ln -s -f Makefile.fs2_6 Makefile)
  848. + mkdir -p ${MODBUILDDIR}/aes
  849. + cp ${LIBRESWANSRCDIR}/packaging/makefiles/module.make ${MODBUILDDIR}/Makefile
  850. + ln -s -f ${LIBRESWANSRCDIR}/linux/net/ipsec/match*.S ${MODBUILDDIR}
  851. +
  852. +module26:
  853. + @if [ -f ${KERNELSRC}/Rules.make ] ; then \ echo "Warning: Building for a 2.6+ kernel in what looks like a 2.4 tree"; \
  854. + fi ; \
  855. + ${MAKE} ${MODBUILDDIR}/Makefile
  856. + ${MAKE} -C ${KERNELSRC} ${KERNELBUILDMFLAGS} BUILDDIR=${MODBUILDDIR} SUBDIRS=${MODBUILDDIR} INITSYSTEM=$(INITSYSTEM) MODULE_DEF_INCLUDE=${MODULE_DEF_INCLUDE} MODULE_DEFCONFIG=${MODULE_DEFCONFIG} MODULE_EXTRA_INCLUDE=${MODULE_EXTRA_INCLUDE} ARCH=${ARCH} V=${V} modules
  857. + @echo
  858. + @echo '========================================================='
  859. + @echo
  860. + @echo 'KLIPS module built successfully. '
  861. + @echo ipsec.ko is in ${MODBUILDDIR}
  862. + @echo
  863. + @(cd ${MODBUILDDIR}; ls -l ipsec.ko)
  864. + @(cd ${MODBUILDDIR}; size ipsec.ko)
  865. + @echo
  866. + @echo 'use make minstall as root to install it'
  867. + @echo
  868. + @echo '========================================================='
  869. + @echo
  870. +
  871. +mod26clean module26clean:
  872. + rm -rf ${MODBUILDDIR}
  873. +
  874. +# module-only install, with error checks
  875. +minstall26:
  876. + $(call osmodlib-from-make,-C $(KERNELSRC) -p help) ; \
  877. + if [ -z "$$OSMODLIB" ] ; then \
  878. + $(call osmodlib-from-make,-C $(KERNELSRC) -n -p modules_install) ; \
  879. + fi ; \
  880. + if [ -z "$$OSMODLIB" ] ; then \
  881. + echo "No known place to install module. Aborting." ; \
  882. + exit 93 ; \
  883. + fi ; \
  884. + set -x ; \
  885. + mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  886. + cp $(MODBUILDDIR)/ipsec.ko $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  887. + if [ -f /sbin/depmod ] ; then \
  888. + /sbin/depmod -a ; \
  889. + fi ; \
  890. + if [ -n "$(OSMOD_DESTDIR)" ] ; then \
  891. + mkdir -p $$OSMODLIB/kernel/$(OSMOD_DESTDIR) ; \
  892. + if [ -f $$OSMODLIB/kernel/ipsec.ko -a -f $$OSMODLIB/kernel/$(OSMOD_DESTDIR)/ipsec.ko ] ; then \
  893. + echo "WARNING: two ipsec.ko modules found in $$OSMODLIB/kernel:" ; \
  894. + ls -l $$OSMODLIB/kernel/ipsec.ko $$OSMODLIB/kernel/$(OSMOD_DESTDIR)/ipsec.ko ; \
  895. + exit 1; \
  896. + fi ; \
  897. + fi
  898. +
  899. +
  900. +else
  901. +module26:
  902. + echo 'Building in place is no longer supported. Please set MODBUILDDIR='
  903. + exit 1
  904. +
  905. +endif
  906. +
  907. +# kernel install, with error checks
  908. +kinstall:
  909. + rm -f out.kinstall
  910. + >out.kinstall
  911. + # undocumented kernel folklore: modules_install must precede install (observed on RHL8.0)
  912. + @if egrep -q '^CONFIG_MODULES=y' $(KCFILE) ; \
  913. + then set -x ; \
  914. + ( cd $(KERNELSRC) ; \
  915. + $(MAKE) $(KERNMAKEOPTS) modules_install 2>&1 ) | tee -a out.kinstall ; \
  916. + fi
  917. + ( cd $(KERNELSRC) ; $(MAKE) $(KERNMAKEOPTS) install ) 2>&1 | tee -a out.kinstall
  918. + ${ERRCHECK} out.kinstall
  919. +
  920. +kernelpatch3 kernelpatch3.5 kernelpatch2.6 kernelpatch:
  921. + packaging/utils/kernelpatch 2.6
  922. +
  923. +kernelpatch2.4:
  924. + packaging/utils/kernelpatch 2.4
  925. +
  926. +nattpatch:
  927. + if [ -f ${KERNELSRC}/Makefile ]; then \
  928. + ${MAKE} nattpatch${KERNELREL}; \
  929. + else echo "Cannot determine Linux kernel version. Perhaps you need to set KERNELSRC? (eg: export KERNELSRC=/usr/src/linux-`uname -r`/)"; exit 1; \
  930. + fi;
  931. +
  932. +sarefpatch2.6:
  933. + #cat patches/kernel/2.6.38/0001-SAREF-add-support-for-SA-selection-through-sendmsg.patch
  934. + #packaging/utils/sarefpatch 2.6
  935. + echo ""
  936. +
  937. +nattpatch2.6:
  938. + packaging/utils/nattpatch 2.6
  939. +
  940. +nattpatch2.4:
  941. + packaging/utils/nattpatch 2.4
  942. +
  943. +nattupdate:
  944. + (cd UMLPOOL && diff -u plain26/net/ipv4/udp.c.orig plain26/net/ipv4/udp.c; exit 0) >nat-t/net/ipv4/udp.c.os2_6.patch
  945. +
  946. +# take all the patches out of the kernel
  947. +# (Note, a couple of files are modified by non-patch means; they are
  948. +# included in "make backup".)
  949. +unpatch:
  950. + @echo \"make unpatch\" is obsolete. See make unapplypatch.
  951. + exit 1
  952. +
  953. +_unpatch:
  954. + for f in `find $(KERNELSRC)/. -name '*.preipsec' -print` ; \
  955. + do \
  956. + echo "restoring $$f:" ; \
  957. + dir=`dirname $$f` ; \
  958. + core=`basename $$f .preipsec` ; \
  959. + cd $$dir ; \
  960. + mv -f $$core.preipsec $$core ; \
  961. + rm -f $$core.wipsec $$core.ipsecmd5 ; \
  962. + done