summaryrefslogtreecommitdiff
path: root/configure
blob: 514b3b554dfebecf0f2cc89930a3c7cb9f786cfb (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/sh
#
#  Copyright (c) 2009 Samuel Lidén Borell <samuel@slbdata.se>
# 
#  Permission is hereby granted, free of charge, to any person obtaining a copy
#  of this software and associated documentation files (the "Software"), to deal
#  in the Software without restriction, including without limitation the rights
#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#  copies of the Software, and to permit persons to whom the Software is
#  furnished to do so, subject to the following conditions:
#  
#  The above copyright notice and this permission notice shall be included in
#  all copies or substantial portions of the Software.
#  
#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#  THE SOFTWARE.
#

prefixSet=""
prefix="/usr/local"
execprefix=""

pluginPathSet=""
pluginPaths="/usr/lib/mozilla/plugins"

userPluginPath="$HOME/.mozilla/plugins"
userPrefix="$HOME/.local"

error=""

basedir=`dirname "$0"`

while [ "$#" != "0" ]; do
    flag="$1"
    shift
    case "$flag" in
    --help)
        echo "Usage: $0 [options]

This script creates a build configuration. The default options are to
install system-wide, into /usr/local, and use /usr/lib/mozilla/plugins
as the plugin directory.

Options:

    --help                Shows this help.
    --prefix=PATH         Sets the installation prefix. [/usr/local]
    --exec-prefix=PATH    Sets the installation prefix for executable files.
                          The default is to use the same prefix for all files.
    --plugin-path=PATH    Sets the NPAPI plugin path [/usr/lib/mozilla/plugin]
                          This option may be repeated if you want to create
                          plugin links in several places. Do not include the
                          prefix in the path.
    --current-user        Selects a per-user installation. Equivalent to:
                              --prefix=$userPrefix
                              --plugin-path=$userPluginPath
"
        exit 0
        ;;
    --prefix=*)
        prefix=${flag#--prefix=}
        prefixSet=1
        ;;
    --exec-prefix=*)
        execprefix=${flag#--exec-prefix=}
        ;;
    --plugin-path=*)
        path=${flag#--plugin-path=}
        path=${path%/}
        if [ -z "$pluginPathSet" ]; then
            pluginPathSet=1
            pluginPaths="$path"
        else
            pluginPaths="$pluginPaths $path"
        fi
        ;;
    --current-user)
        if [ -z "$prefixSet" ]; then
            prefix="$userPrefix"
        fi
        
        if [ -z "$pluginPathSet" ]; then
            pluginPathSet=1
            pluginPaths="$userPluginPath"
        else
            pluginPaths="$pluginPaths $userPluginPath"
        fi
        ;;
    --internal--get-define=*)
        name=${flag#--internal--get-define=}
        printf '#include "%s"\n%s\n' "$basedir/common/defines.h" "$name" | cpp - | sed 's/#[^\n]*//g' | tr -d '\n' | sed 's/" "//g' | tr -d '\"'
        exit 0
        ;;
    --internal--remove-link)
        link="$1"
        target="$2"
        shift 2
        [ ! -h "$link" ] || [ "`readlink "$link"`" != "$target" ] || rm -f "$link"
        exit 0
        ;;
    *)
        echo "Invalid option: $flag"
        error=1
        ;;
    esac
done

if [ ! -r "$basedir/common/defines.h" ]; then
    echo "ERROR: Source code not found."
    error=1
fi

if [ -n "$error" ]; then
    exit 2
fi


### Prefixes
prefixPath="$prefix"

if [ -z "$execprefix" ]; then
    execPath="$prefix"
else
    execPath="$execprefix"
fi

echo "Prefix: $prefixPath"
if [ -n "$execprefix" ]; then
    echo "Executable/library prefix: $execPath"
fi


### Plugin paths
hasPaths=""
for path in $pluginPaths; do
    hasPaths="1"
    if [ "$path" = "${path%/plugins}" ]; then
    	echo "WARNING: Plugin path $path doesn't end with /plugins." >&2
    elif [ -d "$path" ]; then
        echo "Plugin path: $path"
    else
    	echo "WARNING: Plugin path $path doesn't exist!"
    	if [ -z "$pluginPathSet" ]; then
            echo "         You may need to change it with the --plugin-path=... option." >&2
        fi
    fi
done

if [ -z "$hasPaths" ]; then
    echo "No plugin paths specified."
fi


### Check dependencies
utilities="make pkg-config msgfmt"
depError=""
if ! type $utilities > /dev/null 2> /dev/null; then
    echo "Error: Missing commands:" >&2
    for utility in $utilities; do
        if ! type "$utility" > /dev/null 2> /dev/null; then
            echo "  $utility" >&2
            depError=1
        fi
    done
fi

oldifs=IFS
IFS=";"
pkgconfigDeps="gtk+-2.0 >= 2.12;glib-2.0;nss >= 3.10;nspr"

if ! pkg-config --exists $pkgconfigDeps; then
    echo "Error: Unsatisfied dependencies: " >&2
    for dep in $pkgconfigDeps; do
        pkg-config --exists $dep || echo "  $dep" >&2
    done
    depError=1
fi
IFS=oldifs

if [ -n "$depError" ]; then
    exit 1
fi

### Write configuration
CONFFILE="$basedir/common/config.h"

echo "
/* This file is automatically generated.
   Run the configure script to change the configuration. */

#define PREFIX \"$prefixPath\"
#define EPREFIX \"$execPath\"
#define NPAPI_PLUGIN_PATHS \"$pluginPaths\"
" > $CONFFILE


### Display success message
cancreate() {
    if [ -w "$1" ]; then
        return 0
    elif [ ! -e "$1" ]; then
        cancreate `dirname "$1"`
        return $?
    else
        return 1
    fi
}

if cancreate "$prefixPath" && cancreate "$execPath"; then
    INSTALLCMD="make install"
else
    INSTALLCMD="sudo make install"
fi

echo "Wrote $CONFFILE."
echo "Type \"make\" to compile, and then \"$INSTALLCMD\" to install."