UCyborg / BerserkerQuake2

Berserker@Quake2 game engine, ported to SDL2 library.
GNU General Public License v2.0
20 stars 9 forks source link

Compilation with MinGW #8

Open UCyborg opened 7 years ago

UCyborg commented 7 years ago

Still need to look into making the code compilable with MinGW.

hgdagon commented 6 years ago

I was messing around just for myself, but, maybe, you can use this as a starting point.

Or, if you don't want to download: I added #include <errno.h> to both main.c and game.c. Converted both Berserker.rc and resource.h to UTF-8 (also converted EOL to LF). Replaced winres.h in Berserker.rc with windows.h. And here's my Makefile.mingw:

CC=gcc
WINDRES=windres

CFLAGS=-w -O3 -fno-strict-aliasing -DNDEBUG

LDFLAGS_ENGINE=-lopengl32 -lvorbis -lvorbisfile -lz -lminizip -lws2_32 -lmingw32 -lSDL2Main -lSDL2 -lpng -ljpeg
LDFLAGS_GAME=-shared -fPIC

ENGINE_SOURCES=main.c unpak.c
GAME_SOURCES=game.c

ENGINE_OBJECTS=$(ENGINE_SOURCES:.c=.o)
GAME_OBJECTS=$(GAME_SOURCES:.c=.o)

ENGINE_EXE=berserkerq2.exe
GAME_LIB=game.dll
ICON = Berserker/Berserker.rc
ICONRES = Berserker/Berserker.res

all: $(ENGINE_EXE) $(GAME_LIB)

$(ENGINE_OBJECTS): %.o : %.c
    $(CC) $(CFLAGS) -c $< -o $@

$(GAME_OBJECTS): %.o : %.c
    $(CC) $(CFLAGS) -fPIC -fvisibility=hidden -c $< -o $@

$(ENGINE_EXE): $(ENGINE_OBJECTS) $(ICONRES)
    $(CC) -o $@ $^ $(LDFLAGS_ENGINE)

$(GAME_LIB): $(GAME_OBJECTS)
    $(CC) -o $@ $(GAME_OBJECTS) $(LDFLAGS_GAME)

$(ICONRES): $(ICON)
    $(WINDRES) $^ -O coff -o $@

clean:
    -rm $(ENGINE_EXE) $(GAME_LIB) $(ENGINE_OBJECTS) $(GAME_OBJECTS) $(ICONRES)

When I actually got to testing, I realized

my current laptop royally sucks (and my main laptop is unavailable). So, I can only confirm, that this builds (in both MinGW and MinGW-W64), launches, caches everything (AFTER cranking up the hunksize), and starts the first map. No idea how it actually behaves in-game, though. I use msys2.

BerserkerQuake2-msys2-wip.zip

UCyborg commented 6 years ago

You got further than me. I messed with this some time ago and the errno.h was the easy part. I somehow ended up with .exe that just crashed on startup.

Didn't use msys2 at the time, this might be the key. I find compiling with MinGW interesting because you supposedly end up with binaries that link against good old msvcrt.dll, rather than newer runtimes.

I only used pacman briefly when I wanted to get Berserker compiled and running on Manjaro. It was pretty straightforward, thought I'd be more difficult. So I assume with msys2, you can get dev files as well as pre-compiled binaries? I ask because when I was searching the internet for binaries of dependent libraries, I only found SDL2 and zlib.

Thank you for your this. I'll look into it further when I find more time.

hgdagon commented 6 years ago

@UCyborg You don't need to search the internet, msys2 has it's own repos and comes with pacman. And yes, pretty much every package contains libraries, headers, as well as binaries. If the package you need is not in the repos, you can always (try to) compile from source yourself.

UCyborg commented 6 years ago

Good to know. When I get to it, I'll try to make another release compiled exclusively with with Windows version of gcc. The pre-compiled libraries should make this easier. The ZIP file in the Releases section contains 99% of the things compiled with MSVC, except the SDL2 library, which I had problems compiling on my own... It might have needed extra stuff from DirectX SDK June 2010 release to get SDL2 binary with all features, not sure. Some of the DX headers and libraries are definitely included in the current SDKs you get with Visual Studio.

There's also Visual Studio way of managing packages, NuGet, but at the time, I didn't find every package needed. Another project, dhewm3, has those includes and libs in a separate repo. As these things are only here for Windows compiling and redundant for non-Windows systems...