1
0
Fork 0

MingGW compilation support

This commit is contained in:
ec- 2017-05-25 17:47:54 +03:00
parent 8334384637
commit a510e7c7d8
12 changed files with 225 additions and 140 deletions

138
Makefile
View File

@ -124,6 +124,14 @@ ifndef USE_CURL
USE_CURL=1
endif
ifndef USE_CURL_DLOPEN
ifdef MINGW
USE_CURL_DLOPEN=0
else
USE_CURL_DLOPEN=1
endif
endif
ifndef USE_ALSA_STATIC
USE_ALSA_STATIC=0
endif
@ -132,7 +140,6 @@ ifndef USE_STATIC_GL
USE_STATIC_GL=0
endif
#############################################################################
BD=$(BUILD_DIR)/debug-$(PLATFORM)-$(ARCH)
@ -150,6 +157,9 @@ UIDIR=$(MOUNT_DIR)/ui
JPDIR=$(MOUNT_DIR)/jpeg-8c
LOKISETUPDIR=$(UDIR)/setup
bin_path=$(shell which $(1) 2> /dev/null)
STRIP=strip
# extract version info
VERSION=$(shell grep "\#define Q3_VERSION" $(CMDIR)/q_shared.h | \
sed -e 's/.*".* \([^ ]*\)"/\1/')
@ -243,22 +253,71 @@ else # ifeq Linux
# SETUP AND BUILD -- MINGW32
#############################################################################
ifeq ($(PLATFORM),mingw32)
ifdef MINGW
ifeq ($(CROSS_COMPILING),1)
# If CC is already set to something generic, we probably want to use
# something more specific
ifneq ($(findstring $(strip $(CC)),cc gcc),)
CC=
endif
# We need to figure out the correct gcc and windres
ifeq ($(ARCH),x86_64)
MINGW_PREFIXES=x86_64-w64-mingw32 amd64-mingw32msvc
STRIP=x86_64-w64-mingw32-strip
endif
ifeq ($(ARCH),x86)
MINGW_PREFIXES=i686-w64-mingw32 i586-mingw32msvc i686-pc-mingw32
endif
ifndef CC
CC=$(firstword $(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
$(call bin_path, $(MINGW_PREFIX)-gcc))))
endif
# STRIP=$(MINGW_PREFIX)-strip -g
ifndef WINDRES
WINDRES=$(firstword $(strip $(foreach MINGW_PREFIX, $(MINGW_PREFIXES), \
$(call bin_path, $(MINGW_PREFIX)-windres))))
endif
else
# Some MinGW installations define CC to cc, but don't actually provide cc,
# so check that CC points to a real binary and use gcc if it doesn't
ifeq ($(call bin_path, $(CC)),)
CC=gcc
endif
endif
# using generic windres if specific one is not present
ifndef WINDRES
WINDRES=windres
endif
ARCH=x86
BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes
ifeq ($(USE_CODEC_VORBIS),1)
BASE_CFLAGS += -DUSE_CODEC_VORBIS=1
ifeq ($(CC),)
$(error Cannot find a suitable cross compiler for $(PLATFORM))
endif
OPTIMIZE = -O3 -march=i586 -fomit-frame-pointer -ffast-math -falign-loops=2 \
-funroll-loops -falign-jumps=2 -falign-functions=2 -fstrength-reduce
BASE_CFLAGS = -Wall -fno-strict-aliasing -Wimplicit -Wstrict-prototypes \
-DUSE_ICON
# OPTIMIZE = -O3 -march=i586 -fomit-frame-pointer -ffast-math -falign-loops=2 \
# -funroll-loops -falign-jumps=2 -falign-functions=2 -fstrength-reduce
ifeq ($(ARCH),x86_64)
CNAME = quake3e.x64
DNAME = quake3e.ded.x64
BASE_CFLAGS += -m64
OPTIMIZE = -O3 -ffast-math -fstrength-reduce
HAVE_VM_COMPILED = true
endif
ifeq ($(ARCH),x86)
BASE_CFLAGS += -m32
OPTIMIZE = -O2 -march=i586 -mtune=i686 -ffast-math -fstrength-reduce
HAVE_VM_COMPILED = true
endif
DEBUG_CFLAGS=$(BASE_CFLAGS) -g -O0
@ -270,21 +329,25 @@ ifeq ($(PLATFORM),mingw32)
BINEXT=.exe
LDFLAGS= -mwindows -lwsock32 -lgdi32 -lwinmm -lole32
CLIENT_LDFLAGS=
LDFLAGS= -mwindows -Wl,--dynamicbase -Wl,--nxcompat
LDFLAGS += -lwsock32 -lgdi32 -lwinmm -lole32 -lws2_32 -lpsapi -lcomctl32
CLIENT_LDFLAGS=$(LDFLAGS)
ifeq ($(USE_CODEC_VORBIS),1)
CLIENT_LDFLAGS += -lvorbisfile -lvorbis -logg
endif
ifeq ($(ARCH),x86)
# build 32bit
BASE_CFLAGS += -m32
LDFLAGS+=-m32
ifeq ($(USE_CURL),1)
BASE_CFLAGS += -I$(MOUNT_DIR)/libcurl/windows/include
ifeq ($(ARCH),x86)
CLIENT_LDFLAGS += -L$(MOUNT_DIR)/libcurl/windows/mingw/lib32
else
CLIENT_LDFLAGS += -L$(MOUNT_DIR)/libcurl/windows/mingw/lib64
endif
CLIENT_LDFLAGS += -lcurl -lwldap32 -lcrypt32
endif
BUILD_SERVER = 0
else # ifeq mingw32
#############################################################################
@ -444,7 +507,11 @@ endif
ifeq ($(USE_CURL),1)
BASE_CFLAGS += -DUSE_CURL
ifeq ($(USE_CURL_DLOPEN),1)
BASE_CFLAGS += -DUSE_CURL_DLOPEN
else
BASE_CFLAGS += -DCURL_STATICLIB
endif
endif
ifeq ($(USE_ALSA_STATIC),1)
@ -529,6 +596,9 @@ targets: makedirs tools
@echo " ARCH: $(ARCH)"
@echo " COMPILE_PLATFORM: $(COMPILE_PLATFORM)"
@echo " COMPILE_ARCH: $(COMPILE_ARCH)"
ifdef MINGW
@echo " WINDRES: $(WINDRES)"
endif
@echo " CC: $(CC)"
@echo ""
@echo " CFLAGS:"
@ -728,11 +798,12 @@ Q3OBJ = \
$(B)/client/tr_world.o \
ifeq ($(ARCH),x86)
ifndef MINGW
Q3OBJ += \
$(B)/client/linux_asm.o \
$(B)/client/snd_mix_mmx.o \
$(B)/client/snd_mix_sse.o
endif
endif
ifeq ($(HAVE_VM_COMPILED),true)
ifeq ($(ARCH),x86)
@ -747,12 +818,13 @@ ifeq ($(USE_CURL),1)
Q3OBJ += $(B)/client/cl_curl.o
endif
ifeq ($(PLATFORM),mingw32)
ifdef MINGW
Q3OBJ += \
$(B)/client/win_gamma.o \
$(B)/client/win_glimp.o \
$(B)/client/win_input.o \
$(B)/client/win_main.o \
$(B)/client/win_minimize.o \
$(B)/client/win_qgl.o \
$(B)/client/win_shared.o \
$(B)/client/win_snd.o \
@ -780,6 +852,7 @@ $(B)/$(TARGET_CLIENT): $(Q3OBJ) $(Q3POBJ)
$(echo_cmd) "LD $@"
$(Q)$(CC) -o $@ $(Q3OBJ) $(Q3POBJ) $(CLIENT_LDFLAGS) \
$(LDFLAGS)
$(STRIP) $@
#############################################################################
@ -848,15 +921,20 @@ Q3DOBJ = \
$(B)/ded/l_memory.o \
$(B)/ded/l_precomp.o \
$(B)/ded/l_script.o \
$(B)/ded/l_struct.o \
\
$(B)/ded/l_struct.o
ifdef MINGW
Q3DOBJ += \
$(B)/ded/history.o \
$(B)/ded/win_main.o \
$(B)/client/win_resource.o \
$(B)/ded/win_shared.o \
$(B)/ded/win_syscon.o
else
Q3DOBJ += \
$(B)/ded/linux_signals.o \
$(B)/ded/unix_main.o \
$(B)/ded/unix_shared.o
ifeq ($(ARCH),x86)
Q3DOBJ += \
$(B)/ded/linux_asm.o
endif
ifeq ($(HAVE_VM_COMPILED),true)
@ -871,7 +949,7 @@ endif
$(B)/$(TARGET_SERVER): $(Q3DOBJ)
$(echo_cmd) "LD $@"
$(Q)$(CC) -o $@ $(Q3DOBJ) $(LDFLAGS)
$(STRIP) $@
#############################################################################
## CLIENT/SERVER RULES
@ -926,6 +1004,12 @@ $(B)/ded/%.o: $(UDIR)/%.c
$(B)/ded/%.o: $(NDIR)/%.c
$(DO_DED_CC)
$(B)/ded/%.o: $(W32DIR)/%.c
$(DO_DED_CC)
$(B)/ded/%.o: $(W32DIR)/%.rc
$(DO_WINDRES)
#############################################################################
# MISC
#############################################################################

View File

@ -1,40 +0,0 @@
#include "qasm.h"
#ifndef __clang__
#if id386
.arch i586
#endif
#endif
.intel_syntax noprefix
.data
cw037F: .long 0x037F // rounding towards nearest (even)
cw0F7F: .long 0x0F7F // rounding towards zero (chop mode)
cwCurr: .long 0x0000
#if id386
.text
.globl C(Sys_SnapVector)
C(Sys_SnapVector):
fnstcw word ptr cwCurr
mov eax, dword ptr[esp+4]
fldcw word ptr cw037F
fld dword ptr[eax+8]
fistp dword ptr[eax+8]
fild dword ptr[eax+8]
fstp dword ptr[eax+8]
fld dword ptr[eax+4]
fistp dword ptr[eax+4]
fild dword ptr[eax+4]
fstp dword ptr[eax+4]
fld dword ptr[eax+0]
fistp dword ptr[eax+0]
fild dword ptr[eax+0]
fstp dword ptr[eax+0]
fldcw word ptr cwCurr
ret
#endif

View File

@ -50,7 +50,7 @@ void S_WriteLinearBlastStereo16( void )
}
}
#if id386
#if id386 && defined (_MSC_VER)
void S_WriteLinearBlastStereo16_MMX( void );
void S_WriteLinearBlastStereo16_SSE( void );
@ -291,7 +291,7 @@ void S_TransferStereo16( unsigned long *pbuf, int endtime )
snd_linear_count <<= 1;
// write a linear blast of samples
#if id386
#if id386 && defined (_MSC_VER)
if ( CPU_Flags & CPU_SSE )
S_WriteLinearBlastStereo16_SSE();
else

Binary file not shown.

Binary file not shown.

View File

@ -2843,6 +2843,108 @@ int Sys_GetProcessorId( char *vendor )
}
/*
================
Sys_SnapVector
================
*/
#ifdef _MSC_VER
#include <intrin.h>
#if idx64
void Sys_SnapVector( float *vector )
{
__m128 vf0, vf1, vf2;
__m128i vi;
DWORD mxcsr;
mxcsr = _mm_getcsr();
vf0 = _mm_setr_ps( vector[0], vector[1], vector[2], 0.0f );
_mm_setcsr( mxcsr & ~0x6000 ); // enforce rounding mode to "round to nearest"
vi = _mm_cvtps_epi32( vf0 );
vf0 = _mm_cvtepi32_ps( vi );
vf1 = _mm_shuffle_ps(vf0, vf0, _MM_SHUFFLE(1,1,1,1));
vf2 = _mm_shuffle_ps(vf0, vf0, _MM_SHUFFLE(2,2,2,2));
_mm_setcsr( mxcsr ); // restore rounding mode
_mm_store_ss( &vector[0], vf0 );
_mm_store_ss( &vector[1], vf1 );
_mm_store_ss( &vector[2], vf2 );
}
#else // id386
void Sys_SnapVector( float *vector )
{
static const DWORD cw037F = 0x037F;
DWORD cwCurr;
__asm {
fnstcw word ptr [cwCurr]
mov ecx, vector
fldcw word ptr [cw037F]
fld dword ptr[ecx+8]
fistp dword ptr[ecx+8]
fild dword ptr[ecx+8]
fstp dword ptr[ecx+8]
fld dword ptr[ecx+4]
fistp dword ptr[ecx+4]
fild dword ptr[ecx+4]
fstp dword ptr[ecx+4]
fld dword ptr[ecx+0]
fistp dword ptr[ecx+0]
fild dword ptr[ecx+0]
fstp dword ptr[ecx+0]
fldcw word ptr cwCurr
}; // __asm
}
#endif // id386
#else // linux/mingw
#if idx64
void Sys_SnapVector( vec3_t vec )
{
vec[0] = round(vec[0]);
vec[1] = round(vec[1]);
vec[2] = round(vec[2]);
}
#else // id386
#define QROUNDX87(src) \
"flds " src "\n" \
"fistpl " src "\n" \
"fildl " src "\n" \
"fstps " src "\n"
void Sys_SnapVector( vec3_t vector )
{
static const unsigned short cw037F = 0x037F;
unsigned short cwCurr;
__asm__ volatile
(
"fnstcw %1\n" \
"fldcw %2\n" \
QROUNDX87("0(%0)")
QROUNDX87("4(%0)")
QROUNDX87("8(%0)")
"fldcw %1\n" \
:
: "r" (vector), "m"(cwCurr), "m"(cw037F)
: "memory", "st"
);
}
#endif // id386
#endif // linux/mingw
/*
=================
Com_Init

View File

@ -47,6 +47,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#if defined( _MSC_VER ) && _MSC_VER >= 1400 // MSVC++ 8.0 at least
#define OS_STRING "win_msvc"
#elif defined __MINGW32__
#define OS_STRING "win_mingw"
#elif defined __MINGW64__
#define OS_STRING "win_mingw64"
#else
#error "Compiler not supported"
#endif

View File

@ -134,17 +134,6 @@ int Sys_XTimeToSysTime (unsigned long xtime)
#endif
#if !id386
void Sys_SnapVector( float *v )
{
v[0] = round(v[0]);
v[1] = round(v[1]);
v[2] = round(v[2]);
}
#endif
char *strlwr (char *s) {
if ( s==NULL ) { // bk001204 - paranoia
assert(0);

View File

@ -397,7 +397,7 @@ static int GLW_MakeContext( PIXELFORMATDESCRIPTOR *pPFD )
if ( SetPixelFormat( glw_state.hDC, pixelformat, pPFD ) == FALSE )
{
ri.Printf (PRINT_ALL, "...SetPixelFormat failed\n", glw_state.hDC );
ri.Printf (PRINT_ALL, "...SetPixelFormat failed\n" );
return TRY_PFD_FAIL_SOFT;
}

View File

@ -854,10 +854,10 @@ void IN_Win32MouseEvent( int x, int y, int mstate )
#define CHECK_BUTTON(button) \
if ( mstate & (1<<(button-1)) ) { \
if ( !(s_wmv.oldButtonState & (1<<(button-1))) ) \
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MOUSE##button##, qtrue, 0, NULL ); \
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MOUSE##button, qtrue, 0, NULL ); \
} else { \
if ( s_wmv.oldButtonState & (1<<(button-1)) ) \
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MOUSE##button##, qfalse, 0, NULL ); \
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MOUSE##button, qfalse, 0, NULL ); \
}
// perform button actions
@ -910,9 +910,9 @@ void IN_RawMouseEvent( LPARAM lParam )
#define CHECK_RAW_BUTTON(button) \
if ( u.raw.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_##button##_DOWN ) \
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MOUSE##button##, qtrue, 0, NULL ); \
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MOUSE##button, qtrue, 0, NULL ); \
if ( u.raw.data.mouse.usButtonFlags & RI_MOUSE_BUTTON_##button##_UP ) \
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MOUSE##button##, qfalse, 0, NULL )
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MOUSE##button, qfalse, 0, NULL )
CHECK_RAW_BUTTON(1);
CHECK_RAW_BUTTON(2);

View File

@ -62,6 +62,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define DIRECTSOUND_VERSION 0x0300
#define DIRECTINPUT_VERSION 0x0300
#include <mmsystem.h>
#include <dinput.h>
#include <dsound.h>
#include <shlobj.h>

View File

@ -228,60 +228,6 @@ const char *Sys_SteamPath( void )
}
/*
================
Sys_SnapVector
================
*/
#if idx64
void Sys_SnapVector( float *vector )
{
__m128 vf0, vf1, vf2;
__m128i vi;
vf0 = _mm_setr_ps( vector[0], vector[1], vector[2], 0.0 );
vi = _mm_cvtps_epi32( vf0 );
vf0 = _mm_cvtepi32_ps( vi );
vf1 = _mm_shuffle_ps(vf0, vf0, _MM_SHUFFLE(1,1,1,1));
vf2 = _mm_shuffle_ps(vf0, vf0, _MM_SHUFFLE(2,2,2,2));
_mm_store_ss( &vector[0], vf0 );
_mm_store_ss( &vector[1], vf1 );
_mm_store_ss( &vector[2], vf2 );
}
#else
void Sys_SnapVector( float *vector )
{
static const DWORD cw037F = 0x037F;
DWORD cwCurr;
__asm {
fnstcw word ptr [cwCurr]
mov ecx, vector
fldcw word ptr [cw037F]
fld dword ptr[ecx+8]
fistp dword ptr[ecx+8]
fild dword ptr[ecx+8]
fstp dword ptr[ecx+8]
fld dword ptr[ecx+4]
fistp dword ptr[ecx+4]
fild dword ptr[ecx+4]
fstp dword ptr[ecx+4]
fld dword ptr[ecx+0]
fistp dword ptr[ecx+0]
fild dword ptr[ecx+0]
fstp dword ptr[ecx+0]
fldcw word ptr cwCurr
}; // __asm
}
#endif
/*
================
Sys_SetAffinityMask
@ -314,4 +260,3 @@ void Sys_SetAffinityMask( int mask )
Com_Printf( S_COLOR_YELLOW "error setting CPU affinity mask %i\n", mask );
}
}