Blame view

scripts/mkcompile_h 2.48 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

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

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

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

4dcc9a884   Kees Cook   kbuild: mkcompile...
60
61
62
63
    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...
64
  } > .tmpcompile
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
67
68
  
  # Only replace the real compile.h if the new one is different,
  # in order to preserve the timestamp and avoid unnecessary
  # recompilations.
a979522a1   Matthias Maennich   kbuild: mkcompile...
69
70
71
  # We don't consider the file changed if only the date/time changed,
  # unless KBUILD_BUILD_TIMESTAMP was explicitly set (e.g. for
  # reproducible builds with that value referring to a commit timestamp).
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
  # A kernel config change will increase the generation number, thus
38385f8f0   Masahiro Yamada   kbuild: trivial -...
73
  # causing compile.h to be updated (including date/time) due to the
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
75
  # changed comment in the
  # first line.
a979522a1   Matthias Maennich   kbuild: mkcompile...
76
77
78
79
80
  if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
     IGNORE_PATTERN="UTS_VERSION"
  else
     IGNORE_PATTERN="NOT_A_PATTERN_TO_BE_MATCHED"
  fi
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
  if [ -r $TARGET ] && \
a979522a1   Matthias Maennich   kbuild: mkcompile...
82
83
        grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \
        grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
84
85
86
        cmp -s .tmpver.1 .tmpver.2; then
     rm -f .tmpcompile
  else
c39013ee6   Masahiro Yamada   kbuild: clean up ...
87
     echo "  UPD     $TARGET"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
89
90
     mv -f .tmpcompile $TARGET
  fi
  rm -f .tmpver.1 .tmpver.2