Blame project/config/cfgdefs.sh

f8089b
# in projects where [ $mb_use_custom_cfgdefs = yes ],
f8089b
# cfgdefs.sh is invoked from within ./configure via
f8089b
# . $mb_project_dir/project/cfgdefs.sh
f8089b
f8089b
# a successful return from cfgdefs.sh will be followed
f8089b
# by a second invocation of the config_copy() function,
f8089b
# reflecting any changes to common config variables
f8089b
# made by cfgdefs.sh.
f8089b
f8089b
# finally, cfgdefs.sh may update the contents of the
f8089b
# config-time generated cfgdefs.mk.
f8089b
f8089b
f8089b
# cfgdefs helper functions
f8089b
. "$mb_project_dir/project/config/cfghost.sh"
f8089b
f8089b
f8089b
# sofort's config test framework
2f49aa
. "$mb_project_dir/sofort/cfgtest/cfgtest.sh"
f8089b
f8089b
b6fc94
pycfg_pydebug=
b6fc94
pycfg_pymalloc=
b6fc94
f8089b
for arg ; do
f8089b
	case "$arg" in
b6fc94
		--with-pydebug )
b6fc94
			pycfg_pydebug='d' ;;
b6fc94
b6fc94
		--without-pydebug )
b6fc94
			pycfg_pydebug= ;;
b6fc94
b6fc94
		--with-pymalloc )
b6fc94
			pycfg_pymalloc='m' ;;
b6fc94
b6fc94
		--without-pymalloc )
b6fc94
			pycfg_pymalloc= ;;
b6fc94
f8089b
		*)
f8089b
			error_msg ${arg#}: "unsupported config argument."
f8089b
			exit 2
f8089b
	esac
f8089b
done
f8089b
f8089b
db1f1a
cfgdefs_set_python_prefix()
db1f1a
{
db1f1a
	if [ -z "$mb_prefix" ]; then
db1f1a
		mb_prefix='/.'
db1f1a
	fi
db1f1a
db1f1a
	if [ -z "$mb_exec_prefix" ]; then
db1f1a
		mb_exec_prefix='/.'
db1f1a
	fi
db1f1a
}
db1f1a
db1f1a
f8089b
cfgdefs_set_cfghost_flavors()
f8089b
{
f8089b
	cfghost_set_target_cfghost
f8089b
	cfghost_set_native_cfghost
f8089b
}
f8089b
f8089b
8d7c97
cfgdefs_detect_python_version()
8d7c97
{
8d7c97
	mb_internal_verinfo=$(mktemp)
8d7c97
8d7c97
	if [ -z "$mb_internal_verinfo" ]; then
8d7c97
		exit 2
8d7c97
	fi
8d7c97
8d7c97
	"$mb_native_cc" -E -dM "$mb_source_dir/Include/patchlevel.h" \
8d7c97
		> "$mb_internal_verinfo"
8d7c97
8d7c97
	python_major=$(grep '#define PY_MAJOR_VERSION ' "$mb_internal_verinfo" | cut -d' ' -f3)
8d7c97
	python_minor=$(grep '#define PY_MINOR_VERSION ' "$mb_internal_verinfo" | cut -d' ' -f3)
8d7c97
	python_micro=$(grep '#define PY_MICRO_VERSION ' "$mb_internal_verinfo" | cut -d' ' -f3)
8d7c97
8d7c97
	if [ -z "$python_major" ] || [ -z "$python_minor" ] || [ -z "$python_micro" ]; then
8d7c97
		error_msg "Could not properly parse Python's patchlevel.h"
8d7c97
		exit 2
8d7c97
	fi
8d7c97
8d7c97
	python_ver="$python_major.$python_minor"
8d7c97
8d7c97
	[ -z "$mb_package"  ] && mb_package='python'"$python_ver"
8d7c97
	[ -z "$mb_nickname" ] && mb_nickname="$mb_package"
8d7c97
	[ -z "$mb_pkgname"  ] && mb_pkgname="$mb_package"
8d7c97
	[ -z "$mb_pkgdesc"  ] && mb_pkgdesc="$mb_package"
8d7c97
}
8d7c97
8d7c97
b6fc94
cfgdefs_set_option_variables()
b6fc94
{
b6fc94
	python_abifl=$pycfg_pydebug$pycfg_pymalloc
b6fc94
}
b6fc94
b6fc94
b6fc94
cfgdefs_output_options()
b6fc94
{
b6fc94
	if [ -n "$pycfg_pydebug" ]; then
b6fc94
		cfgtest_cflags_append '-DPy_DEBUG'
b6fc94
	fi
b6fc94
b6fc94
	if [ -n "$pycfg_pymalloc" ]; then
b6fc94
		cfgtest_cflags_append '-DWITH_PYMALLOC'
b6fc94
	fi
b6fc94
}
b6fc94
b6fc94
8d7c97
cfgdefs_output_custom_defs()
8d7c97
{
8d7c97
	sed \
8d7c97
			-e 's/@python_ver@/'"$python_ver"'/g'       \
8d7c97
			-e 's/@python_major@/'"$python_major"'/g'   \
8d7c97
			-e 's/@python_minor@/'"$python_minor"'/g'   \
8d7c97
			-e 's/@python_micro@/'"$python_micro"'/g'   \
b6fc94
			-e 's/@python_abifl@/'"$python_abifl"'/g'   \
8d7c97
		"$mb_project_dir/project/config/cfgdefs.in"         \
fee9e4
	| sed -e 's/[ \t]*$//g'                                     \
8d7c97
			>> "$mb_pwd/cfgdefs.mk"
8d7c97
}
8d7c97
8d7c97
bacfcf
cfgdefs_perform_common_tests()
f8089b
{
f8089b
	# headers
998eeb
	cfgtest_header_absence  'stropts.h'
e9a8e5
	cfgtest_header_presence 'stdatomic.h'
998eeb
	cfgtest_header_presence 'endian.h'
998eeb
	cfgtest_header_presence 'net/if.h'
998eeb
	cfgtest_header_presence 'sched.h'
998eeb
	cfgtest_header_presence 'sys/ioctl.h'
998eeb
	cfgtest_header_presence 'sys/sendfile.h'
998eeb
	cfgtest_header_presence 'sys/syscall.h'
998eeb
	cfgtest_header_presence 'sys/sysmacros.h'
998eeb
	cfgtest_header_presence 'sys/uio.h'
998eeb
	cfgtest_header_presence 'sys/xattr.h'
f623e2
	cfgtest_header_presence 'uuid.h'
f623e2
	cfgtest_header_presence 'uuid/uuid.h'
998eeb
998eeb
	# interfaces
998eeb
	mb_cfgtest_headers='sys/epoll.h'
998eeb
	cfgtest_interface_presence 'epoll_create1'
998eeb
998eeb
	mb_cfgtest_headers='sched.h'
998eeb
	cfgtest_interface_presence 'sched_get_priority_max'
998eeb
	cfgtest_interface_presence 'sched_rr_get_interval'
998eeb
	cfgtest_interface_presence 'sched_setaffinity'
998eeb
	cfgtest_interface_presence 'sched_setparam'
998eeb
	cfgtest_interface_presence 'sched_setscheduler'
998eeb
998eeb
	mb_cfgtest_headers='sys/sendfile.h'
998eeb
	cfgtest_interface_presence 'sendfile'
f8089b
ad39fb
	# size of system types
ad39fb
	cfgtest_newline
ad39fb
	cfgtest_comment 'size of system types'
ad39fb
ad39fb
	cfgtest_type_size 'short'
ad39fb
	cfgtest_type_size 'int'
ad39fb
	cfgtest_type_size 'long'
ad39fb
	cfgtest_type_size 'long long'
ad39fb
	cfgtest_type_size 'float'
ad39fb
	cfgtest_type_size 'double'
ad39fb
	cfgtest_type_size 'long double'
ad39fb
	cfgtest_type_size 'void *'
ad39fb
ad39fb
	mb_cfgtest_headers='stdint.h'
ad39fb
	cfgtest_type_size 'uintptr_t'
ad39fb
ad39fb
	mb_cfgtest_headers='stdbool.h'
ad39fb
	cfgtest_type_size '_Bool'
ad39fb
ad39fb
	mb_cfgtest_headers='stddef.h'
ad39fb
	cfgtest_type_size 'size_t'
ad39fb
	cfgtest_type_size 'wchar_t'
ad39fb
ad39fb
	mb_cfgtest_headers='unistd.h'
ad39fb
	cfgtest_type_size 'pid_t'
ad39fb
	cfgtest_type_size 'off_t'
ad39fb
ad39fb
	mb_cfgtest_headers='time.h'
ad39fb
	cfgtest_type_size 'time_t'
ad39fb
ad39fb
	mb_cfgtest_headers='stdio.h'
ad39fb
	cfgtest_type_size 'fpos_t'
ad39fb
ad39fb
	mb_cfgtest_headers='pthread.h'
ad39fb
	cfgtest_type_size 'pthread_t'
ad39fb
ea008a
	# toolchain
ea008a
	cfgtest_newline
ea008a
	cfgtest_comment 'toolchain'
ea008a
ea008a
	# x87
ea008a
	mb_code_snippet=''
ea008a
	mb_code_snippet="$mb_code_snippet "'void fn(void)'
ea008a
	mb_code_snippet="$mb_code_snippet "'{__asm__ __volatile__ ("fnstcw pcw");'
ea008a
	mb_code_snippet="$mb_code_snippet "' __asm__ __volatile__ ("fldcw  pcw");}'
ea008a
7d322b
	if cfgtest_code_snippet_asm "$mb_code_snippet"; then
ea008a
		cfgtest_cflags_append '-DHAVE_GCC_ASM_FOR_X87'
ea008a
	fi
ea008a
ea008a
	# x64
ea008a
	mb_code_snippet=''
ea008a
	mb_code_snippet="$mb_code_snippet "'void fn(void)'
ea008a
	mb_code_snippet="$mb_code_snippet "'{__asm__ __volatile__ ("callq *%rax");}'
ea008a
7d322b
	if cfgtest_code_snippet_asm "$mb_code_snippet"; then
ea008a
		cfgtest_cflags_append '-DHAVE_GCC_ASM_FOR_X64'
ea008a
	fi
ea008a
ea008a
	# IEEE 754: little endian / big endian
ea008a
	if $mb_cfgtest_cc -E -dM - < /dev/null \
ea008a
			| grep '__BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__' \
ea008a
			> /dev/null; then
ea008a
		cfgtest_cflags_append '-DDOUBLE_IS_LITTLE_ENDIAN_IEEE754'
ea008a
ea008a
	elif $mb_cfgtest_cc -E -dM - < /dev/null \
ea008a
			| grep '__BYTE_ORDER__ __ORDER_BIG_ENDIAN__' \
ea008a
			> /dev/null; then
ea008a
		cfgtest_cflags_append '-DDOUBLE_IS_BIG_ENDIAN_IEEE754'
ea008a
ea008a
	else
ea008a
		cfgtest_newline
ea008a
		cfgtest_comment 'cfgdefs.sh: cannot detect little/big endian,'
f546c9
		cfgtest_comment 'cfgdefs.sh: so defined both macros below.'
ea008a
		cfgtest_newline
ea008a
ea008a
		cfgtest_cflags_append '-DDOUBLE_IS_LITTLE_ENDIAN_IEEE754'
ea008a
		cfgtest_cflags_append '-DDOUBLE_IS_BIG_ENDIAN_IEEE754'
ea008a
	fi
ea008a
592c56
	# getrandom: easier to simply test,
592c56
	# than to test whether we need to test
592c56
	# (and then test).
ad39fb
	cfgtest_newline
ad39fb
	cfgtest_comment 'getrandom'
ad39fb
592c56
	mb_cfgtest_headers='sys/syscall.h'
592c56
592c56
	if cfgtest_decl_presence 'SYS_getrandom'; then
592c56
		cfgtest_cflags_append '-DHAVE_GETRANDOM_SYSCALL'
592c56
	fi
592c56
fd8688
	# libintl
fd8688
	cfgtest_newline
fd8688
	cfgtest_comment 'libintl'
fd8688
fd8688
	if cfgtest_library_presence -lintl; then
fd8688
		cfgtest_ldflags_append '-Wl,--as-needed -lintl -Wl,--no-as-needed'
fd8688
	fi
fd8688
f623e2
	# libuuid
f623e2
	cfgtest_newline
f623e2
	cfgtest_comment 'libuuid'
f623e2
f623e2
	if cfgtest_library_presence -luuid; then
f623e2
		cfgtest_ldflags_append '-Wl,--as-needed -luuid -Wl,--no-as-needed'
f623e2
	fi
f623e2
bc7614
	# ncurses
bc7614
	cfgtest_newline
bc7614
	cfgtest_comment 'ncurses/ncursesw'
bc7614
	mb_cfgtest_headers='ncurses.h'
bc7614
bc7614
	if [ $mb_cfgtest_cfgtype = 'target' ]; then
bc7614
		mb_cfgtest_makevar='CFLAGS_NCURSES'
bc7614
	else
cc78d9
		mb_cfgtest_makevar='NATIVE_CFLAGS'
bc7614
	fi
bc7614
bc7614
	cfgtest_unit_header_presence 'curses.h'
bc7614
	cfgtest_unit_header_presence 'ncurses.h'
bc7614
bc7614
	cfgtest_unit_header_presence 'ncurses/panel.h'  && mb_panel_wrapper='yes'
bc7614
	cfgtest_unit_header_presence 'ncursesw/panel.h' && mb_panel_wrapper='yes'
bc7614
bc7614
	if cfgtest_unit_interface_presence 'is_term_resized'; then
bc7614
		cfgtest_makevar_append '-DHAVE_CURSES_IS_TERM_RESIZED'
bc7614
	fi
bc7614
bc7614
	if cfgtest_unit_interface_presence 'resizeterm'; then
bc7614
		cfgtest_makevar_append '-DHAVE_CURSES_RESIZETERM'
bc7614
	fi
bc7614
bc7614
	if cfgtest_unit_interface_presence 'resize_term'; then
bc7614
		cfgtest_makevar_append '-DHAVE_CURSES_RESIZE_TERM'
bc7614
	fi
bc7614
bc7614
	# ncursesw
bc7614
	if cfgtest_unit_interface_presence 'mvwget_wch'; then
bc7614
		cfgtest_makevar_append '-DHAVE_NCURSESW'
bc7614
	fi
bc7614
f8089b
	# ncurses: python refers to members of typedef struct _win_st WINDOW
bc7614
	cfgtest_makevar_append '-DNCURSES_INTERNALS'
bc7614
bc7614
	# <panel.h>
4abd96
	if [ _${mb_panel_wrapper:-} = _yes ]; then
8e6e57
		cfgtest_makevar_append '-I$(PROJECT_DIR)/wrappers/ncurses'
bc7614
		unset mb_panel_wrapper
bc7614
	fi
f8089b
bacfcf
	# ncurses libs (common part)
f8089b
	mb_ncurses_libs='-lpanelw -lncursesw'
f8089b
	mb_ncurses_tinfo='-ltinfo'
f8089b
bc7614
	if cfgtest_library_presence $mb_ncurses_tinfo; then
bc7614
		mb_ncurses_libs="$mb_ncurses_libs $mb_ncurses_tinfo"
bc7614
	fi
bacfcf
}
bacfcf
bacfcf
bacfcf
cfgdefs_perform_target_tests()
bacfcf
{
bacfcf
	# init
bacfcf
	cfgtest_target_section
bacfcf
bacfcf
	# common tests
bacfcf
	cfgdefs_perform_common_tests
f8089b
2cf433
	# ncurses libs
2cf433
	mb_cfgtest_makevar='LDFLAGS_NCURSES_LIBS'
2cf433
	cfgtest_makevar_append $mb_ncurses_libs
2cf433
bc7614
	mb_cfgtest_makevar='LDFLAGS_NCURSES'
bc7614
	cfgtest_makevar_append \
bc7614
		'-Wl,--as-needed $(LDFLAGS_NCURSES_LIBS)' \
bc7614
		'-Wl,--no-as-needed'
bc7614
bc7614
	mb_cfgtest_makevar='LDFLAGS_NCURSES_STATIC'
bc7614
	cfgtest_makevar_append '$(LDFLAGS_NCURSES)'
bc7614
bacfcf
	# openssl
2cf433
	cfgtest_newline
2cf433
	cfgtest_comment 'openssl/libressl'
bacfcf
2cf433
	mb_cfgtest_headers='openssl/x509.h'
bacfcf
2cf433
	if cfgtest_interface_presence 'X509_NAME_ENTRY_set'; then
2cf433
		cfgtest_cflags_append '-DOPENSSL_VERSION_1_1'
2cf433
	fi
f8089b
84ca86
	# tcl/tk libc
2cf433
	cfgtest_newline
2cf433
	cfgtest_comment 'tcl/tk'
1fcff3
	mb_tcltk_libs=
2cf433
84ca86
	for mb_tcltk_ver in 8.9 8.8 8.7 8.6 8.5; do
84ca86
		if [ -z "$mb_tcltk_libs" ]; then
84ca86
			mb_tcltk_libs="-ltk$mb_tcltk_ver -ltcl$mb_tcltk_ver"
84ca86
			cfgtest_library_presence $mb_tcltk_libs \
84ca86
				|| mb_tcltk_libs=''
84ca86
		fi
84ca86
	done
84ca86
84ca86
	mb_cfgtest_makevar='LDFLAGS_TCLTK_LIBS'
84ca86
	cfgtest_makevar_append "$mb_tcltk_libs"
84ca86
f41ab1
	mb_cfgtest_makevar='CFLAGS_TCLTK'
f41ab1
	cfgtest_makevar_append '-DWITH_APPINIT'
f41ab1
f41ab1
	mb_cfgtest_makevar='LDFLAGS_TCLTK'
f41ab1
	cfgtest_makevar_append '$(LDFLAGS_TCLTK_LIBS)'
f41ab1
c403d0
	# sqlite
c403d0
	cfgtest_newline
c403d0
	cfgtest_comment 'sqlite3'
c403d0
c403d0
	mb_cfgtest_makevar='CFLAGS_SQLITE'
c403d0
	cfgtest_makevar_append '-DMODULE_NAME=\"sqlite3\"'
c403d0
	cfgtest_makevar_append '-DSQLITE_OMIT_LOAD_EXTENSION'
c403d0
c403d0
	mb_cfgtest_makevar='LDFLAGS_SQLITE'
c403d0
	cfgtest_makevar_append '-lsqlite3'
c403d0
c403d0
	mb_cfgtest_makevar='LDFLAGS_SQLITE_STATIC'
c403d0
	cfgtest_makevar_append '$(LDFLAGS_SQLITE)'
c403d0
6a10b3
	# expat
6a10b3
	cfgtest_newline
6a10b3
	cfgtest_comment 'expat'
6a10b3
6a10b3
	mb_cfgtest_makevar='CFLAGS_EXPAT'
6a10b3
	cfgtest_makevar_append '-DXML_DEV_URANDOM'
6a10b3
6a10b3
	mb_cfgtest_makevar='LDFLAGS_EXPAT'
6a10b3
	cfgtest_makevar_append '-lexpat'
6a10b3
6a10b3
	mb_cfgtest_makevar='LDFLAGS_EXPAT_STATIC'
6a10b3
	cfgtest_makevar_append '$(LDFLAGS_EXPAT)'
6a10b3
84f4cd
	# ndbm
84f4cd
	cfgtest_newline
84f4cd
	cfgtest_comment 'ndbm'
84f4cd
84f4cd
	mb_cfgtest_makevar='CFLAGS_DBM'
84f4cd
	cfgtest_unit_header_presence 'ndbm.h'
84f4cd
84f4cd
	mb_cfgtest_makevar='LDFLAGS_DBM'
84f4cd
	cfgtest_makevar_append '-lgdbm_compat'
84f4cd
84f4cd
	mb_cfgtest_makevar='LDFLAGS_DBM_STATIC'
84f4cd
	cfgtest_makevar_append '$(LDFLAGS_DBM)'
84f4cd
577c05
	# static python library switches
577c05
	cfgtest_newline
577c05
	cfgtest_comment 'static python library switches'
577c05
	mb_cfgtest_makevar='LDFLAGS_PYEXT_STATIC'
577c05
577c05
	cfgtest_makevar_append '-Wl,--as-needed -lssl -lcrypto -Wl,--no-as-needed'
f623e2
	cfgtest_makevar_append '-Wl,--as-needed -luuid         -Wl,--no-as-needed'
577c05
	cfgtest_makevar_append '-Wl,--as-needed -lbz2          -Wl,--no-as-needed'
577c05
	cfgtest_makevar_append '-Wl,--as-needed -lffi          -Wl,--no-as-needed'
577c05
	cfgtest_makevar_append '-Wl,--as-needed -lgdbm         -Wl,--no-as-needed'
577c05
	cfgtest_makevar_append '-Wl,--as-needed -lreadline     -Wl,--no-as-needed'
577c05
	cfgtest_makevar_append '-Wl,--as-needed -lintl         -Wl,--no-as-needed'
577c05
	cfgtest_makevar_append '-Wl,--as-needed -lz            -Wl,--no-as-needed'
577c05
577c05
	[ $python_major = '3' ] && \
23670a
	cfgtest_makevar_append '-Wl,--as-needed -llzma         -Wl,--no-as-needed'
577c05
b6fc94
	# options
b6fc94
	cfgtest_newline
b6fc94
	cfgtest_comment 'target options'
b6fc94
	cfgdefs_output_options
b6fc94
f8089b
	# pretty cfgdefs.mk
f8089b
	cfgtest_newline
f8089b
}
f8089b
f8089b
f8089b
cfgdefs_perform_native_tests()
f8089b
{
f8089b
	# init
f8089b
	cfgtest_native_section
f8089b
bacfcf
	# common tests
bacfcf
	cfgdefs_perform_common_tests
f8089b
f8089b
	# ncurses libs
f8089b
	cfgtest_ldflags_append $mb_ncurses_libs
f8089b
b6fc94
	# options
b6fc94
	cfgtest_newline
b6fc94
	cfgtest_comment '(native) pycompile options'
b6fc94
	cfgdefs_output_options
b6fc94
f8089b
	# pretty cfgdefs.mk
f8089b
	cfgtest_newline
f8089b
}
f8089b
f8089b
db1f1a
# prefix, exec_prefix
db1f1a
cfgdefs_set_python_prefix
db1f1a
f8089b
# cfghost
f8089b
cfgdefs_set_cfghost_flavors
f8089b
8d7c97
# python version info
8d7c97
cfgdefs_detect_python_version
8d7c97
b6fc94
# python-specific configuration
b6fc94
cfgdefs_set_option_variables
b6fc94
8d7c97
# cfgdefs.in --> cfgdefs.mk
8d7c97
cfgdefs_output_custom_defs
8d7c97
ddc3c4
# strict: some tests might fail
ddc3c4
set +e
ddc3c4
f8089b
# target-specific tests
f8089b
cfgdefs_perform_target_tests
f8089b
f8089b
# native system tests
f8089b
cfgdefs_perform_native_tests
f8089b
ddc3c4
# strict: restore mode
ddc3c4
set -e
ddc3c4
f8089b
# all done
f8089b
return 0