select builtin gpu plugin on configure
[pcsx_rearmed.git] / configure
1 #!/bin/sh
2 # some elements originated from qemu configure
3 set -e
4
5 TMPC="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.c"
6 TMPO="/tmp/pcsx-conf-${RANDOM}-$$-${RANDOM}.o"
7 trap "rm -f $TMPC $TMPO" EXIT INT QUIT TERM
8 rm -f config.log
9
10 compile_object()
11 {
12   c="$CC $CFLAGS -c $TMPC -o $TMPO $1"
13   echo $c >> config.log
14   $c >> config.log 2>&1
15 }
16
17 check_define()
18 {
19   echo "" > $TMPC
20   $CC -E -dD $CFLAGS $TMPC | grep -q $1 || return 1
21   return 0
22 }
23
24 # setting options to "yes" or "no" will make that choice default,
25 # "" means "autodetect".
26
27 platform_list="generic pandora maemo caanoo libretro"
28 platform="generic"
29 builtin_gpu_list="peops unai neon"
30 builtin_gpu=""
31 sound_driver_list="oss alsa libretro none"
32 sound_driver="alsa"
33 plugins="plugins/spunull/spunull.so \
34 plugins/dfxvideo/gpu_peops.so plugins/gpu_unai/gpu_unai.so"
35 ram_fixed="no"
36 drc_cache_base="no"
37 have_armv6=""
38 have_armv7=""
39 have_arm_neon=""
40 have_tslib=""
41 enable_dynarec="yes"
42 # these are for known platforms
43 optimize_cortexa8="no"
44 optimize_arm926ej="no"
45
46 # hardcoded stuff
47 CC="${CC-${CROSS_COMPILE}gcc}"
48 CXX="${CXX-${CROSS_COMPILE}g++}"
49 AS="${AS-${CROSS_COMPILE}as}"
50 AR="${AS-${CROSS_COMPILE}ar}"
51 config_mak="config.mak"
52
53 # call during arg parsing, so that cmd line can override platform defaults
54 set_platform()
55 {
56   platform=$1
57   case "$platform" in
58   generic)
59     ;;
60   pandora)
61     sound_driver="oss"
62     ram_fixed="yes"
63     drc_cache_base="yes"
64     optimize_cortexa8="yes"
65     have_arm_neon="yes"
66     ;;
67   maemo)
68     ram_fixed="yes"
69     drc_cache_base="yes"
70     optimize_cortexa8="yes"
71     have_arm_neon="yes"
72     ;;
73   caanoo)
74     sound_driver="oss"
75     ram_fixed="yes"
76     drc_cache_base="yes"
77     optimize_arm926ej="yes"
78     ;;
79   libretro)
80     sound_driver="libretro"
81     ;;
82   *)
83     echo "unsupported platform: $platform"
84     exit 1
85     ;;
86   esac
87 }
88
89 for opt do
90   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
91   case "$opt" in
92   --help|-h) show_help="yes"
93   ;;
94   --platform=*) set_platform "$optarg"
95   ;;
96   --gpu=*) builtin_gpu="$optarg"
97   ;;
98   --sound-driver=*) sound_driver="$optarg"
99   ;;
100   --enable-neon) have_arm_neon="yes"
101   ;;
102   --disable-neon) have_arm_neon="no"
103   ;;
104   --disable-dynarec) enable_dynarec="no"
105   ;;
106   *) echo "ERROR: unknown option $opt"; show_help="yes"
107   ;;
108   esac
109 done
110
111 if [ "$show_help" = "yes" ]; then
112   echo "options:"
113   echo "  --help                   print this message"
114   echo "  --platform=NAME          target platform [$platform]"
115   echo "                           available: $platform_list"
116   echo "  --gpu=NAME               builtin gpu plugin [guessed]"
117   echo "                           available: $builtin_gpu_list"
118   echo "  --sound-driver=NAME      sound output driver [$sound_driver]"
119   echo "                           available: $sound_driver_list"
120   echo "  --enable-neon"
121   echo "  --disable-neon           enable/disable ARM NEON optimizations [guessed]"
122   echo "  --disable-dynarec        disable dynamic recompiler"
123   echo "                           (dynarec is only available and enabled on ARM)"
124   echo "influential environment variables:"
125   echo "  CROSS_COMPILE CC CXX AS AR CFLAGS ASFLAGS LDFLAGS LDLIBS"
126   exit 1
127 fi
128
129 if [ "x$builtin_gpu" != "x" ]; then
130   case "$builtin_gpu" in
131   peops|unai|neon)
132     ;;
133   *)
134     echo "unsupported builtin gpu plugin: $builtin_gpu"
135     exit 1
136     ;;
137   esac
138 fi
139
140 case "$sound_driver" in
141 oss|alsa|libretro|none)
142   ;;
143 *)
144   echo "unsupported sound driver: $sound_driver"
145   exit 1
146   ;;
147 esac
148
149 if [ -z "$ARCH" ]; then
150   ARCH=`$CC -v 2>&1 | grep -i 'target:' | awk '{print $2}' \
151         | awk -F '-' '{print $1}'`
152 fi
153
154 # ARM stuff
155 if [ "$ARCH" = "arm" ]; then
156   if [ "$optimize_cortexa8" = "yes" ]; then
157   # both: -mfpu=neon
158     CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
159     ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
160   fi
161   if [ "$optimize_arm926ej" = "yes" ]; then
162     CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
163     ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
164   fi
165
166   if [ "x$have_arm_neon" = "x" ]; then
167     # detect NEON from user-supplied cflags to enable asm code
168     have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
169   fi
170   if [ "x$have_armv6" = "x" ]; then
171     have_armv6=`check_define __ARM_ARCH_6 && echo yes` || true
172   fi
173   if [ "x$have_armv7" = "x" ]; then
174     if check_define __ARM_ARCH_7A__; then
175       have_armv6="yes"
176       have_armv7="yes"
177     fi
178   fi
179
180   if [ "x$builtin_gpu" = "x" ]; then
181     if [ "$have_arm_neon" = "yes" ]; then
182       builtin_gpu="neon"
183     elif [ "$have_armv7" != "yes" ]; then
184       # pre-ARMv7 hardware is usually not fast enough for peops
185       builtin_gpu="unai"
186     else
187       builtin_gpu="peops"
188     fi
189   fi
190
191   # set mfpu and mfloat-abi if they are not set
192   if [ "$have_arm_neon" = "yes" ]; then
193     echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=neon"
194     echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=neon"
195   elif [ "$have_armv6" = "yes" ]; then
196     echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=vfp"
197     echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=vfp"
198   fi
199   if [ "$have_armv6" = "yes" ]; then
200     echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
201     echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
202   fi
203
204   # must disable -mthumb as recompiler can't handle it
205   if check_define __thumb__; then
206     CFLAGS="$CFLAGS -mno-thumb"
207   fi
208
209   if [ "$have_armv7" = "yes" ]; then
210     ASFLAGS="$ASFLAGS --defsym HAVE_ARMV7=1"
211   else
212     ASFLAGS="$ASFLAGS --defsym HAVE_ARMV7=0"
213   fi
214 else
215   # dynarec only available on ARM
216   enable_dynarec="no"
217 fi
218
219 if [ "x$builtin_gpu" = "x" ]; then
220   builtin_gpu="peops"
221 fi
222
223 if [ "$ARCH" = "x86_64" ]; then
224   # currently we are full of 32bit assumptions,
225   # at least savestate compatibility will break without these
226   CFLAGS="$CFLAGS -m32"
227   LDFLAGS="$LDFLAGS -m32"
228 fi
229
230 # supposedly we can avoid -fPIC on armv5 for slightly better performace?
231 if [ "$ARCH" != "arm" -o "$have_armv6" = "yes" ]; then
232   PLUGIN_CFLAGS="$PLUGIN_CFLAGS -fPIC"
233 fi
234
235 if [ "$ram_fixed" = "yes" ]; then
236   CFLAGS="$CFLAGS -DRAM_FIXED"
237 fi
238
239 case "$platform" in
240 generic)
241   generic_cflags=`sdl-config --cflags`
242   generic_ldlibs=`sdl-config --libs`
243   CFLAGS="$CFLAGS $generic_cflags"
244   LDFLAGS="$LDFLAGS $generic_ldlibs"
245   ;;
246 maemo)
247   maemo_cflags=`pkg-config --cflags hildon-1`
248   maemo_ldlibs=`pkg-config --libs hildon-1`
249   CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES $maemo_cflags"
250   LDFLAGS="$LDFLAGS $maemo_ldlibs"
251   ;;
252 libretro)
253   CFLAGS="$CFLAGS -fPIC"
254   LDFLAGS="$LDFLAGS -shared"
255   ;;
256 esac
257
258 # check for tslib (only headers needed)
259 if [ "x$have_tslib" = "x" ]; then
260   cat > $TMPC <<EOF
261   #include <tslib.h>
262   void test(struct ts_sample sample) {}
263 EOF
264   if compile_object; then
265     have_tslib="yes"
266   else
267     have_tslib="no"
268   fi
269 fi
270
271 # check for GLES headers
272 cat > $TMPC <<EOF
273 #include <GLES/gl.h>
274 #include <GLES/glext.h>
275 #include <EGL/egl.h>
276 void *test(void) {
277   return eglGetDisplay( (EGLNativeDisplayType)0 );
278 }
279 EOF
280 if compile_object; then
281   plugins="$plugins plugins/gpu-gles/gpu_gles.so"
282 fi
283
284 if [ "$have_arm_neon" = "yes" -a "$builtin_gpu" != "neon" ]; then
285   plugins="$plugins plugins/gpu_neon/gpu_neon.so"
286 fi
287
288 # short plugin list for display
289 for p in $plugins; do
290   p1=`basename $p`
291   plugins_short="$p1 $plugins_short"
292 done
293
294 # set things that failed to autodetect to "no"
295 test "x$have_armv6" != "x" || have_armv6="no"
296 test "x$have_armv7" != "x" || have_armv7="no"
297 test "x$have_arm_neon" != "x" || have_arm_neon="no"
298
299 echo "architecture        $ARCH"
300 echo "platform            $platform"
301 echo "built-in GPU        $builtin_gpu"
302 echo "sound driver        $sound_driver"
303 echo "plugins             $plugins_short"
304 echo "C compiler          $CC"
305 echo "C compiler flags    $CFLAGS"
306 echo "linker flags        $LDFLAGS"
307 echo "enable dynarec      $enable_dynarec"
308 echo "ARMv7 optimizations $have_armv7"
309 echo "enable ARM NEON     $have_arm_neon"
310 echo "tslib support       $have_tslib"
311
312 echo "# Automatically generated by configure" > $config_mak
313 printf "# Configured with:" >> $config_mak
314 printf " '%s'" "$0" "$@" >> $config_mak
315 echo >> $config_mak
316
317 echo "CC = $CC" >> $config_mak
318 echo "CXX = $CXX" >> $config_mak
319 echo "AS = $AS" >> $config_mak
320 echo "CFLAGS += $CFLAGS" >> $config_mak
321 echo "ASFLAGS += $ASFLAGS" >> $config_mak
322 echo "LDFLAGS += $LDFLAGS" >> $config_mak
323 echo "LDLIBS += $LDLIBS" >> $config_mak
324 echo "PLUGIN_CFLAGS += $PLUGIN_CFLAGS" >> $config_mak
325 echo >> $config_mak
326
327 if [ "$platform" = "libretro" ]; then
328   echo "TARGET = libretro.so" >> $config_mak
329 fi
330 echo "ARCH = $ARCH" >> $config_mak
331 echo "PLATFORM = $platform" >> $config_mak
332 echo "BUILTIN_GPU = $builtin_gpu" >> $config_mak
333 echo "SOUND_DRIVER = $sound_driver" >> $config_mak
334 if [ "$ARCH" = "arm" ]; then
335   echo "PLUGINS = $plugins" >> $config_mak
336 else
337   echo -n "PLUGINS =" >> $config_mak
338   for p in $plugins; do
339     echo -n " ${p}.${ARCH}" >> $config_mak
340   done
341   echo >> $config_mak
342 fi
343 if [ "$have_armv6" = "yes" ]; then
344   echo "HAVE_ARMV6 = 1" >> $config_mak
345 fi
346 if [ "$have_armv7" = "yes" ]; then
347   echo "HAVE_ARMV7 = 1" >> $config_mak
348 fi
349 if [ "$have_arm_neon" = "yes" ]; then
350   echo "HAVE_NEON = 1" >> $config_mak
351 fi
352 if [ "$have_tslib" = "yes" ]; then
353   echo "HAVE_TSLIB = 1" >> $config_mak
354 fi
355 if [ "$enable_dynarec" = "yes" ]; then
356   echo "USE_DYNAREC = 1" >> $config_mak
357 fi
358 if [ "$drc_cache_base" = "yes" ]; then
359   echo "DRC_CACHE_BASE = 1" >> $config_mak
360 fi
361
362 # use pandora's skin (for now)
363 test -e skin || ln -s frontend/pandora/skin skin
364
365 # vim:shiftwidth=2:expandtab