mxe/tools/patch-tool-mxe

156 lines
4.4 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2010-10-01 19:13:45 +01:00
2012-03-28 14:46:58 +01:00
# Tool for converting between MXE patch files and git repos
2010-10-01 19:13:45 +01:00
# Imports and exports patch files in "git format-patch" format.
cmd=$1
pkg=$2
patch_name=${3:-1-fixes}
2010-10-01 19:13:45 +01:00
setupEnv() {
# MXE directory
export mxedir=$(cd $(dirname $0) && cd .. && pwd)
2010-10-01 19:13:45 +01:00
# directory for unpacked tarballs/git repos
export gitsdir=${mxedir}/gits
2012-04-26 01:25:36 +01:00
mkdir -p ${gitsdir}
2010-10-01 19:13:45 +01:00
export pkg_version=`grep '^$(PKG)_VERSION' $mxedir/src/$pkg.mk | \
sed 's/.*:= \(.*\)/\1/'`
2010-10-01 19:13:45 +01:00
export pkg_short_version=`echo $pkg_version | sed s/'\(.*\)\.[^.]*$'/'\1'/`
2010-10-01 19:13:45 +01:00
export pkg_subdir=`grep '^$(PKG)_SUBDIR' $mxedir/src/$pkg.mk | \
sed 's/.*:= \(.*\)/\1/' | \
sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \
sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \
sed s/'$(PKG)'/$pkg/;`
2010-10-01 19:13:45 +01:00
export pkg_file=`grep '^$(PKG)_FILE\>' $mxedir/src/$pkg.mk | \
sed 's/.*:= \(.*\)/\1/' | \
sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \
sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \
sed s/'$($(PKG)_SUBDIR)'/$pkg_subdir/ | \
sed s/'$(PKG)'/$pkg/;`
2010-10-01 19:13:45 +01:00
#echo $pkg
#echo $pkg_version
#echo $pkg_subdir
#echo $pkg_file
2010-10-01 19:13:45 +01:00
}
2010-10-01 19:13:45 +01:00
# init
function init_git {
setupEnv
2010-10-01 19:13:45 +01:00
cd $gitsdir
if [ -d $gitsdir/$pkg_subdir ]; then
echo "Error: $gitsdir/$pkg_subdir already exists. Cancelling init." >&2
exit 1
fi
echo "Checking for cached $pkg_file"
if [ ! -f $mxedir/pkg/$pkg_file ]; then
make -C "$mxedir" download-only-$pkg
echo "Building the mxe Makefile target 'download-only-$pkg' to get missing file"
if [ ! $? -eq 0 ]; then
echo "Could not build target download-only-$pkg - cancelling init." >&2
exit 1
fi
fi
echo "Unpacking archive..."
(echo $pkg_file | grep "\.tar\.gz") || (echo $pkg_file | grep "\.tgz") \
>> /dev/null && tar xf $mxedir/pkg/$pkg_file
(echo $pkg_file | grep "\.tar\.bz2") || (echo $pkg_file | grep "\.tbz2") \
>> /dev/null && tar xf $mxedir/pkg/$pkg_file
(echo $pkg_file | grep "\.tar\.xz") || (echo $pkg_file | grep "\.txz") \
>> /dev/null && xz -dc $mxedir/pkg/$pkg_file | tar xf -
2012-03-28 14:48:13 +01:00
echo $pkg_file | grep "\.zip" >> /dev/null && unzip $mxedir/pkg/$pkg_file >> /dev/null
echo "Initializing repo and adding all as first commit"
2010-10-01 19:13:45 +01:00
cd $gitsdir/$pkg_subdir && \
(git init; git add -A; git commit -m "init") > /dev/null
2012-05-07 18:56:06 +01:00
echo "Creating 'dist' tag for distribution tarball state"
2010-10-01 19:13:45 +01:00
git tag dist
2012-05-07 18:56:06 +01:00
echo "Repository ready in $gitsdir/$pkg_subdir"
2010-10-01 19:13:45 +01:00
}
function export_patch {
setupEnv
if [ ! -d $gitsdir/$pkg_subdir ]; then
echo "Error: $gitsdir/$pkg_subdir does not exist, so cannot export patches. Cancelling export." >&2
exit 1
fi
2010-10-01 19:13:45 +01:00
cd $gitsdir/$pkg_subdir && \
(
2012-03-28 14:46:58 +01:00
echo 'This file is part of MXE.'
2012-03-29 11:14:15 +01:00
echo 'See index.html for further information.'
2010-10-01 19:13:45 +01:00
echo ''
echo 'Contains ad hoc patches for cross building.'
echo ''
git format-patch \
--no-numbered \
-p \
--no-signature \
--stdout \
--text \
dist..HEAD | \
sed 's/^From [0-9a-f]\{40\} /From 0000000000000000000000000000000000000000 /' | \
sed 's/^index .......\.\......../index 1111111..2222222/'
) > $mxedir/src/${pkg}-${patch_name}.patch && \
echo "Generated ${mxedir}/src/${pkg}-${patch_name}.patch"
2010-10-01 19:13:45 +01:00
}
function import_patch {
setupEnv
if [ ! -d $gitsdir/$pkg_subdir ]; then
echo "Error: $gitsdir/$pkg_subdir does not exist, so cannot import patches. Cancelling import - try 'init' first." >&2
exit 1
fi
if [ -f ${mxedir}/src/${pkg}-${patch_name}.patch ]; then
cd $gitsdir/$pkg_subdir && \
cat ${mxedir}/src/${pkg}-${patch_name}.patch | \
sed '/^From/,$ !d' | \
sed s/'^From: MXE'/"From: fix@me"/'g;' | \
git am --keep-cr && \
echo "Imported ${mxedir}/src/${pkg}-${patch_name}.patch"
else
echo "patch file ${mxedir}/src/${pkg}-${patch_name}.patch not found."
echo "Cancelling import." >&2
exit 1
fi
2010-10-01 19:13:45 +01:00
}
case "$cmd" in
init)
init_git $pkg
;;
import)
import_patch $pkg
;;
export)
export_patch $pkg
;;
*)
echo "Unrecognized command '${cmd}'" >&2
cat <<EOS
Usage: $0 COMMAND PACKAGENAME [PATCHNAME]
where COMMAND is one of:
init - create a git directory for the package with the raw source
import - apply the "pkgname-PATCHNAME.patch" patch commits
export - create/replace the "pkgname-PATCHNAME.patch" patch with a patch of all commits since init.
If PATCHNAME is not set, it is default to "1-fixes".
EOS
exit 1
;;
esac