File: create_platform_cfg.sh

package info (click to toggle)
cppcheck 2.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,132 kB
  • sloc: cpp: 268,935; python: 20,890; ansic: 8,090; sh: 1,045; makefile: 1,008; xml: 1,005; cs: 291
file content (49 lines) | stat: -rwxr-xr-x 1,862 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

if [ -n "$1" ]; then
  compiler_cmd=$1
else
  compiler_cmd="gcc"
fi

compiler_defs=$($compiler_cmd -dM -E - < /dev/null)

char_bit=$(echo "$compiler_defs" | grep __CHAR_BIT__ | cut -d' ' -f3)
# only set by compiler if -funsigned-char is specified
char_unsigned=$(echo "$compiler_defs" | grep __CHAR_UNSIGNED__ | cut -d' ' -f3)
if [ -n "$char_unsigned" ] && [ "$char_unsigned" -eq 1 ]; then
  default_sign="unsigned"
else
  default_sign="signed"
fi
# TODO
size_of_bool=
size_of_short=$(echo "$compiler_defs" | grep __SIZEOF_SHORT__ | cut -d' ' -f3)
size_of_int=$(echo "$compiler_defs" | grep __SIZEOF_INT__ | cut -d' ' -f3)
size_of_long=$(echo "$compiler_defs" | grep __SIZEOF_LONG__ | cut -d' ' -f3)
size_of_long_long=$(echo "$compiler_defs" | grep __SIZEOF_LONG_LONG__ | cut -d' ' -f3)
size_of_float=$(echo "$compiler_defs" | grep __SIZEOF_FLOAT__ | cut -d' ' -f3)
size_of_double=$(echo "$compiler_defs" | grep __SIZEOF_DOUBLE__ | cut -d' ' -f3)
size_of_long_double=$(echo "$compiler_defs" | grep __SIZEOF_LONG_DOUBLE__ | cut -d' ' -f3)
size_of_pointer=$(echo "$compiler_defs" | grep __SIZEOF_POINTER__ | cut -d' ' -f3)
size_of_size_t=$(echo "$compiler_defs" | grep __SIZEOF_SIZE_T__ | cut -d' ' -f3)
size_of_wchar_t=$(echo "$compiler_defs" | grep __SIZEOF_WCHAR_T__ | cut -d' ' -f3)

echo "<?xml version=\"1.0\"?>
<platform>
  <char_bit>$char_bit</char_bit>
  <default-sign>$default_sign</default-sign>
  <sizeof>
    <bool>$size_of_bool</bool>
    <short>$size_of_short</short>
    <int>$size_of_int</int>
    <long>$size_of_long</long>
    <long-long>$size_of_long_long</long-long>
    <float>$size_of_float</float>
    <double>$size_of_double</double>
    <long-double>$size_of_long_double</long-double>
    <pointer>$size_of_pointer</pointer>
    <size_t>$size_of_size_t</size_t>
    <wchar_t>$size_of_wchar_t</wchar_t>
  </sizeof>
</platform>"