由于想把ffmpeg和SDL移植到android上,先尝试用NDK编译SDL。参考网上一些移植文章,总结如下:
步骤:
1. 下载NDK到ubuntu,我是将NDK解压到/usr/dev/目录下
2. 到www.libsdl.org下载最新的sdl源码,解压到指定的目录
3. 修改后的Makefile.minimal:
PREBUILD = /usr/dev/android-ndk-r6/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/binPLATFROM = /usr/dev/android-ndk-r6/platforms/android-9/arch-arm
INCLUDE = -I./include -I$(PLATFROM)/usr/include
CFLAGS = -g -O2 $(INCLUDE)
# AR = ar
# RANLIB = ranlib
CC = $(PREBUILD)/arm-linux-androideabi-gcc
AR = $(PREBUILD)/arm-linux-androideabi-ar
RANLIB = $(PREBUILD)/arm-linux-androideabi-ranlib
CONFIG_H = include/SDL_config.h
TARGET = libSDL.a
SOURCES = \
src/*.c \
src/audio/*.c \
src/cdrom/*.c \
src/cpuinfo/*.c \
src/events/*.c \
src/file/*.c \
src/joystick/*.c \
src/stdlib/*.c \
src/thread/*.c \
src/timer/*.c \
src/video/*.c \
src/audio/dsp/*.c \
src/audio/dma/*.c \
src/video/fbcon/*.c \
src/joystick/dummy/*.c \
src/cdrom/dummy/*.c \
src/thread/pthread/*.c \
src/timer/unix/*.c \
src/loadso/dlopen/*.c \
OBJECTS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g')
all: $(TARGET)
$(TARGET): $(CONFIG_H) $(OBJECTS)
$(AR) crv $@ $^
$(RANLIB) $@
$(CONFIG_H):
cp $(CONFIG_H).default $(CONFIG_H)
clean:
rm -f $(TARGET) $(OBJECTS)
4. 修改后的./include/SDL_config_minimal.h
#ifndef _SDL_config_minimal_h
#define _SDL_config_minimal_h
#include "SDL_platform.h"
/* This is the minimal configuration that can be used to build SDL */
#include <stdarg.h>
/*
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef unsigned int size_t;
typedef unsigned long uintptr_t;
*/
#define HAVE_LIBC 1
#ifdef HAVE_LIBC
#define HAVE_ALLOCA_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_STDIO_H 1
#define STDC_HEADERS 1
#define HAVE_STDLIB_H 1
#define HAVE_STDARG_H 1
#define HAVE_MALLOC_H 1
#define HAVE_MEMORY_H 1
//#define HAVE_STRING_H 1
//#define HAVE_STRINGS_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_CTYPE_H 1
#define HAVE_MATH_H 1
//#define HAVE_ICONV_H 1
#define HAVE_SIGNAL_H 1
#define HAVE_ALTIVEC_H 1
#define HAVE_MALLOC 1
#define HAVE_CALLOC 1
#define HAVE_REALLOC 1
#define HAVE_FREE 1
#define HAVE_ALLOCA 1
#define HAVE_GETENV 1
#define HAVE_PUTENV 1
#define HAVE_UNSETENV 1
#define HAVE_QSORT 1
#define HAVE_ABS 1
//#define HAVE_BCOPY 1
//#define HAVE_MEMSET 1
//#define HAVE_MEMCPY 1
//#define HAVE_MEMMOVE 1
//#define HAVE_MEMCMP 1
//#define HAVE_STRLEN 1
//#define HAVE_STRLCPY 1
//#define HAVE_STRLCAT 1
//#define HAVE_STRDUP 1
#define HAVE__STRREV 1
#define HAVE__STRUPR 1
#define HAVE__STRLWR 1
//#define HAVE_INDEX 1
#define HAVE_RINDEX 1
//#define HAVE_STRCHR 1
#define HAVE_STRRCHR 1
#define HAVE_STRSTR 1
#define HAVE_ITOA 1
#define HAVE__LTOA 1
#define HAVE__UITOA 1
#define HAVE__ULTOA 1
#define HAVE_STRTOL 1
#define HAVE_STRTOUL 1
#define HAVE__I64TOA 1
#define HAVE__UI64TOA 1
#define HAVE_STRTOLL 1
#define HAVE_STRTOULL 1
#define HAVE_STRTOD 1
#define HAVE_ATOI 1
#define HAVE_ATOF 1
#define HAVE_STRCMP 1
#define HAVE_STRNCMP 1
#define HAVE__STRICMP 1
#define HAVE_STRCASECMP 1
#define HAVE__STRNICMP 1
#define HAVE_STRNCASECMP 1
#define HAVE_SSCANF 1
#define HAVE_SNPRINTF 1
#define HAVE_VSNPRINTF 1
//#define HAVE_ICONV
#define HAVE_SIGACTION 1
#define HAVE_SETJMP 1
#define HAVE_NANOSLEEP 1
//#define HAVE_CLOCK_GETTIME 1
#define HAVE_DLVSYM 1
#define HAVE_GETPAGESIZE 1
#define HAVE_MPROTECT 1
#else
#include <stdarg.h>
#endif
/* Enable the dummy audio driver (src/audio/dummy/\*.c) */
//#define SDL_AUDIO_DRIVER_DUMMY 1
#define SDL_AUDIO_DRIVER_OSS 1
/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
#define SDL_CDROM_DISABLED 1
/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
#define SDL_JOYSTICK_DISABLED 1
/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
//#define SDL_LOADSO_DISABLED 1
#define SDL_LOADSO_DLOPEN 1
/* Enable the stub thread support (src/thread/generic/\*.c) */
//#define SDL_THREADS_DISABLED 1
#define SDL_THREAD_PTHREAD 1
/* Enable the stub timer support (src/timer/dummy/\*.c) */
//#define SDL_TIMERS_DISABLED 1
#define SDL_TIMER_UNIX 1
/* Enable the dummy video driver (src/video/dummy/\*.c) */
//#define SDL_VIDEO_DRIVER_DUMMY 1
#define SDL_VIDEO_DRIVER_FBCON 1
#endif /* _SDL_config_minimal_h */
5. 因为AndroidLinux的framebuffer设备文件与标准Linux不同,Linux的fb设备文件一般是/dev/fb0,但Android的设备文件是 /dev/graphics/fb0,打开$SDL/src/video/fbcon/SDL_fbvideo.c,将203、512行的"/dev/fb0" 替换成"/dev/graphics/fb0",保存。
6. 修改 $SDL/src/thread/pthread/SDL_sysmutex.c,将第30行改成: #defineFAKE_RECURSIVE_MUTEX1,就是在后面加一个“1”子,这可能是编译器的一个bug,define默认应该就是“1”的
7. make -f Makefile.minimal,这是会报错,找不到soundcard.h。
将/usr/include/linux/soundcard.h拷贝到/usr/dev/android-ndk-r6/platforms/android-9/arch-arm/usr/include/sys目录下。
再次运行make -f Makefile.minimal,编译完成即可在根目录下找到libSDL.a