2013年9月13日 星期五

Build SDL1.2 in Mingw of Codeblocks13.12

Pre-install

1. codeblocks-13.12mingw-setup.exe
https://sourceforge.net/projects/codeblocks/files/Binaries/13.12/

2. DXSDK_Aug09.exe
https://download.microsoft.com/download/4/C/F/4CFED5F5-B11C-4159-9ADC-E133B7E42E5C/DXSDK_Aug09.exe

3. VC9 of VS2008
After install we only need one file
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h


Download source
1.  SDL-1.2.15.tar.gz
https://www.libsdl.org/release/SDL-1.2.15.tar.gz
or
https://www.libsdl.org/release/SDL-1.2.15.zip

2. pthreads-w32-2-9-1-release.zip
ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-9-1-release.zip


Manual Modify
1. copy C:\Program Files\Microsoft Visual Studio 9.0\VC\include\sal.h
to SDL-1.2.15\include

2. copy pthreads-w32-2-9-1-release.zip\Pre-built.2\include
to SDL-1.2.15\include

3. copy pthreads-w32-2-9-1-release.zip\Pre-built.2\lib\x86\libpthreadGC2.a
to SDL-1.2.15\lib

4.  Modify source
C:\Program Files\CodeBlocks\MinGW\include\signal.h
//Refer to http://faculty.cs.niu.edu/~berezin/330/N/signals.html
#define SIGHUP    1 /* Hangup (POSIX).  */
#define SIGINT    2 /* Interrupt (ANSI).  */
#define SIGQUIT   3 /* Quit (POSIX).  */
#define SIGILL    4 /* Illegal instruction (ANSI).  */
#define SIGTRAP   5 /* Trace trap (POSIX).  */
#define SIGABRT   6 /* Abort (ANSI).  */
#define SIGIOT    6 /* IOT trap (4.2 BSD).  */
#define SIGBUS    7 /* BUS error (4.2 BSD).  */
#define SIGFPE    8 /* Floating-point exception (ANSI).  */
#define SIGKILL   9 /* Kill, unblockable (POSIX).  */
#define SIGUSR1   10  /* User-defined signal 1 (POSIX).  */
#define SIGSEGV   11  /* Segmentation violation (ANSI).  */
#define SIGUSR2   12  /* User-defined signal 2 (POSIX).  */
#define SIGPIPE   13  /* Broken pipe (POSIX).  */
#define SIGALRM   14  /* Alarm clock (POSIX).  */
#define SIGTERM   15  /* Termination (ANSI).  */
#define SIGSTKFLT 16  /* Stack fault.  */
#define SIGCHLD   17  /* Child status has changed (POSIX).  */
#define SIGCLD    SIGCHLD /* Same as SIGCHLD (System V).  */
#define SIGCONT   18  /* Continue (POSIX).  */
#define SIGSTOP   19  /* Stop, unblockable (POSIX).  */
#define SIGTSTP   20  /* Keyboard stop (POSIX).  */
#define SIGTTIN   21  /* Background read from tty (POSIX).  */
#define SIGTTOU   22  /* Background write to tty (POSIX).  */
#define SIGURG    23  /* Urgent condition on socket (4.2 BSD).  */
#define SIGXCPU   24  /* CPU limit exceeded (4.2 BSD).  */
#define SIGXFSZ   25  /* File size limit exceeded (4.2 BSD).  */
#define SIGVTALRM 26  /* Virtual alarm clock (4.2 BSD).  */
#define SIGPROF   27  /* Profiling alarm clock (4.2 BSD).  */
#define SIGWINCH  28  /* Window size change (4.3 BSD, Sun).  */
#define SIGIO     29  /* I/O now possible (4.2 BSD).  */
#define SIGPOLL   SIGIO /* Pollable event occurred (System V).  */
#define SIGPWR    30  /* Power failure restart (System V).  */
#define SIGSYS    31  /* Bad system call.  */
#define NSIG      32     /* maximum signal number + 1 */

5. edit SDL-1.2.15\include\SDL_config_win32.h
#if defined(__GNUC__) || defined(__DMC__)
#define HAVE_STDINT_H                        1
#define SDL_THREAD_PTHREAD                                   1 //add
#define SDL_THREAD_PTHREAD_RECURSIVE_MUTEX  1 //add
#elif defined(_MSC_VER)

#ifndef _WIN64
//#define SDL_ASSEMBLY_ROUTINES    1 //remove
#endif

6. edit SDL-1.2.15\src\thread\pthread\SDL_sysmutex.c
 #if !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX && !SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP
    #define FAKE_RECURSIVE_MUTEX 1 //add
#else //add
    #define FAKE_RECURSIVE_MUTEX 0 //add
#endif

7. edit SDL-1.2.15\src\thread\pthread\SDL_systhread.c
void SDL_SYS_SetupThread(void)
{
#if !defined(WIN32) //add
    int i;
    sigset_t mask;

    sigemptyset(&mask);
    for ( i=0; sig_list[i]; ++i ) {
        sigaddset(&mask, sig_list[i]);
    }

pthread_sigmask(SIG_BLOCK, &mask, 0);
#endif //add

#ifdef PTHREAD_CANCEL_ASYNCHRONOUS
    /* Allow ourselves to be asynchronously cancelled */
    {
        int oldstate;
        pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldstate);
    }
#endif
}

Uint32 SDL_ThreadID(void)
{
#if !defined(WIN32) //add
    return((Uint32)((size_t)pthread_self()));
#else //add
    return (Uint32)pthread_self().p; //add
#endif //add
}


Codeblocks Project
1. open codeblocks project setting in
SDL-1.2.15\build\SDL.cbp

2. add search directories include path
..\include
C:\Program Files\Microsoft DirectX SDK (August 2009)\Include

3. add  search directories lib path
..\lib

4. add link lib
winmm
dxguid
gdi32
ddraw
dsound
pthreadGC2

5. enable -std=c++11
build and done

Full source:
http://www.mediafire.com/file/91koy3tdwa8b528/SDL1215source.rar

沒有留言:

張貼留言