xref: /freebsd/crypto/openssl/BSDmakefile (revision d9cc3d558d00ee7f62dbef2032f099033c91d2a1)
1# This BSD makefile helps provide a deterministic means of doing a "clean"
2# vendor import of OpenSSL.
3#
4# Recommended use:
5#
6#   % make clean
7#   % make all
8
9NO_OBJ=
10
11LCRYPTO_SRC=	${SRCTOP}/crypto/openssl
12LCRYPTO_DOC=	${LCRYPTO_SRC}/doc
13
14CAT?=		/bin/cat
15CC?=		cc
16GMAKE?=		gmake
17LD?=		ld
18MV?=		/bin/mv
19PERL?=		perl
20SETENVI=	/usr/bin/env -i
21
22BN_CONF_H=		include/crypto/bn_conf.h
23BN_CONF_H_ORIG=		${BN_CONF_H}.orig
24CONFIGURATION_H=	include/openssl/configuration.h
25CONFIGURATION_H_ORIG=	${CONFIGURATION_H}.orig
26
27.PHONY: configure patch all
28.ORDER: configure patch all
29
30LOCALBASE=	/usr/local
31WRK_ENV=	CC=${CC} \
32		LD=${LD} \
33		PATH=${LOCALBASE}/bin:/bin:/usr/bin
34
35configure:
36	@(cd ${.CURDIR} && ${SETENVI} \
37	    ${WRK_ENV} \
38	    ${PERL} ./Configure \
39	    disable-aria \
40	    disable-egd \
41	    disable-idea \
42	    disable-mdc2 \
43	    disable-sm2 \
44	    disable-sm3 \
45	    disable-sm4 \
46	    enable-ec_nistp_64_gcc_128 \
47	    enable-ktls \
48	    enable-sctp \
49	    --openssldir=etc \
50	    --prefix=/usr)
51	@echo "Building configdata.pm for later use."
52	@(cd ${.CURDIR} && \
53	    ${SETENVI} ${WRK_ENV} ${GMAKE} -j ${.MAKE.JOBS} configdata.pm)
54
55	@echo "Populating Makefile.version with release information"
56	@(cd ${LCRYPTO_SRC} && ${SETENVI} ${WRK_ENV} ${PERL} \
57	     ${LCRYPTO_SRC}/freebsd/dump_version_from_configdata.pl > \
58	     ${SRCTOP}/secure/lib/libcrypto/Makefile.version)
59
60all: patch
61	@echo "==> Building generated files (headers, manpages, etc)"
62	@(cd ${.CURDIR} && \
63	     ${SETENVI} ${WRK_ENV} ${GMAKE} -j ${.MAKE.JOBS} build_all_generated)
64
65	# 1. Fix --prefix.
66	#    a. Not sure why --prefix isn't honored properly, even though it's
67	#       passed to Configure; the files might be getting rebuilt
68	#       post-Configure, somehow.
69	# 2. Remove duplicate path in CFLAGS.
70	# 3. Remove duplicate path in includedir(s).
71	@echo "==> Fixing pkgconfig files"
72	@find . -name \*.pc -print -exec sed -i '' -E \
73	    -e 's,^prefix=.+,prefix=/usr,' \
74	    -e 's,[[:space:]]+(\-I)?\$\{prefix\}/\./include[[:space:]]*,,g' \
75	    {} +
76
77	@echo "==> Cleaning / rebuilding ASM"
78	@(cd ${SRCTOP}/secure/lib/libcrypto && \
79	     ${SETENVI} ${WRK_ENV} ${MAKE} cleanasm && \
80	     ${SETENVI} ${WRK_ENV} ${MAKE} buildasm)
81
82	@echo "==> Syncing manpages (section 1)"
83	@rsync -a --delete \
84	    --exclude 'Makefile*' --exclude '*.1' \
85	    ${LCRYPTO_DOC}/man/ \
86	    ${SRCTOP}/secure/lib/libcrypto/man
87
88	@echo "==> Syncing manpages (sections {3,5,7})"
89	@rsync -a --delete \
90	    --exclude 'Makefile*' --exclude '*.[357]' \
91	    ${LCRYPTO_DOC}/man/man1/ \
92	    ${SRCTOP}/secure/usr.bin/openssl/man
93
94
95# This doesn't use standard patching since the generated files can vary
96# depending on the host architecture.
97patch: configure
98	# Spam arch-specific overrides to config files.
99	@echo "==> Patching headers"
100	@(cd ${.CURDIR} && ${SETENVI} ${WRK_ENV} ${GMAKE} ${BN_CONF_H} && \
101	 ${MV} ${BN_CONF_H} ${BN_CONF_H_ORIG} && \
102	 ${CAT} ${BN_CONF_H}.orig \
103	     ${LCRYPTO_SRC}/freebsd/${BN_CONF_H} >> \
104	     ${BN_CONF_H})
105
106	@(cd ${.CURDIR} && \
107	  ${MV} ${CONFIGURATION_H} ${CONFIGURATION_H_ORIG} && \
108	  ${CAT} ${CONFIGURATION_H_ORIG} \
109	     ${LCRYPTO_SRC}/freebsd/${CONFIGURATION_H} >> \
110	     ${CONFIGURATION_H})
111
112
113clean: .PHONY
114	@(cd ${.CURDIR} && rm -f ${BN_CONF_H_ORIG} ${CONFIGURATION_H_ORIG})
115
116	@(cd ${SRCTOP}/secure/lib/libcrypto && \
117	    ${SETENVI} ${WRK_ENV} ${MAKE} cleanasm)
118
119	-@(cd ${.CURDIR} && ${GMAKE} ${.TARGET})
120
121.include <sys.mk>
122