summaryrefslogtreecommitdiffhomepage
path: root/project/config/cfgdefs.sh
blob: 994ef541102d89e95bc4f32e21b12a06ce627e89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
for arg ; do
	case "$arg" in
		--no-complex )
			libc_no_complex=yes
			;;
		*)
			error_msg ${arg#}: "unsupported config argument."
			exit 2
	esac
done

cfgdefs_set_arch()
{
	if [ -n "$mb_arch" ]; then
		return 0
	fi

	case "$mb_cchost" in
		*-*-*-* )
			mb_arch=${mb_cchost%-*-*-*}
			;;
		*-*-* )
			mb_arch=${mb_cchost%-*-*}
			;;
		*-* )
			mb_arch=${mb_cchost%-*-*-*}
			;;
		* )
			mb_arch='unknown'
			;;
	esac

	if [ "$mb_os" = 'midipix' ]; then
		case "$mb_arch" in
			x86_64 )
				mb_arch='nt64'
				;;
			i[3-6]86 )
				mb_arch='nt32'
				;;
		esac
	fi
}


cfgdefs_detect_libc_version()
{
	mb_libc_verinfo=$(cat "$mb_source_dir/VERSION")

	case "$mb_libc_verinfo" in
		*.*.* )
			libc_ver=${mb_libc_verinfo}
			libc_major=${mb_libc_verinfo%.*.*}
			libc_micro=${mb_libc_verinfo#*.*.}

			libc_minor=${libc_ver#*.}
			libc_minor=${libc_minor%.*}
			;;
		* )
			error_msg "Could not properly parse $mb_source_dir/VERSION"
			exit 2
	esac
}


cfgdefs_set_libc_options()
{
	if [ -d $mb_project_dir/arch/$mb_arch ]; then
		port_dir='$(PROJECT_DIR)'
		arch_dir=$mb_project_dir
	else
		port_dir='$(SOURCE_DIR)'
		arch_dir=$mb_source_dir
	fi

	if [ -f $arch_dir/arch/$mb_arch/bits/syscall.h.in ]; then
		libc_syscall_arch='syscall-gen.tag'
	else
		libc_syscall_arch='syscall-copy.tag'
	fi

	if [ -f $mb_source_dir/arch/x86_64/atomic_arch.h ]; then
		libc_source_tree='-D__LIBC_MODERN_SOURCE_TREE'
	else
		libc_source_tree='-D__LIBC_LEGACY_SOURCE_TREE'
	fi

	if [ -f $arch_dir/arch/$mb_arch/bits/alltypes.sed ]; then
		alltypes_sed=$arch_dir/arch/$mb_arch/bits/alltypes.sed
	else
		alltypes_sed=build/alltypes.sed
	fi

	if [ _${libc_no_complex:-} = _yes ]; then
		libc_deps=
		libc_excl_files='$(filter ./src/complex/%, $(libc_all_files))'
	else
		libc_deps='-lgcc -lgcc_eh'
		libc_excl_files=
	fi
}


cfgdefs_set_libc_cflags()
{
	libc_td_tid_addr=
	mb_init_tls_src_file=$mb_source_dir/src/env/__init_tls.c

	[ -z $libc_td_tid_addr ] \
		&& grep '__syscall(SYS_set_tid_address, &td->tid)' $mb_init_tls_src_file > /dev/null \
			&& libc_td_tid_addr='-D__LIBC_TD_TID_ADDR_TID'

	[ -z $libc_td_tid_addr ] \
		&& grep '__syscall(SYS_set_tid_address, &td->join_futex)' $mb_init_tls_src_file > /dev/null \
			&& libc_td_tid_addr='-D__LIBC_TD_TID_ADDR_JOIN_FUTEX'

	[ -z $libc_td_tid_addr ] \
		&& grep '__syscall(SYS_set_tid_address, &td->detach_state)' $mb_init_tls_src_file > /dev/null \
			&& libc_td_tid_addr='-D__LIBC_TD_TID_ADDR_DETACH_STATE'

	[ -z $libc_td_tid_addr ] \
		&& grep '__syscall(SYS_set_tid_address, &__thread_list_lock)' $mb_init_tls_src_file > /dev/null \
			&& libc_td_tid_addr='-D__LIBC_TD_TID_ADDR_THREAD_LIST_LOCK'

	return 0
}


cfgdefs_output_custom_defs()
{
	sed \
			-e 's/@port_dir@/'"$port_dir"'/g'       \
			-e 's/@libc_ver@/'"$libc_ver"'/g'       \
			-e 's/@libc_major@/'"$libc_major"'/g'   \
			-e 's/@libc_minor@/'"$libc_minor"'/g'   \
			-e 's/@libc_micro@/'"$libc_micro"'/g'   \
			-e 's/@libc_deps@/'"$libc_deps"'/g'     \
			-e 's^@libc_excl_files@^'"$libc_excl_files"'^g'   \
			-e 's/@libc_source_tree@/'"$libc_source_tree"'/g'  \
			-e 's/@libc_syscall_arch@/'"$libc_syscall_arch"'/g' \
			-e 's/@libc_td_tid_addr@/'"$libc_td_tid_addr"'/g'    \
			-e 's!@alltypes_sed@!'"$alltypes_sed"'!g'             \
		"$mb_project_dir/project/config/cfgdefs.in"         \
	| sed -e 's/[ \t]*$//g'                                     \
			>> "$mb_pwd/cfgdefs.mk"
}


# arch
cfgdefs_set_arch

# libc version info
cfgdefs_detect_libc_version

# libc (variant-specific) options
cfgdefs_set_libc_options

# libc (variant-specific) cflags
cfgdefs_set_libc_cflags

# cfgdefs.in --> cfgdefs.mk
cfgdefs_output_custom_defs

# all done
return 0