Text rewritten for better clarity
[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 macsetup module.
32 #
33
34 #========================================
35 #  target specific settings
36 #========================================
37
38 #
39 # mac os x release name
40 #
41 release_name=$1
42
43 #
44 # check the release name
45 #
46 case "${release_name}" in
47   # Mac OS X 10.7 (64bit only)
48   "lion")
49     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
50     SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.7.sdk"
51     MACOSX_VERSION="-mmacosx-version-min=10.7"
52     ARCH="-arch x86_64"
53     STARTUP="LaunchDaemon"
54     ;;
55   # Mac OS X 10.6 64bit
56   "snowleopard64")
57     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
58     SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.6.sdk"
59     MACOSX_VERSION="-mmacosx-version-min=10.6"
60     ARCH="-arch x86_64"
61     STARTUP="LaunchDaemon"
62     ;;
63   # Mac OS X 10.6
64   "snowleopard")
65     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
66     SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.6.sdk"
67     MACOSX_VERSION="-mmacosx-version-min=10.6"
68     ARCH="-arch i386"
69     STARTUP="LaunchDaemon"
70     ;;
71   # Mac OS X 10.5 and all later releases
72   "leopardupwards")
73     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
74     SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
75     MACOSX_VERSION="-mmacosx-version-min=10.5"
76     ARCH="-arch x86_64 -arch i386 -arch ppc"
77     STARTUP="LaunchDaemon"
78     ;;
79   # Mac OS X 10.5
80   "leopard")
81     XCODE_PATH="`/usr/bin/xcode-select -print-path`"
82     SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.5.sdk"
83     MACOSX_VERSION="-mmacosx-version-min=10.5"
84     ARCH="-arch i386 -arch ppc"
85     STARTUP="LaunchDaemon"
86     ;;
87   # Mac OS X 10.4
88   "tiger")
89     XCODE_PATH="/Developer"
90     SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.4u.sdk"
91     MACOSX_VERSION="-mmacosx-version-min=10.4"
92     ARCH="-arch i386 -arch ppc"
93     STARTUP="LaunchDaemon"
94     ;;
95   # Mac OS X 10.3
96   "panther")
97     XCODE_PATH="/Developer"
98     SYSROOT="-isysroot ${XCODE_PATH}/SDKs/MacOSX10.3.9.sdk"
99     MACOSX_VERSION="-mmacosx-version-min=10.3"
100     ARCH="-arch ppc"
101     STARTUP="StartupItem"
102     ;;
103   # default
104   *)
105     XCODE_PATH=""
106     SYSROOT=""
107     MACOSX_VERSION=""
108     ARCH=""
109     STARTUP=""
110     ;;
111 esac
112
113
114 #========================================
115 #  host specific settings
116 #========================================
117
118 #
119 # darwin os major release number
120 #
121 darwin_major_rel_num="`/usr/bin/uname -r | /usr/bin/sed 's/\..*//'`"
122
123 #
124 # check the release number
125 #
126 case "${darwin_major_rel_num}" in
127   # Mac OS X 10.5 or higher
128   9|1*)
129     GNAME="`/usr/bin/dscl /Local/Default -list /groups | /usr/bin/grep -E '^(_)?privoxy?'`"
130     UNAME="`/usr/bin/dscl /Local/Default -list /users | /usr/bin/grep -E '^(_)?privoxy?'`"
131     SCRIPT="privoxy-create-dscl.sh"
132     OPTS="--with-user=_privoxy --with-group=_privoxy"
133     ;;
134   # Mac OS X 10.4, 10.3
135   8|7)
136     GNAME="`/usr/bin/nireport . /groups name | /usr/bin/grep -E '^privoxy?'`"
137     UNAME="`/usr/bin/nireport . /users name | /usr/bin/grep -E '^privoxy?'`"
138     SCRIPT="privoxy-create-nicl.sh"
139     OPTS="--with-user=privoxy --with-group=privoxy"
140     ;;
141   # default
142   *)
143     GNAME=""
144     UNAME=""
145     SCRIPT=""
146     OPTS=""
147     ;;
148 esac
149
150 #
151 # identify the directory containing Privoxy's source
152 #
153 cd ..
154 DIRS_FOUND=0
155 SOURCE_DIR=""
156 if [ -d dist ]; then
157         DIRS_FOUND=1
158 fi
159 if [ -d current ]; then
160         DIRS_FOUND=$(( DIRS_FOUND + 10 ))
161 fi
162 case "${DIRS_FOUND}" in
163         # only 'current' found
164         10)
165                 SOURCE_DIR="current"
166         ;;
167         # only 'dist' found
168         1)
169                 SOURCE_DIR="dist"
170         ;;
171         # either both or neither found
172         11|0)
173                 read -p 'Could not select the Privoxy source directory. Please supply the directory name: ' SOURCE_DIR
174         ;;
175 esac
176 cd OSXPackageBuilder
177 echo "Using ../${SOURCE_DIR} as location of Privoxy source"