Merge pull request #90 from gizmo98/patch-2
[libretro-ppsspp.git] / libretro / Makefile
blob4aea15a2ccaafe3f2dbcb33637ed4f205399b20b
1 DEBUG=0
2 PERF_TEST=0
3 HAVE_SHARED_CONTEXT=0
4 SINGLE_THREAD=0
6 DYNAFLAGS :=
7 INCFLAGS := -I.
8 COREFLAGS :=
9 CPUFLAGS :=
11 UNAME=$(shell uname -a)
13 # Cross compile ?
15 ifeq (,$(ARCH))
16 ARCH = $(shell uname -m)
17 endif
19 # Target Dynarec
20 WITH_DYNAREC = $(ARCH)
21 FFMPEG_ARCH = $(ARCH)
23 ifeq ($(ARCH), $(filter $(ARCH), i386 i686))
24 WITH_DYNAREC = x86
25 FFMPEG_ARCH = x86
26 endif
28 ifeq ($(platform),)
29 platform = unix
30 ifeq ($(UNAME),)
31 platform = win
32 else ifneq ($(findstring MINGW,$(UNAME)),)
33 platform = win
34 else ifneq ($(findstring Darwin,$(UNAME)),)
35 platform = osx
36 else ifneq ($(findstring win,$(UNAME)),)
37 platform = win
38 endif
39 endif
42 # Dirs
43 CORE_DIR = ..
44 FFMPEGDIR = $(CORE_DIR)/ffmpeg
45 LIBRETRODIR = $(CORE_DIR)/libretro
46 COREDIR = $(CORE_DIR)/Core
47 COMMONDIR = $(CORE_DIR)/Common
48 GPUCOMMONDIR = $(CORE_DIR)/GPU/Common
49 GPUDIR = $(CORE_DIR)/GPU
50 NATIVEDIR = $(CORE_DIR)/native
51 EXTDIR = $(CORE_DIR)/ext
53 TARGET_NAME := ppsspp
54 GIT_VERSION := " $(shell git rev-parse --short HEAD || echo unknown)"
55 ifneq ($(GIT_VERSION)," unknown")
56 CXXFLAGS += -DGIT_VERSION=\"$(GIT_VERSION)\"
57 endif
58 CC_AS ?= $(CC)
59 FFMPEGINCFLAGS :=
60 FFMPEGLIBDIR :=
61 FFMPEGLIBS :=
63 # Unix
64 ifneq (,$(findstring unix,$(platform)))
65 TARGET := $(TARGET_NAME)_libretro.so
66 LDFLAGS += -shared -Wl,--version-script=link.T -Wl,--no-undefined
68 FFMPEGINCFLAGS += -I$(FFMPEGDIR)/linux/$(FFMPEG_ARCH)/include
69 FFMPEGLIBDIR := $(FFMPEGDIR)/linux/$(FFMPEG_ARCH)/lib
70 FFMPEGLDFLAGS += -L$(FFMPEGLIBDIR) -lavformat -lavcodec -lavutil -lswresample -lswscale
71 fpic = -fPIC
72 ifneq (,$(findstring gles,$(platform)))
73 GLES = 1
74 GL_LIB := -lGLESv2
75 else
76 GL_LIB := -lGL
77 endif
78 PLATFORM_EXT := unix
79 LDFLAGS += -lrt -ldl
81 # Raspberry Pi
82 else ifneq (,$(findstring rpi,$(platform)))
83 TARGET := $(TARGET_NAME)_libretro.so
84 LDFLAGS += -shared -Wl,--version-script=link.T
85 fpic = -fPIC
86 GLES = 1
88 ifneq (,$(findstring mesa,$(platform)))
89 GL_LIB := -lGLESv2
90 else
91 GL_LIB := -L/opt/vc/lib -lGLESv2
92 INCFLAGS += -I/opt/vc/include -I/opt/vc/include/interface/vcos -I/opt/vc/include/interface/vcos/pthreads
93 endif
95 ifneq (,$(findstring rpi2,$(platform)))
96 CPUFLAGS += -mcpu=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard
97 HAVE_NEON = 1
98 FFMPEGINCFLAGS += -I$(FFMPEGDIR)/linux/armv7/include
99 FFMPEGLIBDIR := $(FFMPEGDIR)/linux/armv7/lib
100 else ifneq (,$(findstring rpi3,$(platform)))
101 CPUFLAGS += -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -mfloat-abi=hard
102 HAVE_NEON = 1
103 FFMPEGINCFLAGS += -I$(FFMPEGDIR)/linux/armv7/include
104 FFMPEGLIBDIR := $(FFMPEGDIR)/linux/armv7/lib
105 else
106 FFMPEGINCFLAGS += -I$(FFMPEGDIR)/linux/arm/include
107 FFMPEGLIBDIR := $(FFMPEGDIR)/linux/arm/lib
108 CPUFLAGS += -DARMv5_ONLY
109 endif
111 FFMPEGLDFLAGS += -L$(FFMPEGLIBDIR) -lavformat -lavcodec -lavutil -lswresample -lswscale
113 PLATFORM_EXT := unix
114 WITH_DYNAREC=arm
115 LDFLAGS += -lrt -ldl
117 # i.MX6
118 else ifneq (,$(findstring imx6,$(platform)))
119 TARGET := $(TARGET_NAME)_libretro.so
120 LDFLAGS += -shared -Wl,--version-script=link.T
121 fpic = -fPIC
122 GLES = 1
123 GL_LIB := -lGLESv2
124 CPUFLAGS +=
125 PLATFORM_EXT := unix
126 WITH_DYNAREC=arm
127 HAVE_NEON=1
128 FFMPEGINCFLAGS += -I$(FFMPEGDIR)/linux/armv7/include
129 FFMPEGLIBDIR := $(FFMPEGDIR)/linux/armv7/lib
130 FFMPEGLDFLAGS += -L$(FFMPEGLIBDIR) -lavformat -lavcodec -lavutil -lswresample -lswscale
131 LDFLAGS += -lrt -ldl
133 # OS X
134 else ifneq (,$(findstring osx,$(platform)))
135 TARGET := $(TARGET_NAME)_libretro.dylib
136 LDFLAGS += -dynamiclib
137 OSXVER = `sw_vers -productVersion | cut -d. -f 2`
138 OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9 )) && echo "YES"`
139 ifeq ($(OSX_LT_MAVERICKS),"YES")
140 LDFLAGS += -mmacosx-version-min=10.5
141 endif
142 LDFLAGS += -stdlib=libc++
143 fpic = -fPIC
145 FFMPEGINCFLAGS += -I$(FFMPEGDIR)/macosx/$(FFMPEG_ARCH)/include
146 FFMPEGLIBDIR := $(FFMPEGDIR)/macosx/$(FFMPEG_ARCH)/lib
147 FFMPEGLDFLAGS += -liconv -L$(FFMPEGLIBDIR) -lavformat -lavcodec -lavutil -lswresample -lswscale
148 PLATCFLAGS += -D__MACOSX__
149 GL_LIB := -framework OpenGL
150 PLATFORM_EXT := unix
152 # iOS
153 else ifneq (,$(findstring ios,$(platform)))
154 TARGET := $(TARGET_NAME)_libretro_ios.dylib
155 PLATCFLAGS += -DIOS
156 LDFLAGS += -dynamiclib -marm
157 fpic = -fPIC
158 GLES = 1
159 GL_LIB := -framework OpenGLES
160 HAVE_NEON = 1
162 FFMPEGINCFLAGS += -I$(FFMPEGDIR)/ios/universal/include
163 FFMPEGLIBDIR := $(FFMPEGDIR)/ios/universal/lib
164 FFMPEGLDFLAGS += -L$(FFMPEGLIBDIR) -lavformat -lavcodec -lavutil -lswresample -lswscale
166 ifeq ($(IOSSDK),)
167 IOSSDK := $(shell xcodebuild -version -sdk iphoneos Path)
168 endif
170 CC = clang -arch armv7 -isysroot $(IOSSDK)
171 CC_AS = $(CC)
172 CXX = clang++ -arch armv7 -isysroot $(IOSSDK)
173 OSXVER = `sw_vers -productVersion | cut -c 4`
174 ifneq ($(OSXVER),9)
175 CC += -miphoneos-version-min=5.0
176 CC_AS += -miphoneos-version-min=5.0
177 CXX += -miphoneos-version-min=5.0
178 PLATCFLAGS += -miphoneos-version-min=5.0
179 endif
180 PLATCFLAGS += -DIOS -DHAVE_POSIX_MEMALIGN
181 CPUFLAGS += -DARMv5_ONLY -DARM
182 PLATFORM_EXT := unix
183 WITH_DYNAREC=arm
185 # Android
186 else ifneq (,$(findstring android,$(platform)))
187 fpic = -fPIC
188 TARGET := $(TARGET_NAME)_libretro_android.so
189 LDFLAGS += -shared -Wl,--version-script=link.T -Wl,--no-undefined -Wl,--warn-common
190 GL_LIB := -lGLESv2
192 CC = arm-linux-androideabi-gcc
193 CXX = arm-linux-androideabi-g++
194 WITH_DYNAREC=arm
195 GLES = 1
196 PLATCFLAGS += -DANDROID
197 CPUCFLAGS +=
198 HAVE_NEON = 1
199 CPUFLAGS += -marm -mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp -D__arm__ -DARM_ASM -D__NEON_OPT
200 CFLAGS += -DANDROID
201 LDFLAGS += -llog -lGLESv2 -lEGL
203 FFMPEGINCFLAGS += -I$(FFMPEGDIR)/android/armv7/include
204 FFMPEGLIBDIR := $(FFMPEGDIR)/android/armv7/lib
205 FFMPEGLDFLAGS += -L$(FFMPEGLIBDIR) -lavformat -lavcodec -lavutil -lswresample -lswscale
207 PLATFORM_EXT := unix
209 # QNX
210 else ifeq ($(platform), qnx)
211 fpic = -fPIC
212 TARGET := $(TARGET_NAME)_libretro_qnx.so
213 LDFLAGS += -shared -Wl,--version-script=link.T -Wl,--no-undefined -Wl,--warn-common
214 GL_LIB := -lGLESv2
216 CC = qcc -Vgcc_ntoarmv7le
217 CC_AS = qcc -Vgcc_ntoarmv7le
218 CXX = QCC -Vgcc_ntoarmv7le
219 AR = QCC -Vgcc_ntoarmv7le
220 WITH_DYNAREC=arm
221 GLES = 1
222 PLATCFLAGS += -D__BLACKBERRY_QNX__
223 HAVE_NEON = 1
224 CPUFLAGS += -marm -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=softfp -D__arm__ -DARM_ASM -D__NEON_OPT
225 CFLAGS += -D__QNX__
227 PLATFORM_EXT := unix
229 # ARM
230 else ifneq (,$(findstring armv,$(platform)))
231 CC = gcc
232 CXX = g++
233 TARGET := $(TARGET_NAME)_libretro.so
234 fpic := -fPIC
235 LDFLAGS += -shared -Wl,--version-script=link.T -Wl,--no-undefined
236 FFMPEGINCFLAGS += -I$(FFMPEGDIR)/linux/$(FFMPEG_ARCH)/include
237 FFMPEGLIBDIR := $(FFMPEGDIR)/linux/$(FFMPEG_ARCH)/lib
238 FFMPEGLDFLAGS += -L$(FFMPEGLIBDIR) -lavformat -lavcodec -lavutil -lswresample -lswscale
239 INCFLAGS += -I.
240 WITH_DYNAREC=arm
241 ifneq (,$(findstring gles,$(platform)))
242 GLES := 1
243 GL_LIB := -lGLESv2 -lEGL
244 LDFLAGS += -lGLESv2 -lEGL
245 else
246 GL_LIB := -lGL
247 endif
248 ifneq (,$(findstring cortexa8,$(platform)))
249 CPUFLAGS += -marm -mcpu=cortex-a8
250 else ifneq (,$(findstring cortexa9,$(platform)))
251 CPUFLAGS += -marm -mcpu=cortex-a9
252 endif
253 CPUFLAGS += -marm
254 ifneq (,$(findstring neon,$(platform)))
255 CPUFLAGS += -mfpu=neon -D__NEON_OPT
256 HAVE_NEON = 1
257 endif
258 ifneq (,$(findstring softfloat,$(platform)))
259 CPUFLAGS += -mfloat-abi=softfp
260 else ifneq (,$(findstring hardfloat,$(platform)))
261 CPUFLAGS += -mfloat-abi=hard
262 endif
263 CPUFLAGS += -D__arm__ -DARM_ASM
264 PLATCFLAGS += -DARM
265 LDFLAGS += -lrt -ldl
267 # emscripten
268 else ifeq ($(platform), emscripten)
269 TARGET := $(TARGET_NAME)_libretro_emscripten.bc
270 GLES := 1
271 CPUFLAGS +=
272 PLATCFLAGS += -DCC_resampler=mupen_CC_resampler -Dsinc_resampler=mupen_sinc_resampler \
273 -Drglgen_symbol_map=mupen_rglgen_symbol_map -Dmain_exit=mupen_main_exit \
274 -Dadler32=mupen_adler32 -Drarch_resampler_realloc=mupen_rarch_resampler_realloc \
275 -Daudio_convert_s16_to_float_C=mupen_audio_convert_s16_to_float_C -Daudio_convert_float_to_s16_C=mupen_audio_convert_float_to_s16_C \
276 -Daudio_convert_init_simd=mupen_audio_convert_init_simd -Drglgen_resolve_symbols_custom=mupen_rglgen_resolve_symbols_custom \
277 -Drglgen_resolve_symbols=mupen_rglgen_resolve_symbols
278 PLATFORM_EXT := unix
279 #HAVE_SHARED_CONTEXT := 1
281 # Windows
282 else ifneq (,$(findstring win,$(platform)))
283 TARGET := $(TARGET_NAME)_libretro.dll
284 LDFLAGS += -shared -static-libgcc -static-libstdc++ -Wl,--version-script=link.T -lwinmm -lgdi32 -lwsock32 -lws2_32
285 GL_LIB := -lopengl32
286 PLATFORM_EXT := win32
287 CC = gcc
288 CXX = g++
289 endif
291 include Makefile.common
293 ifeq ($(PERF_TEST), 1)
294 COREFLAGS += -DPERF_TEST
295 endif
297 ifeq ($(HAVE_SHARED_CONTEXT), 1)
298 COREFLAGS += -DHAVE_SHARED_CONTEXT
299 endif
301 ifeq ($(SINGLE_THREAD), 1)
302 COREFLAGS += -DSINGLE_THREAD
303 endif
305 ifeq ($(GLES), 1)
306 GLFLAGS += -DGLES -DUSING_GLES2
307 else
308 GLFLAGS += -DHAVE_OPENGL
309 endif
311 COREFLAGS += -D__LIBRETRO__ -DINLINE="inline" -DPPSSPP -DUSE_FFMPEG -DBAKE_IN_GIT -DPROFILE_THIS_SCOPE\(x\)
313 ifeq ($(DEBUG), 1)
314 CPUOPTS += -O0 -g
315 CPUOPTS += -DOPENGL_DEBUG
316 else
317 CPUOPTS += -O3 -DNDEBUG
318 endif
320 ### Finalize ###
321 OBJECTS += $(SOURCES_CXX:.cpp=.o) $(SOURCES_C:.c=.o) $(ASMFILES:.S=.o)
322 CXXFLAGS += -std=c++11 $(CPUOPTS) $(COREFLAGS) $(INCFLAGS) $(PLATCFLAGS) $(fpic) $(PLATCFLAGS) $(CPUFLAGS) $(GLFLAGS) $(DYNAFLAGS)
323 CFLAGS += $(CPUOPTS) $(COREFLAGS) $(INCFLAGS) $(PLATCFLAGS) $(fpic) $(PLATCFLAGS) $(CPUFLAGS) $(GLFLAGS) $(DYNAFLAGS)
325 LDFLAGS += -lm -lz -lavcodec -lavformat -lswresample -lavutil -lswscale $(FFMPEGLDFLAGS) $(fpic)
326 ifeq (,$(findstring android,$(platform)))
327 LDFLAGS += -lpthread
328 endif
330 all: $(TARGET)
332 %.o: %.S
333 $(CC_AS) $(CFLAGS) -c $^ -o $@
335 %.o: %.c
336 $(CC) $(CFLAGS) -c $^ -o $@
338 %.o: %.cpp
339 $(CXX) $(CXXFLAGS) -c $^ -o $@
341 $(TARGET): $(OBJECTS)
342 $(CXX) -o $@ $(OBJECTS) $(LDFLAGS) $(GL_LIB)
344 clean:
345 rm -f $(OBJECTS) $(TARGET)
347 .PHONY: clean