1# hints/openbsd.sh
2#
3# hints file for OpenBSD; Todd Miller <millert@openbsd.org>
4# Edited to allow Configure command-line overrides by
5#  Andy Dougherty <doughera@lafayette.edu>
6#
7# To build with distribution paths, use:
8#	./Configure -des -Dopenbsd_distribution=defined
9#
10
11# OpenBSD has a better malloc than perl...
12test "$usemymalloc" || usemymalloc='n'
13
14# malloc wrap works
15case "$usemallocwrap" in
16'') usemallocwrap='define' ;;
17esac
18
19# Currently, vfork(2) is not a real win over fork(2).
20usevfork="$undef"
21
22# In OpenBSD < 3.3, the setre?[ug]id() are emulated using the
23# _POSIX_SAVED_IDS functionality which does not have the same
24# semantics as 4.3BSD.  Starting with OpenBSD 3.3, the original
25# semantics have been restored.
26case "$osvers" in
27[0-2].*|3.[0-2])
28	d_setregid=$undef
29	d_setreuid=$undef
30	d_setrgid=$undef
31	d_setruid=$undef
32esac
33
34# OpenBSD 5.5 on has 64 bit time_t
35case "$osvers" in
36[0-4].*|5.[0-4]) ;;
37*)
38	cppflags="$cppflags -DBIG_TIME"
39	;;
40esac
41
42#
43# Not all platforms support dynamic loading...
44# For the case of "$openbsd_distribution", the hints file
45# needs to know whether we are using dynamic loading so that
46# it can set the libperl name appropriately.
47# Allow command line overrides.
48#
49ARCH=`arch | sed 's/^OpenBSD.//'`
50case "${ARCH}-${osvers}" in
51alpha-2.[0-8]|mips-2.[0-8]|powerpc-2.[0-7]|m88k-[2-4].*|m88k-5.[0-2]|hppa-3.[0-5]|vax-*)
52	test -z "$usedl" && usedl=$undef
53	;;
54*)
55	test -z "$usedl" && usedl=$define
56	# We use -fPIC here because -fpic is *NOT* enough for some of the
57	# extensions like Tk on some OpenBSD platforms (ie: sparc)
58	PICFLAG=-fPIC
59	if [ -e /usr/share/mk/bsd.own.mk ]; then
60		PICFLAG=`make -f /usr/share/mk/bsd.own.mk -V PICFLAG`
61	fi
62	cccdlflags="-DPIC ${PICFLAG} $cccdlflags"
63	case "$osvers" in
64	[01].*|2.[0-7]|2.[0-7].*)
65		lddlflags="-Bshareable $lddlflags"
66		;;
67	2.[8-9]|3.0)
68		ld=${cc:-cc}
69		lddlflags="-shared -fPIC $lddlflags"
70		;;
71	*) # from 3.1 onwards
72		ld=${cc:-cc}
73		lddlflags="-shared ${PICFLAG} $lddlflags"
74		libswanted=`echo $libswanted | sed 's/ dl / /'`
75		;;
76	esac
77
78	# We need to force ld to export symbols on ELF platforms.
79	# Without this, dlopen() is crippled.
80	ELF=`${cc:-cc} -dM -E - </dev/null | grep __ELF__`
81	test -n "$ELF" && ldflags="-Wl,-E $ldflags"
82	;;
83esac
84
85#
86# Tweaks for various versions of OpenBSD
87#
88case "$osvers" in
892.5)
90	# OpenBSD 2.5 has broken odbm support
91	i_dbm=$undef
92	;;
93esac
94
95# OpenBSD doesn't need libcrypt but many folks keep a stub lib
96# around for old NetBSD binaries.
97libswanted=`echo $libswanted | sed 's/ crypt / /'`
98
99# OpenBSD hasn't ever needed linking to libutil
100libswanted=`echo $libswanted | sed 's/ util / /'`
101
102# Configure can't figure this out non-interactively
103d_suidsafe=$define
104
105# cc is gcc so we can do better than -O
106# Allow a command-line override, such as -Doptimize=-g
107case "${ARCH}-${osvers}" in
108hppa-3.3|m88k-2.*|m88k-3.[0-3])
109   test "$optimize" || optimize='-O0'
110   ;;
111m88k-3.4)
112   test "$optimize" || optimize='-O1'
113   ;;
114*)
115   test "$optimize" || optimize='-O2'
116   ;;
117esac
118
119#
120# Unaligned access on alpha with -ftree-ter
121# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59679
122# More details
123# https://rt.perl.org/Public/Bug/Display.html?id=120888
124#
125case "${ARCH}-${osvers}" in
126    alpha-*)
127    ccflags="-fno-tree-ter $ccflags"
128    ;;
129esac
130
131# Special per-arch specific ccflags
132case "${ARCH}-${osvers}" in
133    vax-*)
134    ccflags="-DUSE_PERL_ATOF=0 $ccflags"
135    ;;
136esac
137
138# This script UU/usethreads.cbu will get 'called-back' by Configure 
139# after it has prompted the user for whether to use threads.
140cat > UU/usethreads.cbu <<'EOCBU'
141case "$usethreads" in
142$define|true|[yY]*)
143	# any openbsd version dependencies with pthreads?
144	ccflags="-pthread $ccflags"
145	ldflags="-pthread $ldflags"
146	case "$osvers" in
147	[0-2].*|3.[0-2])
148		# Change from -lc to -lc_r
149		set `echo "X $libswanted " | sed 's/ c / c_r /'`
150		shift
151		libswanted="$*"
152	;;
153	esac
154	case "$osvers" in
155	[012].*|3.[0-6])
156        	# Broken up to OpenBSD 3.6, fixed in OpenBSD 3.7
157		d_getservbyname_r=$undef ;;
158	esac
159	;;
160*)
161	libswanted=`echo $libswanted | sed 's/ pthread / /'`
162esac
163EOCBU
164
165# When building in the OpenBSD tree we use different paths
166# This is only part of the story, the rest comes from config.over
167case "$openbsd_distribution" in
168''|$undef|false) ;;
169*)
170	# We put things in /usr, not /usr/local
171	prefix='/usr'
172	prefixexp='/usr'
173	sysman='/usr/share/man/man1'
174	libpth='/usr/lib'
175	glibpth='/usr/lib'
176	# Local things, however, do go in /usr/local
177	siteprefix='/usr/local'
178	siteprefixexp='/usr/local'
179	# Ports installs non-std libs in /usr/local/lib so look there too
180	locincpth=''
181	loclibpth=''
182	# Link perl with shared libperl
183	if [ "$usedl" = "$define" -a -r $src/shlib_version ]; then
184		useshrplib=true
185		libperl=`. $src/shlib_version; echo libperl.so.${major}.${minor}`
186	fi
187	;;
188esac
189
190# openbsd has a problem regarding newlocale()
191# https://marc.info/?l=openbsd-bugs&m=155364568608759&w=2
192# which is being fixed.  In the meantime, forbid POSIX 2008 locales
193d_newlocale="$undef"
194
195# OpenBSD's locale support is not that complete yet
196ccflags="-DNO_LOCALE_NUMERIC -DNO_LOCALE_COLLATE $ccflags"
197
198# Seems that OpenBSD returns bogus values in _Thread_local variables in code in
199# shared objects, so we need to disable it. See GH #19109
200d_thread_local=undef
201
202# end
203