New-style package project for creating PPC installation package
[OSXPackageBuilder.git] / common.sh
1 #!/bin/sh
2
3 # File        :  common.sh
4 #
5 # Purpose     :  Establish settings common to the build and privoxy-create
6 #                scripts.
7 #
8 # Copyright   :  Written by and Copyright (C) 2001-2012 the
9 #                Privoxy team. http://www.privoxy.org/
10 #
11 #                This program is free software; you can redistribute it
12 #                and/or modify it under the terms of the GNU General
13 #                Public License as published by the Free Software
14 #                Foundation; either version 2 of the License, or (at
15 #                your option) any later version.
16 #
17 #                This program is distributed in the hope that it will
18 #                be useful, but WITHOUT ANY WARRANTY; without even the
19 #                implied warranty of MERCHANTABILITY or FITNESS FOR A
20 #                PARTICULAR PURPOSE.  See the GNU General Public
21 #                License for more details.
22 #
23 #                The GNU General Public License should be included with
24 #                this file.  If not, you can view it at
25 #                http://www.gnu.org/copyleft/gpl.html
26 #                or write to the Free Software Foundation, Inc.,
27 #                51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 #                USA
29 #
30 # Modification : If you modify this file please consider whether your 
31 #                changes ought to be passed back to the OSXPackageBuilder
32 #                module.
33 #
34
35 #========================================
36 #  target specific settings
37 #========================================
38
39 #
40 # mac os x release name
41 #
42 release_name=$1
43
44 #
45 # check the release name and assign the build variables accordingly
46 #
47 # NOTE: SYSROOT ought to be programmatically determined using XCODE_PATH, however since upgrading my build environment to El Capitan xcode-select returns a non-useful path, hence I am forced to set the SYSROOT explicitly for my build environment, which is now a hybrid of XCode 3.2.6 'running' on OS X 10.11. I am not going to risk upgrading XCode for fear of losing the ability to target down-level OS X versions.
48 #
49 case "${release_name}" in
50   # Mac OS X 10.7 (x86_64 only)
51   "lion")
52     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
53 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.7.sdk"
54     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.7.sdk"
55     MACOSX_VERSION="-mmacosx-version-min=10.7"
56     ARCH="-arch x86_64"
57     STARTUP="LaunchDaemon"
58     ;;
59   # Mac OS X 10.6 x86_64
60   "snowleopardx64")
61     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
62 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.6.sdk"
63     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.6.sdk"
64     MACOSX_VERSION="-mmacosx-version-min=10.6"
65     ARCH="-arch x86_64"
66     STARTUP="LaunchDaemon"
67     ;;
68   # Mac OS X 10.6 all supported architectures
69   "snowleopard")
70     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
71 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.6.sdk"
72     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.6.sdk"
73     MACOSX_VERSION="-mmacosx-version-min=10.6"
74     ARCH="-arch x86_64 -arch i386"
75     STARTUP="LaunchDaemon"
76     ;;
77   # Mac OS X 10.6 i386
78   "snowleopardi386")
79     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
80 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.6.sdk"
81     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.6.sdk"
82     MACOSX_VERSION="-mmacosx-version-min=10.6"
83     ARCH="-arch i386"
84     STARTUP="LaunchDaemon"
85     ;;
86   # Mac OS X 10.5 and all later releases
87   "leopardupwards")
88     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
89 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
90     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.5.sdk"
91     MACOSX_VERSION="-mmacosx-version-min=10.5"
92     ARCH="-arch x86_64 -arch i386 -arch ppc"
93     STARTUP="LaunchDaemon"
94     ;;
95   # Mac OS X 10.5 all supported architectures
96   "leopard")
97     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
98 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
99     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.5.sdk"
100     MACOSX_VERSION="-mmacosx-version-min=10.5"
101     ARCH="-arch i386 -arch ppc"
102     STARTUP="LaunchDaemon"
103     ;;
104   # Mac OS X 10.5 i386
105   "leopardi386")
106     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
107 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
108     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.5.sdk"
109     MACOSX_VERSION="-mmacosx-version-min=10.5"
110     ARCH="-arch i386"
111     STARTUP="LaunchDaemon"
112     ;;
113   # Mac OS X 10.5 PPC
114   "leopardppc")
115     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
116 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
117     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.5.sdk"
118     MACOSX_VERSION="-mmacosx-version-min=10.5"
119     ARCH="-arch ppc"
120     STARTUP="LaunchDaemon"
121     ;;
122   # Mac OS X 10.4 all supported architectures
123   "tiger")
124     XCODE_PATH="/Developer"
125 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.4u.sdk"
126     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.4u.sdk"
127     MACOSX_VERSION="-mmacosx-version-min=10.4"
128     ARCH="-arch i386 -arch ppc"
129     STARTUP="LaunchDaemon"
130     ;;
131   # Mac OS X 10.4
132   "tigeri386")
133     XCODE_PATH="/Developer"
134 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.4u.sdk"
135     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.4u.sdk"
136     MACOSX_VERSION="-mmacosx-version-min=10.4"
137     ARCH="-arch i386"
138     STARTUP="LaunchDaemon"
139     ;;
140   # Mac OS X 10.4
141   "tigerppc")
142     XCODE_PATH="/Developer"
143 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.4u.sdk"
144     SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.4u.sdk"
145     MACOSX_VERSION="-mmacosx-version-min=10.4"
146     ARCH="-arch ppc"
147     STARTUP="LaunchDaemon"
148     ;;
149   # Mac OS X 10.3
150   "panther")
151     XCODE_PATH="/Developer"
152 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.3.9.sdk"
153     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.3.9.sdk"
154     MACOSX_VERSION="-mmacosx-version-min=10.3"
155     ARCH="-arch ppc"
156     STARTUP="StartupItem"
157     ;;
158   # default
159   *)
160     XCODE_PATH=""
161     SYSROOT=""
162     MACOSX_VERSION=""
163     ARCH=""
164     STARTUP=""
165     ;;
166 esac
167
168
169 #========================================
170 #  host specific settings
171 #========================================
172
173 #
174 # darwin os major release number
175 #
176 darwin_major_rel_num="`/usr/bin/uname -r | /usr/bin/sed 's/\..*//'`"
177
178 #
179 # check the release number
180 #
181 case "${darwin_major_rel_num}" in
182   # Mac OS X 10.5 or higher
183   9|1*)
184     GNAME="`/usr/bin/dscl /Local/Default -list /groups | /usr/bin/grep -E '^(_)?privoxy?'`"
185     UNAME="`/usr/bin/dscl /Local/Default -list /users | /usr/bin/grep -E '^(_)?privoxy?'`"
186     SCRIPT="privoxy-create-dscl.sh"
187     OPTS="--with-user=_privoxy --with-group=_privoxy"
188     ;;
189   # Mac OS X 10.4, 10.3
190   8|7)
191     GNAME="`/usr/bin/nireport . /groups name | /usr/bin/grep -E '^privoxy?'`"
192     UNAME="`/usr/bin/nireport . /users name | /usr/bin/grep -E '^privoxy?'`"
193     SCRIPT="privoxy-create-nicl.sh"
194     OPTS="--with-user=privoxy --with-group=privoxy"
195     ;;
196   # default
197   *)
198     GNAME=""
199     UNAME=""
200     SCRIPT=""
201     OPTS=""
202     ;;
203 esac
204
205 #
206 # identify the directory containing Privoxy's source
207 #
208 cd ..
209 DIRS_FOUND=0
210 SOURCE_DIR=""
211 if [ -d dist ]; then
212         DIRS_FOUND=1
213 fi
214 if [ -d current ]; then
215         DIRS_FOUND=$(( DIRS_FOUND + 10 ))
216 fi
217 case "${DIRS_FOUND}" in
218         # only 'current' found
219         10)
220                 SOURCE_DIR="current"
221         ;;
222         # only 'dist' found
223         1)
224                 SOURCE_DIR="dist"
225         ;;
226         # either both or neither found
227         11|0)
228                 read -p 'Could not select the Privoxy source directory. Please supply the directory name (e.g. current or dist): ' SOURCE_DIR
229         ;;
230 esac
231 cd OSXPackageBuilder
232 echo "Using ../${SOURCE_DIR} as location of Privoxy source"