Couple of mp3/flac fixes
[zcdrip] / build.sh
1 #!/bin/zsh
2
3 ## Copyright (C) 2006 - 2011 Steve Youngs
4
5 ## Author:        Steve Youngs <steve@steveyoungs.com>
6 ## Maintainer:    Steve Youngs <steve@steveyoungs.com>
7 ## Created:       <2006-08-16>
8
9 ## This file is part of zcdrip
10
11 ## Redistribution and use in source and binary forms, with or without
12 ## modification, are permitted provided that the following conditions
13 ## are met:
14 ##
15 ## 1. Redistributions of source code must retain the above copyright
16 ##    notice, this list of conditions and the following disclaimer.
17 ##
18 ## 2. Redistributions in binary form must reproduce the above copyright
19 ##    notice, this list of conditions and the following disclaimer in the
20 ##    documentation and/or other materials provided with the distribution.
21 ##
22 ## 3. Neither the name of the author nor the names of any contributors
23 ##    may be used to endorse or promote products derived from this
24 ##    software without specific prior written permission.
25 ##
26 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
27 ## IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 ## WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 ## DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 ## SUBSTITUTE GOODS OR SERVICES# LOSS OF USE, DATA, OR PROFITS# OR
33 ## BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34 ## WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
35 ## OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
36 ## IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
38 ### Commentary:
39 ## 
40 ##    Because I suck at writing makefiles
41
42 PREFIX=${PREFIX:-/usr/local}
43 BINDIR=${BINDIR:-${PREFIX}/bin}
44 ESHELL=${ESHELL:-0}
45
46 ### Code:
47 clean ()
48 {
49     rm -vf zcdrip ecdrip zdiscid
50 }
51
52 all ()
53 {
54     clean
55     sub=@VERSION@
56     tver=v0.7
57     rep=$(git describe 2>/dev/null||echo ${tver})
58     zmodload -i zsh/mapfile
59     gcc -Wall -o zdiscid zdiscid.c
60     mapfile[zcdrip]=${mapfile[zcdrip.in]/$sub/$rep}
61     [[ ${ESHELL} -eq 1 ]] && eshell
62     chmod -v 755 zcdrip
63 }
64
65 eshell ()
66 {
67     [[ -f zcdrip && -f zdiscid ]] || all
68     ln -svf zcdrip ecdrip
69 }
70
71 INSTALL=${INSTALL:-install}
72
73 _install ()
74 {
75     [[ -f zcdrip && -f zdiscid ]] || all
76
77     $INSTALL -v -m755 -d ${BINDIR}
78     $INSTALL -v -m755 zcdrip zdiscid ${BINDIR}
79     [[ -h ecdrip ]] && ln -svf zcdrip ${BINDIR}/ecdrip
80 }
81
82 ourname=${0##/}
83 help ()
84 {
85     cat<<EOF
86 Usage:  $ourname [OPTION]
87
88 OPTION can be...
89
90     all     -- builds zdiscid and zcdrip, also runs 'clean'
91     eshell  -- create eshell symlink workaround
92     clean   -- removes objects
93     install -- installs zcdrip
94
95 Hints:
96
97     If you want to install zcdrip to a directory somewhere in '${HOME}'
98     do something like...
99
100       PREFIX=${HOME} ./build.sh install
101
102     Which would put everything in ${HOME}/bin
103     or...
104
105       BINDIR=${HOME}/some/other/dir ./build.sh install
106
107     Which would put everything in ${HOME}/some/other/dir
108
109     Basically, setting PREFIX sets the install directory to PREFIX/bin
110     and setting BINDIR sets the install directory to exactly BINDIR
111
112     You can also automatically build the eshell version by setting
113     ESHELL to 1 (one)...
114
115       ESHELL=1 ./build.sh install
116
117 EOF
118 }
119
120 case $argv[1] in
121     (all) all ;;
122     (eshell) eshell ;;
123     (clean) clean ;;
124     (install) _install ;;
125     (*) help ;;
126 esac
127     
128 ### build.sh ends here
129