source: mainline/tools/autogen2.sh@ 5af6cf3d

Last change on this file since 5af6cf3d was 5af6cf3d, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

todo

  • Property mode set to 100755
File size: 1.6 KB
RevLine 
[d5e5fd1]1#!/bin/sh
2
[5af6cf3d]3# There's a bunch of restriction. The script assumes that the structure definition begins with "typedef struct struct_name {",
4# ends with "struct_name_t;", and that every word in between that ends with ";" is a struct member name with optional
5# array subscript. Error handling is mostly omitted for simplicity, so any input that does not follow these rules will result
6# in cryptic errors.
[d5e5fd1]7
[5af6cf3d]8echo $PWD
[d5e5fd1]9
[5af6cf3d]10input="$1"
11output="$2"
12toolsdir="$(readlink -f $(dirname "$0"))"
13awkscript="$toolsdir/autogen2.awk"
[d5e5fd1]14
[5af6cf3d]15# Set default value for $CC.
[d5e5fd1]16if [ -z "${CC}" ]; then
17 CC=cc
18fi
19
[5af6cf3d]20# If $CC is clang, we need to make sure integrated assembler is not used.
[d5e5fd1]21if ( ${CC} --version | grep clang > /dev/null ) ; then
22 CFLAGS="${CFLAGS} -no-integrated-as"
23fi
24
[5af6cf3d]25# Tell the compiler to generate makefile dependencies.
26CFLAGS="${CFLAGS} -MD -MP -MT $output -MF $output.d"
[d5e5fd1]27
[5af6cf3d]28# Generate defines
29defs=`$awkscript -- $input || exit 1`
[d5e5fd1]30
[5af6cf3d]31# Generate C file.
32cat > $output.c <<- EOF
[d5e5fd1]33
[5af6cf3d]34#include "`basename $input`"
35
36#define DEFINE_MEMBER(ls, us, lm, um) \
37 asm volatile ("/* #define "#us"_OFFSET_"#um" %0 */" :: "i" (__builtin_offsetof(struct ls, lm))); \
38 asm volatile ("/* #define "#us"_SIZE_"#um" %0 */" :: "i" (sizeof((struct ls){}.lm)));
39
40#define DEFINE_STRUCT(ls, us) \\
41 asm volatile ("/* #define "#us"_SIZE %0 */" :: "i" (sizeof(struct ls)));
[d5e5fd1]42
43void autogen()
44{
[5af6cf3d]45 $defs
[d5e5fd1]46}
47
48EOF
[5af6cf3d]49
50# Turn the C file into assembly.
51${CC} ${CFLAGS} -w -S -o $output.s $output.c || exit 1
52
53# Process the output.
54
55echo "/* Autogenerated file, do not modify. */" > $output
56echo "#pragma once" >> $output
57sed -n 's/^.* #define \([^ ]\+\) [^0-9]*\([0-9]\+\) .*/#define \1 \2/p' < $output.s > $output || exit 1
Note: See TracBrowser for help on using the repository browser.