-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_gnu.sh
194 lines (170 loc) · 7.99 KB
/
helpers_gnu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
function gnulib_dump_patches(){
declare -a PATCHES=("${BLD_CONFIG_GNU_LIBS_PATCHES_DEFAULT[@]}" "${BLD_CONFIG_GNU_LIBS_PATCHES_ADDL[@]}")
STROUT=""
for patch in "${PATCHES[@]}"; do
if [[ "$STROUT" ]]; then
STROUT+=","
fi
STROUT+="\"${patch}\""
done
echo "ScriptRes=[$STROUT]" >> "$GITHUB_OUTPUT"
}
function gnulib_switch_to_master_and_patch(){
cd $BLD_CONFIG_SRC_FOLDER
#sed -i -E "s#(gnulib_tool=.+gnulib-tool).py\$#\1#" bootstrap
cd $BLD_CONFIG_SRC_FOLDER/gnulib
#we do this process to make it easier to tell what changes we have actually made vs what changes were from our patches
git_stash_cur_work_discard_staged_work
if [[ ! -z "$BLD_CONFIG_GNU_LIBS_BRANCH" ]]; then
git checkout "$BLD_CONFIG_GNU_LIBS_BRANCH"
fi
echo ++++++ Running on GNULIB commit `git rev-parse --abbrev-ref HEAD` `git rev-parse HEAD`
rm -f build-aux/wrapper_helper.sh build-aux/wrapper_helper.sh build-aux/ld-link #temporary as we add files rn that the normal checkout clean doesn't cleanup
gnulib_patches;
git_stash_stage_patches_and_restore_cur_work
cd $BLD_CONFIG_SRC_FOLDER
if [[ -f "Makefile.am" ]]; then
SUBDIR_REGEX="^\\s*SUBDIRS\\s*="
ORIG_LINE=`cat Makefile.am | grep "$SUBDIR_REGEX"`
ORIG_LINE=" $ORIG_LINE "
FINAL_LINE="$ORIG_LINE"
if [[ $BLD_CONFIG_CONFIG_NO_TESTS -eq 1 ]]; then
FINAL_LINE=${FINAL_LINE//" gnulib-tests "/" "}
sed -E -i 's/\-\-with\-tests/--without-tests/g' bootstrap.conf
sed -E -i 's/\-\-tests\-base[^ ]+//g' bootstrap.conf
#if [[ $BLD_CONFIG_GNU_LIBS_USE_GNULIB_TOOL_PY -eq 1 ]]; then
#sed -E -i 's#--automake-subdir##g' bootstrap.conf
#fi
sed -E -i 's/gnulib\-tests[^s]*//g' configure.ac
rm -fr gnulib-tests
#need to remove tests-base as it still trys to include the gunlib test file
fi
if [[ $BLD_CONFIG_CONFIG_NO_PO -eq 1 ]]; then
FINAL_LINE=${FINAL_LINE//" po "/" "}
FINAL_LINE=${FINAL_LINE//" gnulib_po "/" "}
if [[ ! -d "build-aux" ]]; then #fixes error: required file 'build-aux/config.rpath' not found this is a gettext file
mkdir build-aux
fi
echo "" > build-aux/config.rpath
sed -i -E 's/^[ ]*AM_GNU_GETTEXT/#AM_GNU_GETTEXT/g' configure.ac
grep -v "texi2pdf" bootstrap.conf > tmp
mv tmp bootstrap.conf
if [[ -d "po" ]]; then
echo "" > po/Makefile.in.in
fi
fi
if [[ $BLD_CONFIG_CONFIG_NO_DOCS -eq 1 ]]; then
FINAL_LINE=${FINAL_LINE//" doc "/" "}
fi
sed -E -i "s/${SUBDIR_REGEX}.+/$FINAL_LINE/" Makefile.am
fi
#echo "DBGRAN cat Makefile.am | grep $SUBDIR_REGEX ORIG LINE WAS: $ORIG_LINE NOW: $FINAL_LINE final sed cmd was: " sed -i "s/${SUBDIR_REGEX}.+/$FINAL_LINE/g" Makefile.am
#done
}
function gnulib_ensure_buildaux_scripts_copied(){
FORCED=0
if [[ $1 == "--forced" ]]; then
FORCED=1
fi
if [[ $BLD_CONFIG_GNU_LIBS_USED -eq 1 ]] || [[ $BLD_CONFIG_GNU_LIBS_BUILD_AUX_ONLY_USED -eq 1 ]]; then
mkdir -p "$BLD_CONFIG_BUILD_AUX_FOLDER"
declare -a SCRIPTS_TO_ADD=("${BLD_CONFIG_BUILD_AUX_SCRIPTS_DEFAULT[@]}" "${BLD_CONFIG_BUILD_AUX_SCRIPTS_ADDL[@]}")
for flf in "${SCRIPTS_TO_ADD[@]}"; do
local gnu_path=$(convert_to_universal_path "${BLD_CONFIG_BUILD_AUX_FOLDER}/${flf}")
local SRC_PATH="${BLD_CONFIG_SRC_FOLDER}/gnulib/build-aux/${flf}"
if [[ ! -e "${gnu_path}" || $FORCED -eq 1 ]]; then
if [[ -e "${SRC_PATH}" ]]; then #we have gnulib the build aux folder and ar-lib so hopefully its our patched version
cp "${SRC_PATH}" "${gnu_path}"
else #no gnulib local so lets fetch it from remote
wget --quiet "https://raw.githubusercontent.com/mitchcapper/gnulib/ours_build_aux_handle_dot_a_libs/build-aux/${flf}" -O "${gnu_path}"
fi
fi
done
fi
}
function gnulib_add_addl_modules_to_bootstrap(){
cd $BLD_CONFIG_SRC_FOLDER
declare -a LIB_ADD=("${BLD_CONFIG_GNU_LIBS_DEFAULT[@]}" "${BLD_CONFIG_GNU_LIBS_ADDL[@]}")
CUR_MODULES=""
BOOT_FILE=""
INDENT=""
if [[ -f "gnulib.modules" ]]; then #ie tar style
CUR_MODULES=`cat gnulib.modules | grep "^[A-Za-z0-9]" | sed 's/^ *//;s/ *$//'`;
BOOT_FILE=`cat gnulib.modules | grep -v "^[A-Za-z0-9]"`;
else
#use \K to get exactly what we want here sed doesn't do \K so will just capture the group and sub that as grep doesnt do that
CUR_MODULES=`grep -Pzo "\n[ \t]*gnulib_modules\s*=\s*[\"'\x5c]+\K[^\"'\x5c]+" bootstrap.conf | sed 's/^ *//;s/ *$//' | tr -d '\0'`
BOOT_FILE=`sed -z -E "s#(\n[ \t]*gnulib_modules\s*=\s*['\"]+)[\n\x5c]*[^\"'\x5c]+#\1\nTOREPLACEZSTR\n#" bootstrap.conf | sed ''`
INDENT=" "
fi
CUR_MODULES=$"${CUR_MODULES}"$'\n'`printf '%s\n' "${LIB_ADD[@]}"`
CUR_MODULES=`echo "$CUR_MODULES" | sort -u | sed "s#^#${INDENT}#"`
if [[ -f "gnulib.modules" ]]; then
BOOT_FILE="$BOOT_FILE"$'\n'"$CUR_MODULES"
echo "${BOOT_FILE}" > gnulib.modules
else
echo "${BOOT_FILE/TOREPLACEZSTR/"$CUR_MODULES"$'\n'}" > bootstrap.conf
fi
}
function libtool_fixes(){
# even when symlink is used for autotools the m4 macro and the build-aux/ltmain.sh are still copied so fine to edit directly
# first the newer libtools have more windows support but that makes things actually a bit harder as it has some issues
# first it puts the export symbol commands in a .exp file but that is used by the compiler too so .expsym is better and used elsewhere
# Secondly it does -Fe [arg] but it needs to be next to the -Fe[arg]
# ie libtool_fixes "build-aux/ltmain.sh" "m4/libtool.m4"
# note you must run autoreconf after this if it wont automatically happen. Sometimes these will not be present until after the first bootstrap though so likely want to run autoreconf ourselves.
# local POS_FILES=("build-aux/ltmain.sh" "m4/libtool.m4")
# for fl in "${POS_FILES[@]}"; do
# if [[ -e "$fl" ]]; then
sed -i -E "s/(\\.exp)/\1sym/g;s/expsymsym/expsym/g;s/-Fe /-Fe/g" "$@"
sed -i -E "s/func_convert_core_msys_to_w32 \(/func_convert_core_msys_to_w32 (){ func_convert_core_msys_to_w32_result=\$1; }\\nfunc_convert_core_msys_to_w32_old (/" "$@"
#sed -i -E "s#(gnulib_tool=.+gnulib-tool)\$#\1.py#" bootstrap
# fi
#done
}
function setup_gnulibtool_py_autoconfwrapper(){
if [[ $BLD_CONFIG_GNU_LIBS_AUTORECONF_WRAPPER -eq 1 ]]; then
local TARGET_FL="${BLD_CONFIG_BUILD_AUX_FOLDER}/AUTORECONF_prewrapper.sh"
#For things like coreutils bootstrap will create the mk files we need to fix before it also then runs autoreconf so we will just use our wrapper for autoreconf, call ourselves, then call autoreconf
if [[ ! -e "$TARGET_FL" ]]; then
WRAPPER=`cat "${SCRIPT_FOLDER}/AUTORECONF_prewrapper.sh.template"`
WRAPPER="${WRAPPER/SCRIPT_PATH/"$CALL_SCRIPT_PATH"}"
mkdir -p "$BLD_CONFIG_BUILD_AUX_FOLDER"
echo "${WRAPPER}" > "$TARGET_FL"
fi
export AUTORECONF="$TARGET_FL"
#gnulib_tool_py_remove_nmd_makefiles;
fi
gnulib_ensure_buildaux_scripts_copied; #this has nothing to do wit autoconf but for some reason can get more failures with debug otherwise.
}
function gnulib_tool_py_remove_nmd_makefiles() {
echo "DONT THINK NEEDED ANYMORE" 1>&2
exit 1
#this taken from the normal gnulib_tool process, not sure lib/ will exist yet
#sed_eliminate_NMD='s/@NMD@//;/@!NMD@/d' #this is what is needed for automake subdirs but as that doesn't work with gnulib-tool..py right now no need to worry about it
sed_eliminate_NMD='/@NMD@/d;s/@!NMD@//'
local FILES=`find . -maxdepth 3 -name Makefile.am`
if [[ "${FILES}" != "" ]]; then
mapfile -t TO_FIX <<<$FILES
TO_FIX=("${TO_FIX[@]}" "${BLD_CONFIG_GNU_LIBS_USE_GNULIB_TOOL_PY_ADDL_MK_FILES_FIX[@]}")
for fl in "${TO_FIX[@]}"; do
if [[ -f "${fl}" ]]; then
# we grep first so we only modify files we would change
(grep '@NMD@' "${fl}" &>/dev/null && sed -i -e "$sed_eliminate_NMD" "${fl}") || true
fi
done
fi
#sed -i -E '/@NMD@/d;s/@!NMD@//' lib/Makefile.am Makefile.am
#sed -i -E "s#(gnulib_tool=.+gnulib-tool)\$#\1.py#" bootstrap
}
function gnulib_apply_patch(){
local patch=$1
local options=$2 #only valid option is skip_fixes right now
git_apply_patch "$WIN_SCRIPT_FOLDER/patches/patches_GNULIB_${patch}.patch"
}
function gnulib_patches(){
declare -a PATCHES=("${BLD_CONFIG_GNU_LIBS_PATCHES_DEFAULT[@]}" "${BLD_CONFIG_GNU_LIBS_PATCHES_ADDL[@]}")
for patch in "${PATCHES[@]}"; do
gnulib_apply_patch "$patch"
done
}