162306a36Sopenharmony_ci#!/bin/sh 262306a36Sopenharmony_ci# SPDX-License-Identifier: LGPL-2.1 362306a36Sopenharmony_ci 462306a36Sopenharmony_ciif [ $# -ne 3 ] ; then 562306a36Sopenharmony_ci [ $# -eq 1 ] && hostarch=$1 || hostarch=`uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/` 662306a36Sopenharmony_ci linux_header_dir=tools/include/uapi/linux 762306a36Sopenharmony_ci header_dir=tools/include/uapi/asm-generic 862306a36Sopenharmony_ci arch_header_dir=tools/arch/${hostarch}/include/uapi/asm 962306a36Sopenharmony_cielse 1062306a36Sopenharmony_ci linux_header_dir=$1 1162306a36Sopenharmony_ci header_dir=$2 1262306a36Sopenharmony_ci arch_header_dir=$3 1362306a36Sopenharmony_cifi 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_cilinux_mman=${linux_header_dir}/mman.h 1662306a36Sopenharmony_ciarch_mman=${arch_header_dir}/mman.h 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci# those in grep -E -vw are flags, we want just the bits 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ciprintf "static const char *mmap_flags[] = {\n" 2162306a36Sopenharmony_ciregex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' 2262306a36Sopenharmony_citest -f ${arch_mman} && \ 2362306a36Sopenharmony_cigrep -E -q $regex ${arch_mman} && \ 2462306a36Sopenharmony_ci(grep -E $regex ${arch_mman} | \ 2562306a36Sopenharmony_ci sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ 2662306a36Sopenharmony_ci xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n") 2762306a36Sopenharmony_cigrep -E -q $regex ${linux_mman} && \ 2862306a36Sopenharmony_ci(grep -E $regex ${linux_mman} | \ 2962306a36Sopenharmony_ci grep -E -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \ 3062306a36Sopenharmony_ci sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ 3162306a36Sopenharmony_ci xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n") 3262306a36Sopenharmony_ci( ! test -f ${arch_mman} || \ 3362306a36Sopenharmony_cigrep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) && 3462306a36Sopenharmony_ci(grep -E $regex ${header_dir}/mman-common.h | \ 3562306a36Sopenharmony_ci grep -E -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \ 3662306a36Sopenharmony_ci sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ 3762306a36Sopenharmony_ci xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n") 3862306a36Sopenharmony_ci( ! test -f ${arch_mman} || \ 3962306a36Sopenharmony_cigrep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.h>.*' ${arch_mman}) && 4062306a36Sopenharmony_ci(grep -E $regex ${header_dir}/mman.h | \ 4162306a36Sopenharmony_ci sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ 4262306a36Sopenharmony_ci xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n") 4362306a36Sopenharmony_ciprintf "};\n" 44