Blame project/config/cfgdefs.sh

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