1#!/usr/bin/env bash
2# Copyright 2024 The Hafnium Authors.
3#
4# Use of this source code is governed by a BSD-style
5# license that can be found in the LICENSE file or at
6# https://opensource.org/licenses/BSD-3-Clause.
7
8set -euox pipefail
9
10source "$(dirname ${BASH_SOURCE[0]})/../build/bash/common.inc"
11# Initialize global variables, prepare repo for building.
12init_build
13
14OUT=$ROOT_DIR/out
15# Dowloading the script from 6.11.5 stable.
16LINK=https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/plain/scripts/checkpatch.pl?h=v6.11.5
17
18# From a fresh clone out/ folder may not have been created.
19mkdir -p $OUT
20
21# Delete the folder to avoid any conflicts if it exists.
22CHECKPATCH_DIR=$OUT/checkpatch
23
24[ -d $CHECKPATCH_DIR ] && rm -r $CHECKPATCH_DIR
25mkdir $CHECKPATCH_DIR
26
27touch ${CHECKPATCH_DIR}/download_checkpatch.log
28wget --tries=3 --output-file=${CHECKPATCH_DIR}/download_checkpatch.log ${LINK} -P $CHECKPATCH_DIR
29
30# Rename to drop the extra characters at the end of the file name.
31mv $CHECKPATCH_DIR/checkpatch* $CHECKPATCH_DIR/checkpatch.pl
32chmod +x $CHECKPATCH_DIR/checkpatch.pl
33
34# File for outputting spelling mistakes and for outputting structs that
35# shoud const. This is mostly to mute the warnings.
36touch $CHECKPATCH_DIR/spelling.txt
37touch $CHECKPATCH_DIR/const_structs.checkpatch
38