summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: ab08f703eec018e09c97487530d20634587439f5 (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Maintainer: Eugene Cherny <iam@oscii.ru>
pkgname=cabbage-git
pkgrel=1 
pkgver=2.0.0r1188
pkgdesc='A framework for audio software development'
arch=('x86_64')
url="http://cabbageaudio.com/"
license=('GPLv3')
makedepends=('freeglut' 'curl' 'jack' 'libxcomposite' 'libxrandr' 'libxcursor'
             'libx11' 'libxinerama' 'mesa' 'gtk3' 'vim' 'dos2unix')
depends=('csound' 'steinberg-vst36')
conflicts=('cabbage')
provides=('cabbage')
source=('git+https://github.com/rorywalsh/cabbage.git#branch=master'
        'git+https://github.com/WeAreROLI/JUCE.git#tag=5.2.0'
        'fix_default_dirs.patch'
        'cabbage.png'
        'Cabbage.desktop'
        'CabbageLite.desktop')
md5sums=('SKIP'
         'SKIP'
         '44c102c1fbd8e5b1e784136f3bcba7dd'
         'c3c8e35dd46c86f22a3565aa4dd828a8'
         '35cfc89844c90769f4dc4f8309b340b1'
         'c39a85709e31e03a0850f2e324a4faea')

_projucer_dir="JUCE/extras/Projucer/Builds/LinuxMakefile/build/"
_projucer="${_projucer_dir}/Projucer"

function patch_strings_in_file() {
    # Source (Johan Hedin):
    # http://everydaywithlinux.blogspot.com/2012/11/patch-strings-in-binary-files-with-sed.html
    # Slight modification by Colin Wallace to force the pattern to capture the entire line
    # Usage: patch_strings_in_file <file> <pattern> <replacement>
    # replaces all occurances of <pattern> with <replacement> in <file>, padding
    # <replacement> with null characters to match the length
    # Unlike sed or patch, this works on binary files
    local FILE="$1"
    local PATTERN="$2"
    local REPLACEMENT="$3"

    # Find all unique strings in FILE that contain the pattern 
    STRINGS=$(strings ${FILE} | grep "^${PATTERN}$" | sort -u -r)

    if [ "${STRINGS}" != "" ] ; then
        echo "File '${FILE}' contains strings equal to '${PATTERN}':"

        for OLD_STRING in ${STRINGS} ; do
            # Create null terminated ASCII HEX representations of the strings
            OLD_STRING_HEX="$(echo -n ${OLD_STRING} | xxd -g 0 -u -ps -c 256)00"
            NEW_STRING_HEX="$(echo -n ${REPLACEMENT} | xxd -g 0 -u -ps -c 256)00"

            if [ ${#NEW_STRING_HEX} -le ${#OLD_STRING_HEX} ] ; then
                # Pad the replacement string with null terminations so the
                # length matches the original string
                while [ ${#NEW_STRING_HEX} -lt ${#OLD_STRING_HEX} ] ; do
                    NEW_STRING_HEX="${NEW_STRING_HEX}00"
                done

                # Now, replace every occurrence of OLD_STRING with NEW_STRING 
                echo -n "Replacing ${OLD_STRING} with ${REPLACEMENT}... "
                hexdump -ve '1/1 "%.2X"' ${FILE} | \
                sed "s/${OLD_STRING_HEX}/${NEW_STRING_HEX}/g" | \
                xxd -r -p > ${FILE}.tmp
                chmod --reference ${FILE} ${FILE}.tmp
                mv ${FILE}.tmp ${FILE}
                echo "Done!"
            else
                echo "New string '${NEW_STRING}' is longer than old" \
                     "string '${OLD_STRING}'. Skipping."
            fi
        done
    fi
}

prepare() {
  cd "${srcdir}/cabbage"
  for f in *jucer; do
    sed -i "s@/usr/local/include/csound@/usr/include/csound@g" "$f"
    sed -i "s@/usr/local/lib@/usr/lib@g" "$f"
  done

  b="${srcdir}/cabbage/Builds/LinuxMakefile/buildCabbage"
  sed -i "s@/usr/local/include/csound@/usr/include/csound@g" "$b"
  sed -i "/CabbageBuild\/cabbage.desktop/d" "$b"

  dos2unix "${srcdir}/cabbage/Source/Settings/CabbageSettings.cpp"
  patch -p1 < ../../fix_default_dirs.patch
}

pkgver() {
	cd "${srcdir}/cabbage"
	printf "2.0.0r%s" "$(git rev-list --count HEAD)"
}

build() {
  # Projucer

  sed -i -e "s/JUCER_ENABLE_GPL_MODE 0/JUCER_ENABLE_GPL_MODE 1/" \
            "${srcdir}/JUCE/extras/Projucer/JuceLibraryCode/AppConfig.h"
  cd "${srcdir}/JUCE/extras/Projucer/Builds/LinuxMakefile/"
  make -j4

  # a hack to make Projucer use the system's VST header path
  patch_strings_in_file "${srcdir}/${_projucer}" "~/SDKs/VST_SDK/VST3_SDK" "/usr/include/vst36"
  # will be replaced with the following once Cabbage is ported to JUCE 5.3.0
  # "${srcdir}/${_projucer_dir}" --set-global-search-path linux vst3Path /usr/include/vst36/

  # Cabage

  cd "${srcdir}/cabbage/Builds/LinuxMakefile"
  ./buildCabbage
}

package() {
  install -Dm644 cabbage.png "${pkgdir}/usr/share/icons/hicolor/512x512/apps/cabbage.png"
  install -Dm644 Cabbage.desktop "${pkgdir}/usr/share/applications/Cabbage.desktop"
  install -Dm644 Cabbage.desktop "${pkgdir}/usr/share/applications/CabbageLite.desktop"

  cd "${srcdir}/cabbage/Builds/LinuxMakefile/CabbageBuild/"

  for f in Cabbage CabbageLite CabbagePluginEffect.so CabbagePluginSynth.so opcodes.txt; do
    install -Dm755 "$f" "${pkgdir}/usr/bin/$f"
  done

  install -d "${pkgdir}/usr/share/doc/cabbage/examples"
  cp -r Examples/* "${pkgdir}/usr/share/doc/cabbage/examples/"
  chmod -R 755 "${pkgdir}/usr/share/doc/cabbage"
}