Skip to content

Commit 4637be2

Browse files
committed
build: make the message-compile script reusable from another build system
make_message_src.sh hardcoded the genrb/pkgdata paths per-OS and assumed the in-source messages/ layout (cd into the bundle dir, write the archive to ../../). Honor $GENRB/$PKGDATA from the environment when set, and accept optional source-bundle and output directories so an out-of-source build can call the same script. The one-argument form keeps the historical behavior, so messages/Makefile.am is unchanged.
1 parent bf6ee80 commit 4637be2

1 file changed

Lines changed: 63 additions & 58 deletions

File tree

messages/make_message_src.sh

Lines changed: 63 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
11
#!/bin/sh
22

3+
# Compile an ICU message bundle (a directory of *.txt resource files) into a
4+
# static archive lib<name>_dat.a using genrb + pkgdata.
5+
#
6+
# Usage: make_message_src.sh <archive_name> [src_bundle_dir] [out_dir]
7+
# <archive_name> e.g. libbin_ltfs_dat.a; the bundle name is derived from it
8+
# [src_bundle_dir] directory holding the *.txt files (default: ./<name>)
9+
# [out_dir] directory to write the archive into (default: .)
10+
#
11+
# genrb/pkgdata are taken from $GENRB/$PKGDATA when set (the build system
12+
# passes the paths it discovered); otherwise they are guessed per-OS. This
13+
# script is shared by the autotools and CMake builds: the one-argument form
14+
# preserves the historical in-source layout used by messages/Makefile.am.
15+
316
set -e
417

518
KERNEL_NAME=`uname -s`
19+
20+
# Resolve the ICU tools, honoring the environment first.
621
if [ "$KERNEL_NAME" = "Darwin" ]; then
722
ICU_FRAMEWORK=/Library/Frameworks/ICU.framework
8-
9-
if [ -d ${ICU_FRAMEWORK} ]; then
10-
export PATH=${PATH}:${ICU_FRAMEWORK}/Versions/Current/usr/bin
11-
export DYLD_LIBRARY_PATH=${ICU_FRAMEWORK}/Versions/Current/usr/lib
12-
GENRB=${ICU_FRAMEWORK}/Versions/Current/usr/bin/genrb
13-
PKGDATA=${ICU_FRAMEWORK}/Versions/Current/usr/bin/pkgdata
23+
if [ -d "${ICU_FRAMEWORK}" ]; then
24+
export PATH="${PATH}:${ICU_FRAMEWORK}/Versions/Current/usr/bin"
25+
export DYLD_LIBRARY_PATH="${ICU_FRAMEWORK}/Versions/Current/usr/lib"
26+
: "${GENRB:=${ICU_FRAMEWORK}/Versions/Current/usr/bin/genrb}"
27+
: "${PKGDATA:=${ICU_FRAMEWORK}/Versions/Current/usr/bin/pkgdata}"
1428
else
15-
GENRB=genrb
16-
PKGDATA=pkgdata
29+
: "${GENRB:=genrb}"
30+
: "${PKGDATA:=pkgdata}"
1731
fi
1832
elif [ "$KERNEL_NAME" = "FreeBSD" ]; then
19-
GENRB=genrb
20-
PKGDATA=/usr/local/bin/pkgdata
33+
: "${GENRB:=genrb}"
34+
: "${PKGDATA:=/usr/local/bin/pkgdata}"
2135
else
22-
if [ -x /usr/bin/genrb ]; then
23-
GENRB=/usr/bin/genrb
24-
else
25-
GENRB=genrb
26-
fi
27-
if [ -x /usr/bin/pkgdata ]; then
28-
PKGDATA=/usr/bin/pkgdata
29-
else
30-
PKGDATA=pkgdata
31-
fi
36+
if [ -x /usr/bin/genrb ]; then : "${GENRB:=/usr/bin/genrb}"; else : "${GENRB:=genrb}"; fi
37+
if [ -x /usr/bin/pkgdata ]; then : "${PKGDATA:=/usr/bin/pkgdata}"; else : "${PKGDATA:=pkgdata}"; fi
3238
fi
3339

34-
if [ "$#" -ne "1" ]; then
35-
echo "Usage: $0 object_file"
40+
if [ "$#" -lt "1" ]; then
41+
echo "Usage: $0 archive_name [src_bundle_dir] [out_dir]"
3642
exit 1
3743
fi
3844

@@ -46,65 +52,64 @@ case $KERNEL_NAME in
4652
;;
4753
esac
4854

49-
cd ${BASENAME}
55+
# Source bundle dir and output dir default to the historical in-source layout.
56+
SRC_DIR=${2:-./${BASENAME}}
57+
OUT_DIR=${3:-.}
58+
mkdir -p "$OUT_DIR"
59+
OUT_DIR=`cd "$OUT_DIR" && pwd` # absolute, survives the work-dir cd
60+
SRC_DIR=`cd "$SRC_DIR" && pwd`
5061

5162
make_obj() {
5263
echo "Processing ${BASENAME}"
5364

54-
# Create a fresh work directory
55-
if [ -d work ]; then
56-
rm -rf work
57-
fi
58-
mkdir work
65+
WORK="${OUT_DIR}/.work-${BASENAME}"
66+
rm -rf "$WORK"
67+
mkdir -p "$WORK"
5968

60-
# Generate files
61-
${GENRB} -d work -q *.txt
62-
cd work
63-
ls *.res >packagelist.txt
64-
${PKGDATA} -p ${BASENAME} -m static -q packagelist.txt >/dev/null
69+
# Generate the resource files, then package them statically.
70+
${GENRB} -d "$WORK" -q "${SRC_DIR}"/*.txt
71+
( cd "$WORK" && ls *.res > packagelist.txt && \
72+
${PKGDATA} -p ${BASENAME} -m static -q packagelist.txt >/dev/null )
6573

6674
case $KERNEL_NAME in
6775
MINGW32_NT*)
68-
mv ${BASENAME}.dat ../../
76+
mv "$WORK/${BASENAME}.dat" "$OUT_DIR/"
6977
;;
7078
FreeBSD)
71-
# pkgdata with -m static generates an ar(1) archive
72-
# with several object files on FreeBSD. To avoid
73-
# reworking the makefiles for all OSes, just rename
74-
# the archive to match the regular convention. The
75-
# linker handles it without a problem.
76-
mv lib${BASENAME}.a ../../lib${BASENAME}_dat.a
79+
# pkgdata -m static produces an ar(1) archive with several
80+
# object files on FreeBSD; rename it to the regular convention.
81+
mv "$WORK/lib${BASENAME}.a" "$OUT_DIR/lib${BASENAME}_dat.a"
7782
;;
7883
NetBSD)
79-
# generate libtool archive for later linking
80-
mv lib${BASENAME}.a ../../lib${BASENAME}_dat.a
84+
# Generate a libtool archive for later linking.
85+
mv "$WORK/lib${BASENAME}.a" "$OUT_DIR/lib${BASENAME}_dat.a"
8186
OBJFILE=${BASENAME}_dat.o
8287
LTFILE=${BASENAME}_dat.lo
83-
mkdir -p .libs ../../.libs
84-
mv ${OBJFILE} .libs
88+
mkdir -p "$WORK/.libs" "$OUT_DIR/.libs"
89+
mv "$WORK/${OBJFILE}" "$WORK/.libs"
8590
LTVERS=`libtool --version |
8691
sed -e 's/^\([^ ]*\) (GNU \(.*\)) \(.*\)$$/\1 - GNU \2 \3/' -e q`
87-
echo "# ${OBJFILE} - a libtool object file" > ${LTFILE}
88-
echo "# Generated by ${LTVERS}" >> ${LTFILE}
89-
echo "pic_object='.libs/${OBJFILE}'" >> ${LTFILE}
90-
echo "non_pic_object=none" >> ${LTFILE}
91-
libtool --mode=link --tag=CC cc -o ../../lib${BASENAME}_dat.la ${LTFILE}
92-
cp ../../lib${BASENAME}_dat.a ../../.libs
92+
echo "# ${OBJFILE} - a libtool object file" > "$OUT_DIR/${LTFILE}"
93+
echo "# Generated by ${LTVERS}" >> "$OUT_DIR/${LTFILE}"
94+
echo "pic_object='.libs/${OBJFILE}'" >> "$OUT_DIR/${LTFILE}"
95+
echo "non_pic_object=none" >> "$OUT_DIR/${LTFILE}"
96+
cp "$WORK/.libs/${OBJFILE}" "$OUT_DIR/.libs/"
97+
( cd "$OUT_DIR" && libtool --mode=link --tag=CC cc -o "lib${BASENAME}_dat.la" "${LTFILE}" )
98+
cp "$OUT_DIR/lib${BASENAME}_dat.a" "$OUT_DIR/.libs"
9399
;;
94100
*)
95-
mv ${BASENAME}_dat.o ../../lib${BASENAME}_dat.a
101+
mv "$WORK/${BASENAME}_dat.o" "$OUT_DIR/lib${BASENAME}_dat.a"
96102
;;
97103
esac
98104

99-
# Clean up
100-
cd ..
101-
rm -rf work
105+
rm -rf "$WORK"
102106
}
103107

104-
# Check whether we need to do anything
105-
if [ -f "../$1" ]; then
106-
for file in *.txt; do
107-
if [ "$file" -nt "../$1" ]; then
108+
# Rebuild only when a source file is newer than the existing archive.
109+
OUT_FILE="$OUT_DIR/$1"
110+
if [ -f "$OUT_FILE" ]; then
111+
for file in "$SRC_DIR"/*.txt; do
112+
if [ "$file" -nt "$OUT_FILE" ]; then
108113
make_obj
109114
exit 0
110115
fi

0 commit comments

Comments
 (0)