Blame view

scripts/mkcompile_h 2.27 KB
17c5ca988   Felipe Contreras   kbuild: mkcompile...
1
  #!/bin/sh
b24413180   Greg Kroah-Hartman   License cleanup: ...
2
  # SPDX-License-Identifier: GPL-2.0
17c5ca988   Felipe Contreras   kbuild: mkcompile...
3

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
  TARGET=$1
  ARCH=$2
  SMP=$3
bd5bdd875   Sam Ravnborg   kbuild: "PREEMPT"...
7
  PREEMPT=$4
4b950bb9a   Thomas Gleixner   Kbuild: Handle PR...
8
  PREEMPT_RT=$5
9a9501546   Masahiro Yamada   kbuild: use CONFI...
9
  CC_VERSION="$6"
4dcc9a884   Kees Cook   kbuild: mkcompile...
10
  LD=$7
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11

d03fab43c   Mike Frysinger   kbuild: kill outp...
12
  vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
  # Do not expand names
  set -f
87c94bfb8   Sam Ravnborg   kbuild: override ...
15
16
17
18
19
  # Fix the language to get consistent output
  LC_ALL=C
  export LC_ALL
  
  if [ -z "$KBUILD_BUILD_VERSION" ]; then
37131ec4f   Masahiro Yamada   kbuild: mkcompile...
20
  	VERSION=$(cat .version 2>/dev/null || echo 1)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  else
87c94bfb8   Sam Ravnborg   kbuild: override ...
22
  	VERSION=$KBUILD_BUILD_VERSION
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
  fi
87c94bfb8   Sam Ravnborg   kbuild: override ...
24
25
26
27
28
  if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
  	TIMESTAMP=`date`
  else
  	TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
  fi
53e6892c0   Michal Marek   kbuild: Allow to ...
29
  if test -z "$KBUILD_BUILD_USER"; then
f07726048   Marcin Nowakowski   Fix handling of b...
30
  	LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
53e6892c0   Michal Marek   kbuild: Allow to ...
31
32
33
34
35
36
37
38
  else
  	LINUX_COMPILE_BY=$KBUILD_BUILD_USER
  fi
  if test -z "$KBUILD_BUILD_HOST"; then
  	LINUX_COMPILE_HOST=`hostname`
  else
  	LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST
  fi
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39
40
  
  UTS_VERSION="#$VERSION"
bd5bdd875   Sam Ravnborg   kbuild: "PREEMPT"...
41
42
43
  CONFIG_FLAGS=""
  if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
  if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
4b950bb9a   Thomas Gleixner   Kbuild: Handle PR...
44
  if [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
  
  # Truncate to maximum length
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
  UTS_LEN=64
e8193650b   Masahiro Yamada   mkcompile_h: git ...
48
  UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
50
  
  # Generate a temporary compile.h
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
51
  { echo /\* This file is auto generated, version $VERSION \*/
bd5bdd875   Sam Ravnborg   kbuild: "PREEMPT"...
52
    if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
38385f8f0   Masahiro Yamada   kbuild: trivial -...
53

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
    echo \#define UTS_MACHINE \"$ARCH\"
e8193650b   Masahiro Yamada   mkcompile_h: git ...
55
    echo \#define UTS_VERSION \"$UTS_VERSION\"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56

c8f3dea90   Masahiro Yamada   mkcompile_h: use ...
57
58
    printf '#define LINUX_COMPILE_BY "%s"
  ' "$LINUX_COMPILE_BY"
e8193650b   Masahiro Yamada   mkcompile_h: git ...
59
    echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60

4dcc9a884   Kees Cook   kbuild: mkcompile...
61
62
63
64
    LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
  		      | sed 's/[[:space:]]*$//')
    printf '#define LINUX_COMPILER "%s"
  ' "$CC_VERSION, $LD_VERSION"
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
65
  } > .tmpcompile
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
66
67
68
69
70
71
  
  # Only replace the real compile.h if the new one is different,
  # in order to preserve the timestamp and avoid unnecessary
  # recompilations.
  # We don't consider the file changed if only the date/time changed.
  # A kernel config change will increase the generation number, thus
38385f8f0   Masahiro Yamada   kbuild: trivial -...
72
  # causing compile.h to be updated (including date/time) due to the
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
74
75
76
  # changed comment in the
  # first line.
  
  if [ -r $TARGET ] && \
061296dc2   Michal Marek   kbuild: Drop unus...
77
78
        grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \
        grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
80
81
        cmp -s .tmpver.1 .tmpver.2; then
     rm -f .tmpcompile
  else
d03fab43c   Mike Frysinger   kbuild: kill outp...
82
     vecho "  UPD     $TARGET"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
     mv -f .tmpcompile $TARGET
  fi
  rm -f .tmpver.1 .tmpver.2