summaryrefslogtreecommitdiffstats
path: root/tools/patch-tool-mxe
blob: c130fae93ba1ba22583f06fd82a1351ca57ebf92 (plain)
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
#!/usr/bin/env bash

# Tool for converting between MXE patch files and git repos
# Imports and exports patch files in "git format-patch" format.

cmd=$1
pkg=$2

# MXE directory
mxedir=~/mxe

# directory for unpacked tarballs/git repos
gitsdir=~/gits


# John Doe <John Doe@acme.org>
author=`git var GIT_AUTHOR_IDENT | sed 's/^\(.* [<].*[>]\).*$/\1/'`

pkg_version=`grep '^$(PKG)_VERSION' $mxedir/src/$pkg.mk  | \
  sed 's/.*:= \(.*\)/\1/'`

pkg_short_version=`echo $pkg_version | sed s/'\(.*\)\.[^.]*$'/'\1'/`

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/;`

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/;`

#echo $pkg
#echo $pkg_version
#echo $pkg_subdir
#echo $pkg_file

# init
function init_git {
  cd $gitsdir
  echo $pkg_file | grep "\.tar\.gz"  >> /dev/null && tar xf $mxedir/pkg/$pkg_file
  echo $pkg_file | grep "\.tar\.bz2" >> /dev/null && tar xf $mxedir/pkg/$pkg_file
  echo $pkg_file | grep "\.tar\.xz"  >> /dev/null && xz -dc $mxedir/pkg/$pkg_file | tar xf -
  echo $pkg_file | grep "\.zip"      >> /dev/null && unzip  $mxedir/pkg/$pkg_file >> /dev/null
  cd $gitsdir/$pkg_subdir && \
  (git init; git add -A; git commit -m "init") > /dev/null
  git tag dist
}

function export_patch {
  cd $gitsdir/$pkg_subdir && \
  (
    echo 'This file is part of MXE.'
    echo 'See index.html for further information.'
    echo ''
    echo 'Contains ad hoc patches for cross building.'
    echo ''
    git format-patch -p --stdout dist..HEAD | \
    sed 's/^From: .*/From: MXE/g;'
  ) > $mxedir/src/$pkg-1-fixes.patch
}

function import_patch {
  cd $gitsdir/$pkg_subdir && \
  cat $mxedir/src/$pkg-1-fixes.patch | \
  sed '/^From/,$  !d' | \
  sed s/'^From: .*'/"From: $author"/'g;' | \
  git am --keep-cr
}

if [ "$cmd" == "init" ]; then
  init_git $pkg
elif [ "$cmd" == "import" ]; then
  import_patch $pkg
elif [ "$cmd" == "export" ]; then
  export_patch $pkg
fi