18c2ecf20Sopenharmony_ci#!/bin/sh
28c2ecf20Sopenharmony_ci# SPDX-License-Identifier: LGPL-2.1
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciif [ $# -ne 3 ] ; then
58c2ecf20Sopenharmony_ci	[ $# -eq 1 ] && hostarch=$1 || hostarch=`uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/`
68c2ecf20Sopenharmony_ci	linux_header_dir=tools/include/uapi/linux
78c2ecf20Sopenharmony_ci	header_dir=tools/include/uapi/asm-generic
88c2ecf20Sopenharmony_ci	arch_header_dir=tools/arch/${hostarch}/include/uapi/asm
98c2ecf20Sopenharmony_cielse
108c2ecf20Sopenharmony_ci	linux_header_dir=$1
118c2ecf20Sopenharmony_ci	header_dir=$2
128c2ecf20Sopenharmony_ci	arch_header_dir=$3
138c2ecf20Sopenharmony_cifi
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cilinux_mman=${linux_header_dir}/mman.h
168c2ecf20Sopenharmony_ciarch_mman=${arch_header_dir}/mman.h
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci# those in egrep -vw are flags, we want just the bits
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciprintf "static const char *mmap_flags[] = {\n"
218c2ecf20Sopenharmony_ciregex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*'
228c2ecf20Sopenharmony_ciegrep -q $regex ${arch_mman} && \
238c2ecf20Sopenharmony_ci(egrep $regex ${arch_mman} | \
248c2ecf20Sopenharmony_ci	sed -r "s/$regex/\2 \1 \1 \1 \2/g"	| \
258c2ecf20Sopenharmony_ci	xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
268c2ecf20Sopenharmony_ciegrep -q $regex ${linux_mman} && \
278c2ecf20Sopenharmony_ci(egrep $regex ${linux_mman} | \
288c2ecf20Sopenharmony_ci	egrep -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
298c2ecf20Sopenharmony_ci	sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \
308c2ecf20Sopenharmony_ci	xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
318c2ecf20Sopenharmony_ci([ ! -f ${arch_mman} ] || egrep -q '#[[:space:]]*include[[:space:]]+<uapi/asm-generic/mman.*' ${arch_mman}) &&
328c2ecf20Sopenharmony_ci(egrep $regex ${header_dir}/mman-common.h | \
338c2ecf20Sopenharmony_ci	egrep -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
348c2ecf20Sopenharmony_ci	sed -r "s/$regex/\2 \1 \1 \1 \2/g"	| \
358c2ecf20Sopenharmony_ci	xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
368c2ecf20Sopenharmony_ci([ ! -f ${arch_mman} ] || egrep -q '#[[:space:]]*include[[:space:]]+<uapi/asm-generic/mman.h>.*' ${arch_mman}) &&
378c2ecf20Sopenharmony_ci(egrep $regex ${header_dir}/mman.h | \
388c2ecf20Sopenharmony_ci	sed -r "s/$regex/\2 \1 \1 \1 \2/g"	| \
398c2ecf20Sopenharmony_ci	xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
408c2ecf20Sopenharmony_ciprintf "};\n"
41