1PORTNAME=	tor
2DISTVERSION=	0.4.9.7
3CATEGORIES=	security net
4MASTER_SITES=	TOR
5
6MAINTAINER=	ports@MidnightBSD.org
7COMMENT=	Anonymizing overlay network for TCP
8WWW=		https://www.torproject.org/
9
10LICENSE=	bsd3
11
12USES=		compiler:c11 cpe gmake pkgconfig
13
14CPE_VENDOR=	torproject
15GNU_CONFIGURE=	yes
16GNU_CONFIGURE_MANPREFIX=${PREFIX}/share
17CONFIGURE_ARGS=	--with-openssl-dir="${OPENSSLBASE}"
18CONFIGURE_ENV=	TOR_CPPFLAGS_libevent="-I${LOCALBASE}/include" \
19		TOR_LDFLAGS_libevent="-L${LOCALBASE}/lib/" \
20		TOR_LIBEVENT_LIBS="${TOR_LIBEVENT_LIBS}"
21
22OPTIONS_DEFINE=	DOCS MANPAGES POW STATIC_TOR TCMALLOC
23OPTIONS_GROUP=	COMPRESSION TRACING
24OPTIONS_GROUP_COMPRESSION=	ZSTD LZMA
25OPTIONS_GROUP_TRACING=	LTTNG USDT LOG_DEBUG
26OPTIONS_DEFAULT=	MANPAGES POW LZMA ZSTD
27OPTIONS_SUB=	yes
28STATIC_TOR_DESC=	Build a static tor
29COMPRESSION_DESC=	Supported compression libraries
30TRACING_DESC=		Tracing
31
32USE_RC_SUBR=	tor
33SUB_FILES=	pkg-message
34SUB_LIST=	USER="${USERS}" GROUP="${GROUPS}"
35PLIST_SUB=	USER="${USERS}" GROUP="${GROUPS}"
36
37GROUPS=		_tor
38USERS=		_tor
39
40CONFLICTS_INSTALL=	tor-devel
41
42POW_DESC=		Enable PoW (Proof of Work) module (licence changes to GPL)
43POW_CONFIGURE_ENABLE=	gpl # gpl enables POW
44
45STATIC_TOR_USES=	ssl:build
46STATIC_TOR_USES_OFF=	ssl
47
48# compression options
49ZSTD_CONFIGURE_ENABLE=		zstd
50ZSTD_CONFIGURE_ENV=TOR_ZSTD_LIBS="${TOR_ZSTD_LIBS}"
51LZMA_CONFIGURE_ENABLE=		lzma
52
53# tracing options
54LTTNG_DESC=			Build with LTTng-UST instrumentation
55LTTNG_USES=			localbase
56LTTNG_CONFIGURE_ENABLE=		tracing-instrumentation-lttng
57LTTNG_LIB_DEPENDS=		liblttng-ust.so:sysutils/lttng-ust
58USDT_DESC=			Build with tracing USDT instrumentation
59USDT_CONFIGURE_ENABLE=		tracing-instrumentation-usdt
60USDT_LIB_DEPENDS=		liblttng-ust.so:sysutils/lttng-ust
61USDT_BROKEN=			error: use of undeclared identifier 'tor_circuit': https://gitlab.torproject.org/tpo/core/tor/-/issues/40174#note_2714275
62LOG_DEBUG_DESC=			Build with tracing event to debug log
63LOG_DEBUG_CONFIGURE_ENABLE=	tracing-instrumentation-log-debug
64
65.include <bsd.mport.options.mk>
66
67.if ${PORT_OPTIONS:MDOCS} || ${PORT_OPTIONS:MMANPAGES}
68BUILD_DEPENDS+=	asciidoc:textproc/asciidoc
69.else
70CONFIGURE_ARGS+=	--disable-asciidoc
71.endif
72
73.if ${PORT_OPTIONS:MPOW}
74LICENSE=	gpl3
75.else
76LICENSE_FILE=	${WRKSRC}/LICENSE # BSD license file
77.endif
78
79.if !defined(USE_GCC) && \
80empty(PORT_OPTIONS:MSTATIC_TOR)
81CONFIGURE_ARGS+=	--enable-gcc-hardening
82.else
83CONFIGURE_ARGS+=	--disable-gcc-hardening
84.endif
85
86.if ${PORT_OPTIONS:MSTATIC_TOR}
87BUILD_DEPENDS +=	${LOCALBASE}/lib/libevent.a:devel/libevent
88CONFIGURE_ARGS+=	--enable-static-tor \
89			--with-zlib-dir=/usr/lib --disable-linker-hardening
90TOR_LIBEVENT_LIBS=	${LOCALBASE}/lib/libevent.a
91.  if ${PORT_OPTIONS:MZSTD}
92BUILD_DEPENDS+=		${LOCALBASE}/lib/libzstd.a:archivers/zstd
93TOR_ZSTD_LIBS=		${LOCALBASE}/lib/libzstd.a
94LDFLAGS+=		-lelf # needed by libexecinfo.a
95.  endif
96.else
97CONFIGURE_ARGS+=	--enable-linker-hardening
98LIB_DEPENDS+=		libevent.so:devel/libevent
99TOR_LIBEVENT_LIBS=	-levent
100.  if ${PORT_OPTIONS:MZSTD}
101LIB_DEPENDS+=		libzstd.so:archivers/zstd
102TOR_ZSTD_LIBS=		-lzstd
103.  endif
104.endif
105
106.if ${PORT_OPTIONS:MTCMALLOC}
107CONFIGURE_ARGS+=	--with-malloc=tcmalloc
108.if ${PORT_OPTIONS:MSTATIC_TOR}
109BUILD_DEPENDS+=		${LOCALBASE}/lib/libtcmalloc.a:devel/google-perftools # for static 'tor' executable
110RUN_DEPENDS+=		google-perftool>0:devel/google-perftools # for a still-dynamic 'tor-gencert' executable
111LDFLAGS+=		-lc++ -lm # required by libtcmalloc.a and isn't cocered by google-perftools' `pkg-config --libs libtcmalloc` output
112.else
113LIB_DEPENDS+=		libtcmalloc.so:devel/google-perftools
114.endif
115.endif
116
117post-patch:
118	@${REINPLACE_CMD} -E -e "s@(-z) (relro|now)@-Wl,\1,\2@g" \
119		${WRKSRC}/configure
120	@${REINPLACE_CMD} -e 's|lib/tor|db/tor|' \
121		${WRKSRC}/src/config/torrc.*.in \
122		${WRKSRC}/doc/man/tor.1.* \
123		${WRKSRC}/doc/man/tor.html.in
124
125post-install:
126	@${MKDIR} ${FAKE_DESTDIR}/var/log/tor ${FAKE_DESTDIR}/var/run/tor ${FAKE_DESTDIR}/var/db/tor
127
128.include <bsd.port.mk>
129