aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2026-03-19 06:33:24 +0100
committerJunio C Hamano <gitster@pobox.com>2026-03-19 06:40:09 -0700
commita767f2fd6c5a6104ff32a35a27f0c15aec546957 (patch)
treed558fdbd55b625018b35d7e83ac3c1d4217ef318 /tools
parent405c98a6a0e017f41f5de9c649a8f6f1b3fc4314 (diff)
downloadgit-a767f2fd6c5a6104ff32a35a27f0c15aec546957.tar.xz
builds: move build scripts into "tools/"
We have a bunch of scripts used by our different build systems that are all located in the top-level directory. Now that we have introduced the new "tools/" directory though we have a better home for them. Move the scripts into the "tools/" directory. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/check-builtins.sh34
-rwxr-xr-xtools/detect-compiler58
-rwxr-xr-xtools/generate-cmdlist.sh120
-rwxr-xr-xtools/generate-configlist.sh52
-rwxr-xr-xtools/generate-hooklist.sh33
-rwxr-xr-xtools/generate-perl.sh37
-rwxr-xr-xtools/generate-python.sh20
-rwxr-xr-xtools/generate-script.sh34
8 files changed, 388 insertions, 0 deletions
diff --git a/tools/check-builtins.sh b/tools/check-builtins.sh
new file mode 100755
index 0000000000..a0aaf3a347
--- /dev/null
+++ b/tools/check-builtins.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+{
+ cat <<\EOF
+sayIt:
+ $(foreach b,$(BUILT_INS),echo XXX $(b:$X=) YYY;)
+EOF
+ cat Makefile
+} |
+make -f - sayIt 2>/dev/null |
+sed -n -e 's/.*XXX \(.*\) YYY.*/\1/p' |
+sort |
+{
+ bad=0
+ while read builtin
+ do
+ base=$(expr "$builtin" : 'git-\(.*\)')
+ x=$(sed -ne 's/.*{ "'$base'", \(cmd_[^, ]*\).*/'$base' \1/p' git.c)
+ if test -z "$x"
+ then
+ echo "$base is builtin but not listed in git.c command list"
+ bad=1
+ fi
+ for sfx in sh perl py
+ do
+ if test -f "$builtin.$sfx"
+ then
+ echo "$base is builtin but $builtin.$sfx still exists"
+ bad=1
+ fi
+ done
+ done
+ exit $bad
+}
diff --git a/tools/detect-compiler b/tools/detect-compiler
new file mode 100755
index 0000000000..124ebdd4c9
--- /dev/null
+++ b/tools/detect-compiler
@@ -0,0 +1,58 @@
+#!/bin/sh
+#
+# Probe the compiler for vintage, version, etc. This is used for setting
+# optional make knobs under the DEVELOPER knob.
+
+CC="$*"
+
+# we get something like (this is at least true for gcc and clang)
+#
+# FreeBSD clang version 3.4.1 (tags/RELEASE...)
+get_version_line() {
+ LANG=C LC_ALL=C $CC -v 2>&1 | sed -n '/ version /{p;q;}'
+}
+
+get_family() {
+ get_version_line | sed 's/^\(.*\) version [0-9].*/\1/'
+}
+
+get_version() {
+ # A string that begins with a digit up to the next SP
+ ver=$(get_version_line | sed 's/^.* version \([0-9][^ ]*\).*/\1/')
+
+ # There are known -variant suffixes that do not affect the
+ # meaning of the main version number. Strip them.
+ ver=${ver%-win32}
+ ver=${ver%-posix}
+
+ echo "$ver"
+}
+
+print_flags() {
+ family=$1
+ version=$(get_version | cut -f 1 -d .)
+
+ # Print a feature flag not only for the current version, but also
+ # for any prior versions we encompass. This avoids needing to do
+ # numeric comparisons in make, which are awkward.
+ while test "$version" -gt 0
+ do
+ echo $family$version
+ version=$((version - 1))
+ done
+}
+
+case "$(get_family)" in
+gcc)
+ print_flags gcc
+ ;;
+clang | *" clang")
+ print_flags clang
+ ;;
+"Apple LLVM")
+ print_flags clang
+ ;;
+*)
+ : unknown compiler family
+ ;;
+esac
diff --git a/tools/generate-cmdlist.sh b/tools/generate-cmdlist.sh
new file mode 100755
index 0000000000..0ed39c4c5d
--- /dev/null
+++ b/tools/generate-cmdlist.sh
@@ -0,0 +1,120 @@
+#!/bin/sh
+
+die () {
+ echo "$@" >&2
+ exit 1
+}
+
+command_list () {
+ while read cmd rest
+ do
+ case "$cmd" in
+ "#"* | '')
+ # Ignore comments and allow empty lines
+ continue
+ ;;
+ *)
+ case "$exclude_programs" in
+ *":$cmd:"*)
+ ;;
+ *)
+ echo "$cmd $rest"
+ ;;
+ esac
+ esac
+ done <"$1"
+}
+
+category_list () {
+ echo "$1" |
+ cut -d' ' -f2- |
+ tr ' ' '\012' |
+ grep -v '^$' |
+ LC_ALL=C sort -u
+}
+
+define_categories () {
+ echo
+ echo "/* Command categories */"
+ bit=0
+ echo "$1" |
+ while read cat
+ do
+ echo "#define CAT_$cat (1UL << $bit)"
+ bit=$(($bit+1))
+ done
+ test "$bit" -gt 32 && die "Urgh.. too many categories?"
+}
+
+define_category_names () {
+ echo
+ echo "/* Category names */"
+ echo "static const char *category_names[] = {"
+ bit=0
+ echo "$1" |
+ while read cat
+ do
+ echo " \"$cat\", /* (1UL << $bit) */"
+ bit=$(($bit+1))
+ done
+ echo " NULL"
+ echo "};"
+}
+
+print_command_list () {
+ echo "static struct cmdname_help command_list[] = {"
+
+ echo "$2" |
+ while read cmd rest
+ do
+ synopsis=
+ while read line
+ do
+ case "$line" in
+ "$cmd - "*)
+ synopsis=${line#$cmd - }
+ break
+ ;;
+ esac
+ done <"$1/Documentation/$cmd.adoc"
+
+ printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis"
+ printf " | CAT_%s" $rest
+ echo " },"
+ done
+ echo "};"
+}
+
+exclude_programs=:
+while test "--exclude-program" = "$1"
+do
+ shift
+ exclude_programs="$exclude_programs$1:"
+ shift
+done
+
+if test "$#" -ne 2
+then
+ die "USAGE: $0 <SOURCE_DIR> <OUTPUT>"
+fi
+
+SOURCE_DIR="$1"
+OUTPUT="$2"
+
+{
+ commands="$(command_list "$SOURCE_DIR"/command-list.txt)"
+ categories="$(category_list "$commands")"
+
+ echo "/* Automatically generated by generate-cmdlist.sh */
+ struct cmdname_help {
+ const char *name;
+ const char *help;
+ uint32_t category;
+ };
+ "
+ define_categories "$categories"
+ echo
+ define_category_names "$categories"
+ echo
+ print_command_list "$SOURCE_DIR" "$commands"
+} >"$OUTPUT"
diff --git a/tools/generate-configlist.sh b/tools/generate-configlist.sh
new file mode 100755
index 0000000000..e28054f9e0
--- /dev/null
+++ b/tools/generate-configlist.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+SOURCE_DIR="$1"
+OUTPUT="$2"
+DEPFILE="$3"
+
+if test -z "$SOURCE_DIR" || ! test -d "$SOURCE_DIR" || test -z "$OUTPUT"
+then
+ echo >&2 "USAGE: $0 <SOURCE_DIR> <OUTPUT> [<DEPFILE>]"
+ exit 1
+fi
+
+print_config_list () {
+ cat <<EOF
+static const char *config_name_list[] = {
+EOF
+ sed -e '
+ /^`*[a-zA-Z].*\..*`*::$/ {
+ /deprecated/d;
+ s/::$//;
+ s/`//g;
+ s/^.*$/ "&",/;
+ p;};
+ d' \
+ "$SOURCE_DIR"/Documentation/*config.adoc \
+ "$SOURCE_DIR"/Documentation/config/*.adoc |
+ sort
+ cat <<EOF
+ NULL,
+};
+EOF
+}
+
+{
+ echo "/* Automatically generated by generate-configlist.sh */"
+ echo
+ echo
+ print_config_list
+} >"$OUTPUT"
+
+if test -n "$DEPFILE"
+then
+ QUOTED_OUTPUT="$(printf '%s\n' "$OUTPUT" | sed 's,[&/\],\\&,g')"
+ {
+ printf '%s\n' "$SOURCE_DIR"/Documentation/*config.adoc \
+ "$SOURCE_DIR"/Documentation/config/*.adoc |
+ sed -e 's/[# ]/\\&/g' -e "s/^/$QUOTED_OUTPUT: /"
+ printf '%s:\n' "$SOURCE_DIR"/Documentation/*config.adoc \
+ "$SOURCE_DIR"/Documentation/config/*.adoc |
+ sed -e 's/[# ]/\\&/g'
+ } >"$DEPFILE"
+fi
diff --git a/tools/generate-hooklist.sh b/tools/generate-hooklist.sh
new file mode 100755
index 0000000000..e0cdf26944
--- /dev/null
+++ b/tools/generate-hooklist.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+#
+# Usage: ./generate-hooklist.sh >hook-list.h
+
+SOURCE_DIR="$1"
+OUTPUT="$2"
+
+if test -z "$SOURCE_DIR" || ! test -d "$SOURCE_DIR" || test -z "$OUTPUT"
+then
+ echo >&2 "USAGE: $0 <SOURCE_DIR> <OUTPUT>"
+ exit 1
+fi
+
+{
+
+cat <<EOF
+/* Automatically generated by generate-hooklist.sh */
+
+static const char *hook_name_list[] = {
+EOF
+
+sed -n \
+ -e '/^~~~~*$/ {x; s/^.*$/ "&",/; p;}' \
+ -e 'x' \
+ <"$SOURCE_DIR"/Documentation/githooks.adoc |
+ LC_ALL=C sort
+
+cat <<EOF
+ NULL,
+};
+EOF
+
+} >"$OUTPUT"
diff --git a/tools/generate-perl.sh b/tools/generate-perl.sh
new file mode 100755
index 0000000000..796d835932
--- /dev/null
+++ b/tools/generate-perl.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+set -e
+
+if test $# -ne 5
+then
+ echo >&2 "USAGE: $0 <GIT_BUILD_OPTIONS> <GIT_VERSION_FILE> <PERL_HEADER> <INPUT> <OUTPUT>"
+ exit 1
+fi
+
+GIT_BUILD_OPTIONS="$1"
+GIT_VERSION_FILE="$2"
+PERL_HEADER="$3"
+INPUT="$4"
+OUTPUT="$5"
+
+. "$GIT_BUILD_OPTIONS"
+. "$GIT_VERSION_FILE"
+
+sed -e '1{' \
+ -e " /^#!.*perl/!b" \
+ -e " s|#!.*perl|#!$PERL_PATH|" \
+ -e " r $PERL_HEADER" \
+ -e ' G' \
+ -e '}' \
+ -e "s|@GIT_VERSION@|$GIT_VERSION|g" \
+ -e "s|@LOCALEDIR@|$PERL_LOCALEDIR|g" \
+ -e "s|@NO_GETTEXT@|$NO_GETTEXT|g" \
+ -e "s|@NO_PERL_CPAN_FALLBACKS@|$NO_PERL_CPAN_FALLBACKS|g" \
+ "$INPUT" >"$OUTPUT"
+
+case "$INPUT" in
+*.perl|*git-contacts)
+ chmod a+x "$OUTPUT";;
+*)
+ ;;
+esac
diff --git a/tools/generate-python.sh b/tools/generate-python.sh
new file mode 100755
index 0000000000..31ac115689
--- /dev/null
+++ b/tools/generate-python.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+set -e
+
+if test $# -ne 3
+then
+ echo >&2 "USAGE: $0 <GIT_BUILD_OPTIONS> <INPUT> <OUTPUT>"
+ exit 1
+fi
+
+GIT_BUILD_OPTIONS="$1"
+INPUT="$2"
+OUTPUT="$3"
+
+. "$GIT_BUILD_OPTIONS"
+
+sed -e "1s|#!.*python|#!$PYTHON_PATH|" \
+ "$INPUT" >"$OUTPUT+"
+chmod a+x "$OUTPUT+"
+mv "$OUTPUT+" "$OUTPUT"
diff --git a/tools/generate-script.sh b/tools/generate-script.sh
new file mode 100755
index 0000000000..a149e4f0ba
--- /dev/null
+++ b/tools/generate-script.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+set -e
+
+if test $# -ne 3
+then
+ echo >&2 "USAGE: $0 <INPUT> <OUTPUT> <GIT-BUILD-OPTIONS>"
+ exit 1
+fi
+
+INPUT="$1"
+OUTPUT="$2"
+BUILD_OPTIONS="$3"
+
+. "$BUILD_OPTIONS"
+
+sed -e "1s|#!.*/sh|#!$SHELL_PATH|" \
+ -e "s|@SHELL_PATH@|$SHELL_PATH|" \
+ -e "s|@DIFF@|$DIFF|" \
+ -e "s|@LOCALEDIR@|$LOCALEDIR|g" \
+ -e "s/@USE_GETTEXT_SCHEME@/$USE_GETTEXT_SCHEME/g" \
+ -e "$BROKEN_PATH_FIX" \
+ -e "s|@GITWEBDIR@|$GITWEBDIR|g" \
+ -e "s|@PERL_PATH@|$PERL_PATH|g" \
+ -e "s|@PAGER_ENV@|$PAGER_ENV|g" \
+ "$INPUT" >"$OUTPUT"
+
+case "$(basename "$INPUT")" in
+git-mergetool--lib.sh|git-sh-i18n.sh|git-sh-setup.sh)
+ ;;
+*)
+ chmod a+x "$OUTPUT"
+ ;;
+esac