summaryrefslogtreecommitdiff
path: root/configure
blob: c4582bad7ffba6a956fc69dc6f65728835084fc8 (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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#! /bin/sh

# This file is part of AKFQuiz
#
# AKFQuiz is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# AKFQuiz is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

#####################################################################
# configure here:

PREFIX=/usr/local
CGIDIR=/usr/lib/cgi-bin
EXAMDIR=""

# for modified versions use a variant-name please
VARIANT=""
VARIANT="-testing"
NAME="AKFQuiz"

MAINVERSION=4
SUBVERSION=5
REVISION=0
PKGVERSION=0

VERSION=$MAINVERSION.$SUBVERSION.$REVISION
SVERSION=$MAINVERSION$SUBVERSION$REVISION

SRCDIR="."

# either a E-Mail address, or empty
BUGMAIL="[email protected]"

#####################################################################
# don't change these values

SOUND=no

#####################################################################
# functions

help() {
cat <<EOF
./configure [options]

options:
  -h | --help
  --srcdir=
  --prefix=
  --cgidir=
  --examdir=
  --variant=
  --arch=
  --sys=
  --with-fpc
  --with-gpc
  --with-grx
  --with-xw32
  --with-xw64
  --with-xarm
  --enable-exam
EOF
exit
}

warn() {
  echo "$@" 1>&2
  }

error() {
  echo "error: $@" 1>&2
  exit 1
  }
  
getcompiler() {
  # search for available compiler
  echo "checking for fpc or gpc..."
  if which fpc
  then COMPILER=fpc
  elif which gpc
  then COMPILER=gpc
  else error "neither gpc nor fpc found"
  fi
  }

create_rc() {
  sed < "srcbin/w32/rc.in" > "srcbin/w32/$1.rc" \
    -e "s/^\(FILEVERSION\).*/\1 $MAINVERSION, $SUBVERSION, $REVISION, 0/" \
    -e "s/^\(PRODUCTVERSION\).*/\1 $MAINVERSION, $SUBVERSION, $REVISION, 0/" \
    -e "s/\(.*VALUE \"FileDescription\", *\)\".*\"/\1\"$2\"/" \
    -e "s/\(.*VALUE \"FileVersion\", *\)\".*\"/\1\"$VERSION$VARIANT\"/" \
    -e "s/\(.*VALUE \"InternalName\", *\)\".*\"/\1\"$1\"/" \
    -e "s/\(.*VALUE \"OriginalFilename\", *\)\".*\"/\1\"$1.exe\"/" \
    -e "s/\(.*VALUE \"Comments\", *\)\".*\"/\1\"$3\"/" \
    -e "s/\(.*VALUE \"ProductName\", *\)\".*\"/\1\"$NAME$VARIANT\"/" \
    -e "s/\(.*VALUE \"ProductVersion\", *\)\".*\"/\1\"$VERSION\"/"
    }

notsupported() {
  warn "configure: warning: $1 not supported"
  }

#####################################################################
# main program:

SYS=`uname -s`
ARCH=`uname -m`
# rename architecture
case "$ARCH" in
   i?86) ARCH=x86 ;;
esac

# system specific settings
case "$SYS" in
  *Linux*) NEEDPTHREAD="yes" ;;
  *) NEEDPTHREAD="no" ;;
esac

# check parameter
while [ $# -gt 0 ] 
do
  case "$1" in
    -h | --help)   help ;;
    --target=gpc | --target=fpc | --target=xw32 | --target=xarm)
                   error "old usage for --target no longer supported!" ;;
    #--srcdir=*)    SRCDIR=`echo "$1" | sed -e "s/--srcdir=\(.*\)/\1/"` ;;
    --srcdir=*)    notsupported --srcdir ;; # yet to be implemented
    --build=*)     notsupported --build ;; # yet to be implemented
    --host=*)      notsupported --host ;;  # yet to be implemented
    --target=*)    notsupported --target ;; # yet to be implemented
    --with-gpc)    COMPILER=gpc ;;
    --with-grx)    COMPILER=grx ;;
    --with-fpc)    COMPILER=fpc ;;
    --with-xw32)   COMPILER=xw32 ;;
    --with-xw64)   COMPILER=xw64 ;;
    --with-xarm)   COMPILER=xarm ;;
    --with-*)      ;; # ignore (see GNU Coding Standards)
    --gpc)         COMPILER=gpc ;;
    --grx)         COMPILER=grx ;;
    --fpc)         COMPILER=fpc ;;
    --xw32)        COMPILER=xw32 ;;
    --xw32)        COMPILER=xw64 ;;
    --xarm)        COMPILER=xarm ;;
    --enable-sound|--enable-sound=yes|--disable-sound=no) SOUND=yes ;;
    --disable-sound|--disable-sound=yes|--enable-sound=no) SOUND=no ;;
    --enable-exam|--enable-exam=yes|--disable-exam=no)
                   EXAMDIR="cgi-data/exam" ;;
    --disable-exam|--disable-exam=yes|--enable-exam=no) EXAMDIR="" ;;
    --enable-*)    ;; # ignore (see GNU Coding Standards)
    --disable-*)   ;; # ignore (see GNU Coding Standards)
    --prefix=*)    PREFIX=`echo "$1" | sed -e "s/--prefix=\(.*\)/\1/"` ;;
    --mandir=*)    notsupported --mandir ;; # yet to be implemented
    --infodir=*)    ;; # ignore - not used
    --sysconfdir=*) ;; # ignore - not used
    --libexecdir=*) ;; # ignore - not used
    --cgidir=*)    CGIDIR=`echo "$1" | sed -e "s/--cgidir=\(.*\)/\1/"` ;;
    --cgipath=*)   CGIDIR=`echo "$1" | sed -e "s/--cgipath=\(.*\)/\1/"` ;;
    --examdir=*)   EXAMDIR=`echo "$1" | sed -e "s/--examdir=\(.*\)/\1/"` ;;
    --variant=*)   VARIANT=-`echo "$1" | sed -e "s/--variant=\(.*\)/\1/"` ;;
    --arch=*)      ARCH=`echo "$1" | sed -e "s/--arch=\(.*\)/\1/"` ;;
    --sys=*)       SYS=`echo "$1" | sed -e "s/--sys=\(.*\)/\1/"` ;;
    -*) error "unknown parameter $1" ;;
    *) ;; # ignore for now
  esac
  shift
done

test -z "$COMPILER" && getcompiler

test "$COMPILER" = "xarm" && ARCH=arm
test "$COMPILER" = "xw32" && { SYS=w32; NEEDPTHREAD="no"; }
test "$COMPILER" = "xw64" && { SYS=w64; NEEDPTHREAD="no"; }

# disable exam-mode on some systems
case $SYS in
  w32|w64|mingw*|MINGW*) EXAMDIR="" ;;
esac

# check for needed tools
case $COMPILER in
  grx) echo "checking for binobj... "
       which binobj || error "binobj not found - should come with gpc" ;;
esac

VERSION=$MAINVERSION.$SUBVERSION.$REVISION
SVERSION=$MAINVERSION$SUBVERSION$REVISION

#if [ ! -r $SRCDIR/srcbin/uakfquiz.pas ]
#then
#  error cannot find sources in srcdir "$SRCDIR"
#fi

# show settings:
cat << EOF
prefix:   $PREFIX
cgidir:   $CGIDIR
examdir:  $EXAMDIR
Name:     $NAME
Variant:  $VARIANT
Version:  $VERSION
SVersion: $SVERSION
Compiler: $COMPILER
Sys:      $SYS
Arch:     $ARCH
BugMail:  $BUGMAIL
NeedPthread: $NEEDPTHREAD
EOF

# change to default directory
cd $(dirname $0)

sed < Makefile.in > Makefile \
    -e "s%^\(srcdir *= *\).*%\1$SRCDIR%" \
    -e "s/ARCH=.*/ARCH=$ARCH/" \
    -e "s/SYS=.*/SYS=$SYS/" \
    -e "s/^\(VERSION *= *\).*/\1$VERSION/" \
    -e "s/^\(VARIANT *= *\).*/\1$VARIANT/"


SOUNDCOMMENTED=""
test "$SOUND" = "no" && SOUNDCOMMENTED="#"
test "$NEEDPTHREAD" = "no" && PTHREADCOMMENTED="#"
sed < srcbin/Makefile.$COMPILER > srcbin/Makefile \
   -e "s/.*\(DEFINES.*SdlSoundForAll\)$/$SOUNDCOMMENTED\1/" \
   -e "s/.*\(DEFINES.*NEEDPTHREAD\)$/$PTHREADCOMMENTED\1/"

sed < srcbin/common.in > srcbin/common.mak \
    -e "s%^\(srcdir *= *\).*%\1$SRCDIR%" \
    -e "s%^\(prefix *= *\).*%\1$PREFIX%" \
    -e "s%^\(cgidir *= *\).*%\1$CGIDIR%" \
    -e "s%^\(examdir *= *\).*%\1$EXAMDIR%" \
    -e "s/^\(SVERSION *= *\).*/\1$SVERSION/"

cat > srcbin/config.inc <<EOF
{ this file was generated automatically using configure
  do not edit this by hand }

const AKFQuizName = '$NAME$VARIANT';
const AKFQuizVersion = '$VERSION';
const BugMail = '$BUGMAIL';
const ExamDir = '$EXAMDIR';

EOF

cat > srcbin/getquiz <<EOF
#!/bin/sh
cp -i $PREFIX/share/akfquiz/html/* .
EOF

if [ -w ../autopackage/default.apspec ]
then
  mv ../autopackage/default.apspec ../autopackage/default.apspec.old
  sed < ../autopackage/default.apspec.old > ../autopackage/default.apspec \
      -e "s/^\(SoftwareVersion: *\).*/\1$VERSION/"
fi

# Windows stuff

cat > srcbin/w32/akfquiz.nsh <<EOF
!define NAME "$NAME$VARIANT"
!define MAINNAME "$NAME"
!define VERSION $VERSION
!define PKGVERSION $PKGVERSION
!define VARIANT "$VARIANT"
EOF

create_rc scrquiz "scrquiz: AKFQuiz in text-mode" "ported from GNU\/Linux"
create_rc mkquiz "mkquiz: make HTML quiz-file for JavaScript" \
          "ported from GNU\/Linux"
create_rc cgiquiz "cgiquiz: CGI program for AKFQuiz" "ported from GNU\/Linux"
create_rc linequiz "linequiz: AKFQuiz line oriented" "ported from GNU\/Linux"
create_rc grquiz "grquiz: AKFQuiz in graphic-mode" "ported from GNU\/Linux"