Skip to content

Commit 3f145a4

Browse files
pks-tgitster
authored andcommitted
Makefile: refactor generators to be PWD-independent
We have multiple scripts that generate headers from other data. All of these scripts have the assumption built-in that they are executed in the current source directory, which makes them a bit unwieldy to use during out-of-tree builds. Refactor them to instead take the source directory as well as the output file as arguments. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 19d8fe7 commit 3f145a4

File tree

5 files changed

+68
-34
lines changed

5 files changed

+68
-34
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,17 +2523,17 @@ $(BUILT_INS): git$X
25232523
config-list.h: generate-configlist.sh
25242524

25252525
config-list.h: Documentation/*config.txt Documentation/config/*.txt
2526-
$(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh >$@
2526+
$(QUIET_GEN)$(SHELL_PATH) ./generate-configlist.sh . $@
25272527

25282528
command-list.h: generate-cmdlist.sh command-list.txt
25292529

25302530
command-list.h: $(wildcard Documentation/git*.txt)
25312531
$(QUIET_GEN)$(SHELL_PATH) ./generate-cmdlist.sh \
25322532
$(patsubst %,--exclude-program %,$(EXCLUDED_PROGRAMS)) \
2533-
command-list.txt >$@
2533+
. $@
25342534

25352535
hook-list.h: generate-hooklist.sh Documentation/githooks.txt
2536-
$(QUIET_GEN)$(SHELL_PATH) ./generate-hooklist.sh >$@
2536+
$(QUIET_GEN)$(SHELL_PATH) ./generate-hooklist.sh . $@
25372537

25382538
SCRIPT_DEFINES = $(SHELL_PATH_SQ):$(DIFF_SQ):\
25392539
$(localedir_SQ):$(USE_GETTEXT_SCHEME):$(SANE_TOOL_PATH_SQ):\

contrib/buildsystems/CMakeLists.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -638,23 +638,24 @@ set(EXCLUSION_PROGS_CACHE ${EXCLUSION_PROGS} CACHE STRING "Programs not built" F
638638
if(NOT EXISTS ${CMAKE_BINARY_DIR}/command-list.h OR NOT EXCLUSION_PROGS_CACHE STREQUAL EXCLUSION_PROGS)
639639
list(REMOVE_ITEM EXCLUSION_PROGS empty)
640640
message("Generating command-list.h")
641-
execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-cmdlist.sh ${EXCLUSION_PROGS} command-list.txt
642-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
643-
OUTPUT_FILE ${CMAKE_BINARY_DIR}/command-list.h)
641+
execute_process(COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-cmdlist.sh"
642+
${EXCLUSION_PROGS}
643+
"${CMAKE_SOURCE_DIR}"
644+
"${CMAKE_BINARY_DIR}/command-list.h")
644645
endif()
645646

646647
if(NOT EXISTS ${CMAKE_BINARY_DIR}/config-list.h)
647648
message("Generating config-list.h")
648-
execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-configlist.sh
649-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
650-
OUTPUT_FILE ${CMAKE_BINARY_DIR}/config-list.h)
649+
execute_process(COMMAND "${SH_EXE}" "${CMAKE_SOURCE_DIR}/generate-configlist.sh"
650+
"${CMAKE_SOURCE_DIR}"
651+
"${CMAKE_BINARY_DIR}/config-list.h")
651652
endif()
652653

653654
if(NOT EXISTS ${CMAKE_BINARY_DIR}/hook-list.h)
654655
message("Generating hook-list.h")
655-
execute_process(COMMAND ${SH_EXE} ${CMAKE_SOURCE_DIR}/generate-hooklist.sh
656-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
657-
OUTPUT_FILE ${CMAKE_BINARY_DIR}/hook-list.h)
656+
execute_process(COMMAND "${SH_EXE}" ${CMAKE_SOURCE_DIR}/generate-hooklist.sh
657+
"${CMAKE_SOURCE_DIR}"
658+
"${CMAKE_BINARY_DIR}/hook-list.h")
658659
endif()
659660

660661
include_directories(${CMAKE_BINARY_DIR})

generate-cmdlist.sh

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ define_category_names () {
6464
print_command_list () {
6565
echo "static struct cmdname_help command_list[] = {"
6666

67-
echo "$1" |
67+
echo "$2" |
6868
while read cmd rest
6969
do
7070
synopsis=
@@ -76,7 +76,7 @@ print_command_list () {
7676
break
7777
;;
7878
esac
79-
done <"Documentation/$cmd.txt"
79+
done <"$1/Documentation/$cmd.txt"
8080

8181
printf '\t{ "%s", N_("%s"), 0' "$cmd" "$synopsis"
8282
printf " | CAT_%s" $rest
@@ -93,18 +93,28 @@ do
9393
shift
9494
done
9595

96-
commands="$(command_list "$1")"
97-
categories="$(category_list "$commands")"
96+
if test "$#" -ne 2
97+
then
98+
die "USAGE: $0 <SOURCE_DIR> <OUTPUT>"
99+
fi
100+
101+
SOURCE_DIR="$1"
102+
OUTPUT="$2"
103+
104+
{
105+
commands="$(command_list "$SOURCE_DIR"/command-list.txt)"
106+
categories="$(category_list "$commands")"
98107

99-
echo "/* Automatically generated by generate-cmdlist.sh */
100-
struct cmdname_help {
101-
const char *name;
102-
const char *help;
103-
uint32_t category;
104-
};
105-
"
106-
define_categories "$categories"
107-
echo
108-
define_category_names "$categories"
109-
echo
110-
print_command_list "$commands"
108+
echo "/* Automatically generated by generate-cmdlist.sh */
109+
struct cmdname_help {
110+
const char *name;
111+
const char *help;
112+
uint32_t category;
113+
};
114+
"
115+
define_categories "$categories"
116+
echo
117+
define_category_names "$categories"
118+
echo
119+
print_command_list "$SOURCE_DIR" "$commands"
120+
} >"$OUTPUT"

generate-configlist.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#!/bin/sh
22

3-
echo "/* Automatically generated by generate-configlist.sh */"
4-
echo
3+
SOURCE_DIR="$1"
4+
OUTPUT="$2"
5+
6+
if test -z "$SOURCE_DIR" || ! test -d "$SOURCE_DIR" || test -z "$OUTPUT"
7+
then
8+
echo >&2 "USAGE: $0 <SOURCE_DIR> <OUTPUT>"
9+
exit 1
10+
fi
511

612
print_config_list () {
713
cat <<EOF
814
static const char *config_name_list[] = {
915
EOF
10-
grep -h '^[a-zA-Z].*\..*::$' Documentation/*config.txt Documentation/config/*.txt |
16+
grep -h '^[a-zA-Z].*\..*::$' "$SOURCE_DIR"/Documentation/*config.txt "$SOURCE_DIR"/Documentation/config/*.txt |
1117
sed '/deprecated/d; s/::$//; s/, */\n/g' |
1218
sort |
1319
sed 's/^.*$/ "&",/'
@@ -17,5 +23,9 @@ EOF
1723
EOF
1824
}
1925

20-
echo
21-
print_config_list
26+
{
27+
echo "/* Automatically generated by generate-configlist.sh */"
28+
echo
29+
echo
30+
print_config_list
31+
} >"$OUTPUT"

generate-hooklist.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
#
33
# Usage: ./generate-hooklist.sh >hook-list.h
44

5+
SOURCE_DIR="$1"
6+
OUTPUT="$2"
7+
8+
if test -z "$SOURCE_DIR" || ! test -d "$SOURCE_DIR" || test -z "$OUTPUT"
9+
then
10+
echo >&2 "USAGE: $0 <SOURCE_DIR> <OUTPUT>"
11+
exit 1
12+
fi
13+
14+
{
15+
516
cat <<EOF
617
/* Automatically generated by generate-hooklist.sh */
718
@@ -11,10 +22,12 @@ EOF
1122
sed -n \
1223
-e '/^~~~~*$/ {x; s/^.*$/ "&",/; p;}' \
1324
-e 'x' \
14-
<Documentation/githooks.txt |
25+
<"$SOURCE_DIR"/Documentation/githooks.txt |
1526
LC_ALL=C sort
1627

1728
cat <<EOF
1829
NULL,
1930
};
2031
EOF
32+
33+
} >"$OUTPUT"

0 commit comments

Comments
 (0)