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