Adjusted compilation optimisation flags to tune per target processor. Multi-architect...
[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     CFLAGS="-mtune=x86_64 ${CFLAGS}"
59     ;;
60   # Mac OS X 10.6 x86_64
61   "snowleopardx64")
62     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
63 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.6.sdk"
64     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.6.sdk"
65     MACOSX_VERSION="-mmacosx-version-min=10.6"
66     ARCH="-arch x86_64"
67     STARTUP="LaunchDaemon"
68     CFLAGS="-mtune=x86_64 ${CFLAGS}"
69     ;;
70   # Mac OS X 10.6 all supported architectures
71   "snowleopard")
72     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
73 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.6.sdk"
74     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.6.sdk"
75     MACOSX_VERSION="-mmacosx-version-min=10.6"
76     ARCH="-arch x86_64 -arch i386"
77     STARTUP="LaunchDaemon"
78     ;;
79   # Mac OS X 10.6 i386
80   "snowleopardi386")
81     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
82 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.6.sdk"
83     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.6.sdk"
84     MACOSX_VERSION="-mmacosx-version-min=10.6"
85     ARCH="-arch i386"
86     STARTUP="LaunchDaemon"
87     CFLAGS="-mtune=i386 ${CFLAGS}"
88     ;;
89   # Mac OS X 10.5 and all later releases
90   "leopardupwards")
91     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
92 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
93     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.5.sdk"
94     MACOSX_VERSION="-mmacosx-version-min=10.5"
95     ARCH="-arch x86_64 -arch i386 -arch ppc"
96     STARTUP="LaunchDaemon"
97     ;;
98   # Mac OS X 10.5 all supported architectures
99   "leopard")
100     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
101 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
102     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.5.sdk"
103     MACOSX_VERSION="-mmacosx-version-min=10.5"
104     ARCH="-arch i386 -arch ppc"
105     STARTUP="LaunchDaemon"
106     ;;
107   # Mac OS X 10.5 i386
108   "leopardi386")
109     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
110 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
111     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.5.sdk"
112     MACOSX_VERSION="-mmacosx-version-min=10.5"
113     ARCH="-arch i386"
114     STARTUP="LaunchDaemon"
115     CFLAGS="-mtune=i386 ${CFLAGS}"
116     ;;
117   # Mac OS X 10.5 PPC
118   "leopardppc")
119     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
120 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
121     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.5.sdk"
122     MACOSX_VERSION="-mmacosx-version-min=10.5"
123     ARCH="-arch ppc"
124     STARTUP="LaunchDaemon"
125     CFLAGS="-mtune=G5 ${CFLAGS}"
126     ;;
127   # Mac OS X 10.4 all supported architectures
128   "tiger")
129     XCODE_PATH="/Developer"
130 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.4u.sdk"
131     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.4u.sdk"
132     MACOSX_VERSION="-mmacosx-version-min=10.4"
133     ARCH="-arch i386 -arch ppc"
134     STARTUP="LaunchDaemon"
135     ;;
136   # Mac OS X 10.4 i386
137   "tigeri386")
138     XCODE_PATH="/Developer"
139 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.4u.sdk"
140     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.4u.sdk"
141     MACOSX_VERSION="-mmacosx-version-min=10.4"
142     ARCH="-arch i386"
143     STARTUP="LaunchDaemon"
144     CFLAGS="-mtune=i386 ${CFLAGS}"
145     ;;
146   # Mac OS X 10.4 PPC
147   "tigerppc")
148     XCODE_PATH="/Developer"
149 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.4u.sdk"
150     SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.4u.sdk"
151     MACOSX_VERSION="-mmacosx-version-min=10.4"
152     ARCH="-arch ppc"
153     STARTUP="LaunchDaemon"
154     CFLAGS="-mtune=G5 ${CFLAGS}"
155     ;;
156   # Mac OS X 10.3 PPC
157   "panther")
158     XCODE_PATH="/Developer"
159 #    SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.3.9.sdk"
160     SYSROOT="-isysroot /Developer/SDKs/MacOSX10.3.9.sdk"
161     MACOSX_VERSION="-mmacosx-version-min=10.3"
162     ARCH="-arch ppc"
163     STARTUP="StartupItem"
164     CFLAGS="-mtune=G5 ${CFLAGS}"
165     ;;
166   # default
167   *)
168     XCODE_PATH=""
169     SYSROOT=""
170     MACOSX_VERSION=""
171     ARCH=""
172     STARTUP=""
173     ;;
174 esac
175
176
177 #========================================
178 #  host specific settings
179 #========================================
180
181 #
182 # darwin os major release number
183 #
184 darwin_major_rel_num="`/usr/bin/uname -r | /usr/bin/sed 's/\..*//'`"
185
186 #
187 # check the release number
188 #
189 case "${darwin_major_rel_num}" in
190   # Mac OS X 10.5 or higher
191   9|1*)
192     GNAME="`/usr/bin/dscl /Local/Default -list /groups | /usr/bin/grep -E '^(_)?privoxy?'`"
193     UNAME="`/usr/bin/dscl /Local/Default -list /users | /usr/bin/grep -E '^(_)?privoxy?'`"
194     SCRIPT="privoxy-create-dscl.sh"
195     OPTS="--with-user=_privoxy --with-group=_privoxy"
196     ;;
197   # Mac OS X 10.4, 10.3
198   8|7)
199     GNAME="`/usr/bin/nireport . /groups name | /usr/bin/grep -E '^privoxy?'`"
200     UNAME="`/usr/bin/nireport . /users name | /usr/bin/grep -E '^privoxy?'`"
201     SCRIPT="privoxy-create-nicl.sh"
202     OPTS="--with-user=privoxy --with-group=privoxy"
203     ;;
204   # default
205   *)
206     GNAME=""
207     UNAME=""
208     SCRIPT=""
209     OPTS=""
210     ;;
211 esac
212
213 #
214 # identify the directory containing Privoxy's source
215 #
216 cd ..
217 DIRS_FOUND=0
218 SOURCE_DIR=""
219 if [ -d dist ]; then
220         DIRS_FOUND=1
221 fi
222 if [ -d current ]; then
223         DIRS_FOUND=$(( DIRS_FOUND + 10 ))
224 fi
225 case "${DIRS_FOUND}" in
226         # only 'current' found
227         10)
228                 SOURCE_DIR="current"
229         ;;
230         # only 'dist' found
231         1)
232                 SOURCE_DIR="dist"
233         ;;
234         # either both or neither found
235         11|0)
236                 read -p 'Could not select the Privoxy source directory. Please supply the directory name (e.g. current or dist): ' SOURCE_DIR
237         ;;
238 esac
239 cd OSXPackageBuilder
240 echo "Using ../${SOURCE_DIR} as location of Privoxy source"