Mercurial > mxe-octave
annotate tools/patch-tool-mxe @ 2489:2f3353b7a313
Patch tool: Move environment variable setup to a function.
This keeps us from doing this in case of an incorrect call,
making error messages much more sane.
author | Ryan Pavlik <rpavlik@iastate.edu> |
---|---|
date | Mon, 07 May 2012 12:41:32 -0500 |
parents | d9f6c4ade221 |
children | 0db1b21402e9 |
rev | line source |
---|---|
2358
14b3f5ea78ae
Cleanup coding style via "make cleanup-style"
Volker Grabsch <vog@notjusthosting.com>
parents:
2353
diff
changeset
|
1 #!/usr/bin/env bash |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
2 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
3 # Tool for converting between MXE patch files and git repos |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
4 # Imports and exports patch files in "git format-patch" format. |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
5 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
6 cmd=$1 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
7 pkg=$2 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
8 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
9 setupEnv() { |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
10 # MXE directory |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
11 export mxedir=$(cd $(dirname $0) && cd .. && pwd) |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
12 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
13 # directory for unpacked tarballs/git repos |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
14 export gitsdir=${mxedir}/gits |
2486
a866a8b8beab
patch-tool: use relative directories
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2485
diff
changeset
|
15 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
16 mkdir -p ${gitsdir} |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
17 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
18 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
19 # John Doe <John Doe@acme.org> |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
20 export author=`git var GIT_AUTHOR_IDENT | sed 's/^\(.* [<].*[>]\).*$/\1/'` |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
21 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
22 export pkg_version=$(sed -n "s/^.* id=\"${pkg}-version\">\([^<]*\)<.*$/\1/p" "${mxedir}/index.html") |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
23 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
24 export pkg_short_version=`echo $pkg_version | sed s/'\(.*\)\.[^.]*$'/'\1'/` |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
25 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
26 export pkg_subdir=`grep '^$(PKG)_SUBDIR' $mxedir/src/$pkg.mk | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
27 sed 's/.*:= \(.*\)/\1/' | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
28 sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
29 sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
30 sed s/'$(PKG)'/$pkg/;` |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
31 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
32 export pkg_file=`grep '^$(PKG)_FILE' $mxedir/src/$pkg.mk | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
33 sed 's/.*:= \(.*\)/\1/' | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
34 sed s/'$($(PKG)_VERSION)'/$pkg_version/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
35 sed s/'$(call SHORT_PKG_VERSION,$(PKG))'/$pkg_short_version/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
36 sed s/'$($(PKG)_SUBDIR)'/$pkg_subdir/ | \ |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
37 sed s/'$(PKG)'/$pkg/;` |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
38 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
39 #echo $pkg |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
40 #echo $pkg_version |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
41 #echo $pkg_subdir |
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
42 #echo $pkg_file |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
43 |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
44 } |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
45 # init |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
46 function init_git { |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
47 setupEnv |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
48 cd $gitsdir |
2334
0ac3f45e790f
Improve indentation
Volker Grabsch <vog@notjusthosting.com>
parents:
2333
diff
changeset
|
49 echo $pkg_file | grep "\.tar\.gz" >> /dev/null && tar xf $mxedir/pkg/$pkg_file |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
50 echo $pkg_file | grep "\.tar\.bz2" >> /dev/null && tar xf $mxedir/pkg/$pkg_file |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
51 echo $pkg_file | grep "\.tar\.xz" >> /dev/null && xz -dc $mxedir/pkg/$pkg_file | tar xf - |
2334
0ac3f45e790f
Improve indentation
Volker Grabsch <vog@notjusthosting.com>
parents:
2333
diff
changeset
|
52 echo $pkg_file | grep "\.zip" >> /dev/null && unzip $mxedir/pkg/$pkg_file >> /dev/null |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
53 cd $gitsdir/$pkg_subdir && \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
54 (git init; git add -A; git commit -m "init") > /dev/null |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
55 git tag dist |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
56 } |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
57 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
58 function export_patch { |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
59 setupEnv |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
60 cd $gitsdir/$pkg_subdir && \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
61 ( |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
62 echo 'This file is part of MXE.' |
2353
99516e73b368
Move doc/index.html -> index.html
Volker Grabsch <vog@notjusthosting.com>
parents:
2334
diff
changeset
|
63 echo 'See index.html for further information.' |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
64 echo '' |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
65 echo 'Contains ad hoc patches for cross building.' |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
66 echo '' |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
67 git format-patch -p --stdout dist..HEAD | \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
68 sed 's/^From: .*/From: MXE/g;' |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
69 ) > $mxedir/src/$pkg-1-fixes.patch |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
70 } |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
71 |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
72 function import_patch { |
2489
2f3353b7a313
Patch tool: Move environment variable setup to a function.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2488
diff
changeset
|
73 setupEnv |
2333
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
74 cd $gitsdir/$pkg_subdir && \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
75 cat $mxedir/src/$pkg-1-fixes.patch | \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
76 sed '/^From/,$ !d' | \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
77 sed s/'^From: .*'/"From: $author"/'g;' | \ |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
78 git am --keep-cr |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
79 } |
f653602a0500
Rebrand to new project name MXE
Volker Grabsch <vog@notjusthosting.com>
parents:
diff
changeset
|
80 |
2488
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
81 case "$cmd" in |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
82 init) |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
83 init_git $pkg |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
84 ;; |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
85 import) |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
86 import_patch $pkg |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
87 ;; |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
88 export) |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
89 export_patch $pkg |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
90 ;; |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
91 *) |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
92 echo "Unrecognized command '${cmd}'" >&2 |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
93 cat <<EOS |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
94 Usage: $0 COMMAND PACKAGENAME |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
95 where COMMAND is one of: |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
96 init - create a git directory for the package with the raw source |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
97 import - apply the "pkgname-1-fixes.patch" patch commits |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
98 export - create/replace the "pkgname-1-fixes.patch" patch with a patch of all commits since init. |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
99 EOS |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
100 exit 1 |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
101 ;; |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
102 esac |
d9f6c4ade221
Patch tool: replace elifs with case. Also handles errors.
Ryan Pavlik <rpavlik@iastate.edu>
parents:
2487
diff
changeset
|
103 |