Linux fix patch

Linux geeks and Mac OS hipsters unite! A board for discussion of Supermodel on non-Windows platforms.
Forum rules
Keep it classy!

  • No ROM requests or links.
  • Do not ask to be a play tester.
  • Do not ask about release dates.
  • No drama!

Linux fix patch

Postby sergio-br2 » Sun Apr 03, 2016 5:42 pm

Hi!

I can compile Supermodel with the patch below.

The patch basically fix the Unix makefile and give you the option to build with Glew and Minizip from the system or statically.

I'm not sure about "types.h", does it the right path on windows? On linux it needs to be <sys/types.h>

Code: Select all
Index: trunk/Makefiles/Makefile.SDL.UNIX.GCC
===================================================================
--- trunk.orig/Makefiles/Makefile.SDL.UNIX.GCC   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Makefiles/Makefile.SDL.UNIX.GCC   2016-04-04 18:11:03.212520442 -0300
@@ -65,12 +65,27 @@
 # Compiler and Linker
 ###############################################################################
 
+USE_MINIZIP_STATIC ?= 0
+USE_GLEW_STATIC ?= 0
+
 CC = gcc
 LD = gcc
 COMPILER_FLAGS = $(SDL_CFLAGS) -ISrc/ -ISrc/OSD/SDL/ -ISrc/Pkgs/ -c -Wall -O3
-CFLAGS = $(COMPILER_FLAGS)
-CPPFLAGS = $(COMPILER_FLAGS)
-LFLAGS = -o $(OUTFILE) $(SDL_LIBFLAGS) -lGL -lGLU -lz -lm -lstdc++
+CFLAGS += $(COMPILER_FLAGS)
+CPPFLAGS += $(CXXFLAGS) $(COMPILER_FLAGS) -std=c++11
+LFLAGS += -o $(OUTFILE) $(SDL_LIBFLAGS) -lGL -lGLU -lz -lm -lstdc++
+
+ifeq ($(USE_GLEW_STATIC), 1)
+   COMPILER_FLAGS += -DGLEW_STATIC
+else
+   LFLAGS += -lGLEW
+endif
+
+ifeq ($(USE_MINIZIP_STATIC), 1)
+   COMPILER_FLAGS += -DMINIZIP_STATIC
+else
+   LFLAGS += -lminizip
+endif
 
 #
 # Build options...
@@ -91,8 +106,10 @@
 #
 HEADERS = Src/Supermodel.h Src/Games.h Src/OSD/SDL/Types.h
 OBJ = $(OBJ_DIR)/PPCDisasm.o $(OBJ_DIR)/Games.o $(OBJ_DIR)/Config.o $(OBJ_DIR)/INIFile.o $(OBJ_DIR)/BlockFile.o $(OBJ_DIR)/93C46.o \
-   $(OBJ_DIR)/ROMLoad.o $(OBJ_DIR)/unzip.o $(OBJ_DIR)/ioapi.o $(OBJ_DIR)/Error.o $(OBJ_DIR)/glew.o $(OBJ_DIR)/Shader.o \
-   $(OBJ_DIR)/Real3D.o $(OBJ_DIR)/Render3D.o $(OBJ_DIR)/Models.o $(OBJ_DIR)/TextureRefs.o $(OBJ_DIR)/Render2D.o $(OBJ_DIR)/TileGen.o \
+   $(OBJ_DIR)/ROMLoad.o $(OBJ_DIR)/Error.o $(OBJ_DIR)/Shader.o \
+   $(OBJ_DIR)/Real3D.o $(OBJ_DIR)/Legacy3D.o $(OBJ_DIR)/Models.o $(OBJ_DIR)/TextureRefs.o \
+   $(OBJ_DIR)/New3D.o $(OBJ_DIR)/Mat4.o $(OBJ_DIR)/Model.o $(OBJ_DIR)/PolyHeader.o $(OBJ_DIR)/Texture.o $(OBJ_DIR)/TextureSheet.o $(OBJ_DIR)/VBO.o $(OBJ_DIR)/Vec.o $(OBJ_DIR)/R3DShader.o \
+   $(OBJ_DIR)/Render2D.o $(OBJ_DIR)/TileGen.o \
    $(OBJ_DIR)/Model3.o $(OBJ_DIR)/ppc.o $(OBJ_DIR)/Main.o $(OBJ_DIR)/Audio.o $(OBJ_DIR)/Thread.o $(OBJ_DIR)/SoundBoard.o \
    $(OBJ_DIR)/SCSP.o $(OBJ_DIR)/SCSPDSP.o $(OBJ_DIR)/68K.o $(OBJ_DIR)/m68kcpu.o $(OBJ_DIR)/m68kopnz.o $(OBJ_DIR)/m68kopdm.o \
    $(OBJ_DIR)/m68kopac.o $(OBJ_DIR)/m68kops.o $(OBJ_DIR)/DSB.o $(OBJ_DIR)/Z80.o \
@@ -102,7 +119,16 @@
    $(OBJ_DIR)/Outputs.o \
    $(OBJ_DIR)/amp_audio.o $(OBJ_DIR)/amp_dump.o $(OBJ_DIR)/amp_getbits.o $(OBJ_DIR)/amp_getdata.o $(OBJ_DIR)/amp_huffman.o \
    $(OBJ_DIR)/amp_layer2.o $(OBJ_DIR)/amp_layer3.o $(OBJ_DIR)/amp_misc2.o $(OBJ_DIR)/amp_position.o $(OBJ_DIR)/amp_transform.o \
-   $(OBJ_DIR)/amp_util.o
+   $(OBJ_DIR)/amp_util.o \
+   $(OBJ_DIR)/Crypto.o
+
+ifeq ($(USE_GLEW_STATIC), 1)
+   OBJ += $(OBJ_DIR)/glew.o
+endif
+
+ifeq ($(USE_MINIZIP_STATIC), 1)
+   OBJ += $(OBJ_DIR)/unzip.o $(OBJ_DIR)/ioapi.o
+endif
 
 # If built-in debugger enabled, include all debugging classes
 ifeq ($(strip $(ENABLE_DEBUGGER)),yes)
@@ -172,12 +198,18 @@
 $(OBJ_DIR)/%.o:   Src/Model3/%.cpp Src/Model3/%.h $(HEADERS)
    $(CC) $< $(CPPFLAGS) -o $(OBJ_DIR)/$(*F).o
 
-$(OBJ_DIR)/%.o:   Src/Graphics/%.cpp Src/Graphics/%.h $(HEADERS)
-   $(CC) $< $(CPPFLAGS) -o $(OBJ_DIR)/$(*F).o
-   
-$(OBJ_DIR)/%.o:   Src/Graphics/%.cpp $(HEADERS)
-   $(CC) $< $(CPPFLAGS) -o $(OBJ_DIR)/$(*F).o
-   
+$(OBJ_DIR)/%.o:   Src/Graphics/%.cpp Src/Graphics/Shaders2D.h
+   $(CXX) $< $(CPPFLAGS) -o $(OBJ_DIR)/$(*F).o
+
+$(OBJ_DIR)/%.o:   Src/Graphics/Legacy3D/%.cpp Src/Graphics/Legacy3D/%.h Src/Graphics/Legacy3D/Shaders3D.h
+   $(CXX) $< $(CPPFLAGS) -o $(OBJ_DIR)/$(*F).o
+
+$(OBJ_DIR)/%.o:   Src/Graphics/Legacy3D/%.cpp
+   $(CXX) $< $(CPPFLAGS) -o $(OBJ_DIR)/$(*F).o
+
+$(OBJ_DIR)/%.o:   Src/Graphics/New3D/%.cpp Src/Graphics/New3D/%.h
+   $(CXX) $< $(CPPFLAGS) -o $(OBJ_DIR)/$(*F).o
+
 $(OBJ_DIR)/%.o:   Src/Sound/%.cpp Src/Sound/%.h $(HEADERS)
    $(CC) $< $(CPPFLAGS) -o $(OBJ_DIR)/$(*F).o
 
Index: trunk/Src/Graphics/Render2D.cpp
===================================================================
--- trunk.orig/Src/Graphics/Render2D.cpp   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/Render2D.cpp   2016-04-04 18:11:03.212520442 -0300
@@ -269,7 +269,11 @@
  */
 
 #include <cstring>
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"
+#else
+#include <GL/glew.h>
+#endif
 #include "Supermodel.h"
 #include "Graphics/Shaders2D.h"   // fragment and vertex shaders
 
Index: trunk/Src/Graphics/Render2D.h
===================================================================
--- trunk.orig/Src/Graphics/Render2D.h   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/Render2D.h   2016-04-04 18:11:03.212520442 -0300
@@ -28,7 +28,11 @@
 #ifndef INCLUDED_RENDER2D_H
 #define INCLUDED_RENDER2D_H
 
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"
+#else
+#include <GL/glew.h>
+#endif
 
 
 /*
Index: trunk/Src/Graphics/Shader.cpp
===================================================================
--- trunk.orig/Src/Graphics/Shader.cpp   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/Shader.cpp   2016-04-04 18:11:03.212520442 -0300
@@ -44,7 +44,11 @@
 
 #include <new>
 #include <cstdio>
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"
+#else
+#include <GL/glew.h>
+#endif
 #include "Supermodel.h"
 
 
Index: trunk/Src/Graphics/Shader.h
===================================================================
--- trunk.orig/Src/Graphics/Shader.h   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/Shader.h   2016-04-04 18:11:03.212520442 -0300
@@ -28,7 +28,11 @@
 #ifndef INCLUDED_SHADER_H
 #define INCLUDED_SHADER_H
 
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"
+#else
+#include <GL/glew.h>
+#endif
 
 /*
  * LoadShaderProgram(shaderProgramPtr, vertexShaderPtr, fragmentShaderPtr,
Index: trunk/Src/OSD/SDL/Main.cpp
===================================================================
--- trunk.orig/Src/OSD/SDL/Main.cpp   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/OSD/SDL/Main.cpp   2016-04-04 18:11:03.212520442 -0300
@@ -43,7 +43,11 @@
 #include <cstdio>
 #include <cstring>
 #include <cstdarg>
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"
+#else
+#include <GL/glew.h>
+#endif
 #ifdef SUPERMODEL_OSX
 #include <SDL/SDL.h>
 #else
Index: trunk/Src/Graphics/Legacy3D/Legacy3D.h
===================================================================
--- trunk.orig/Src/Graphics/Legacy3D/Legacy3D.h   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/Legacy3D/Legacy3D.h   2016-04-04 18:11:03.212520442 -0300
@@ -30,7 +30,11 @@
 #define INCLUDED_LEGACY3D_H
 
 #include "Graphics/IRender3D.h"
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"
+#else
+#include <GL/glew.h>
+#endif
 
 namespace Legacy3D {
 
Index: trunk/Src/Graphics/New3D/New3D.h
===================================================================
--- trunk.orig/Src/Graphics/New3D/New3D.h   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/New3D/New3D.h   2016-04-04 18:11:03.212520442 -0300
@@ -28,7 +28,11 @@
 #ifndef INCLUDED_NEW3D_H
 #define INCLUDED_NEW3D_H
 
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"
+#else
+#include <GL/glew.h>
+#endif
 #include "Types.h"
 #include "TextureSheet.h"
 #include "Graphics/IRender3D.h"
Index: trunk/Src/Graphics/New3D/R3DShader.h
===================================================================
--- trunk.orig/Src/Graphics/New3D/R3DShader.h   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/New3D/R3DShader.h   2016-04-04 18:11:03.212520442 -0300
@@ -1,7 +1,11 @@
 #ifndef _R3DSHADER_H_
 #define _R3DSHADER_H_
 
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"
+#else
+#include <GL/glew.h>
+#endif
 #include "Model.h"
 
 namespace New3D {
@@ -64,4 +68,4 @@
 
 } // New3D
 
-#endif
\ No newline at end of file
+#endif
Index: trunk/Src/Graphics/New3D/Texture.h
===================================================================
--- trunk.orig/Src/Graphics/New3D/Texture.h   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/New3D/Texture.h   2016-04-04 18:11:03.212520442 -0300
@@ -2,7 +2,11 @@
 #define _TEXTURE_H_
 
 #include "Types.h"
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"   //arg
+#else
+#include <GL/glew.h>   //arg
+#endif
 
 namespace New3D {
   
Index: trunk/Src/Graphics/New3D/VBO.h
===================================================================
--- trunk.orig/Src/Graphics/New3D/VBO.h   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/New3D/VBO.h   2016-04-04 18:11:03.212520442 -0300
@@ -1,7 +1,11 @@
 #ifndef _VBO_H_
 #define _VBO_H_
 
+#ifdef GLEW_STATIC
 #include "Pkgs/glew.h"
+#else
+#include <GL/glew.h>
+#endif
 
 namespace New3D {
 
Index: trunk/Src/Graphics/New3D/Model.h
===================================================================
--- trunk.orig/Src/Graphics/New3D/Model.h   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/New3D/Model.h   2016-04-04 18:11:38.229037419 -0300
@@ -1,7 +1,11 @@
 #ifndef _MODEL_H_
 #define _MODEL_H_
 
+#ifdef SUPERMODEL_WIN32
 #include "Types.h"
+#else
+#include <sys/types.h>
+#endif
 #include <vector>
 #include <unordered_map>
 #include <map>
@@ -126,4 +130,4 @@
 } // New3D
 
 
-#endif
\ No newline at end of file
+#endif
Index: trunk/Src/Graphics/New3D/Vec.cpp
===================================================================
--- trunk.orig/Src/Graphics/New3D/Vec.cpp   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/Graphics/New3D/Vec.cpp   2016-04-04 18:11:03.212520442 -0300
@@ -1,6 +1,10 @@
+#ifdef SUPERMODEL_WIN32
 #include <windows.h>
-#include "Vec.h"
 #include <Math.h>
+#else
+#include <math.h>
+#endif
+#include "Vec.h"
 
 namespace New3D {
 
Index: trunk/Makefiles/Makefile.SDL.Win32.GCC
===================================================================
--- trunk.orig/Makefiles/Makefile.SDL.Win32.GCC   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Makefiles/Makefile.SDL.Win32.GCC   2016-04-04 18:11:03.212520442 -0300
@@ -97,7 +97,7 @@
 CC = gcc
 CXX = g++
 LD = g++
-COMPILER_FLAGS = -I$(SDL_INCLUDEPATH) -ISrc/ -ISrc/OSD/ -ISrc/OSD/SDL/ -ISrc/OSD/Windows/ -c -Wall -DSUPERMODEL_WIN32 -DGLEW_STATIC -O3
+COMPILER_FLAGS = -I$(SDL_INCLUDEPATH) -ISrc/ -ISrc/OSD/ -ISrc/OSD/SDL/ -ISrc/OSD/Windows/ -c -Wall -DSUPERMODEL_WIN32 -DGLEW_STATIC -DMINIZIP_STATIC -O3
 CFLAGS = $(COMPILER_FLAGS)
 CPPFLAGS = $(COMPILER_FLAGS) -I$(BOOST_INCLUDEPATH) -std=c++11
 LFLAGS = -o $(OUTFILE) $(OBJ) -L$(SDL_LIBPATH) -lmingw32 -lSDLmain -lSDL -lopengl32 -lglu32 -ldinput8 -ldxguid -lole32 -loleaut32 -lwbemuuid -lz -s #-l:$(WINSDK_LIBPATH)/WbemUuid.lib -s
Index: trunk/Src/ROMLoad.cpp
===================================================================
--- trunk.orig/Src/ROMLoad.cpp   2016-04-04 18:11:03.216520502 -0300
+++ trunk/Src/ROMLoad.cpp   2016-04-04 18:11:03.216520502 -0300
@@ -28,7 +28,11 @@
 #include <new>
 #include <cstring>
 #include "Supermodel.h"
+#ifdef MINIZIP_STATIC
 #include "Pkgs/unzip.h"
+#else
+#include <minizip/unzip.h>
+#endif
 
 static bool IsPowerOfTwo(long x)
 {



http://bazaar.launchpad.net/~random-stu ... uild.patch

Patch updated to svn 333
Last edited by sergio-br2 on Mon Apr 04, 2016 2:15 pm, edited 1 time in total.
sergio-br2
 
Posts: 22
Joined: Wed May 27, 2015 7:14 pm

Re: Linux fix patch

Postby sergio-br2 » Sun Apr 03, 2016 5:49 pm

It also enables compile with CFLAG and CXXFLAGS from the system.
sergio-br2
 
Posts: 22
Joined: Wed May 27, 2015 7:14 pm

Re: Linux fix patch

Postby Bart » Mon Apr 04, 2016 11:54 am

Thanks. I'll take a look at this patch. I was able to build without the glew-related changes. What's wrong with Pkgs/glew.h?

Re: types.h, it should be Types.h and I think I fixed that already in SVN. The windows.h include needs to be removed from Vec.cpp as well (it's not needed.)
User avatar
Bart
Site Admin
 
Posts: 2064
Joined: Thu Sep 01, 2011 2:13 pm
Location: New York City

Re: Linux fix patch

Postby sergio-br2 » Mon Apr 04, 2016 2:38 pm

Bart wrote:Thanks. I'll take a look at this patch. I was able to build without the glew-related changes. What's wrong with Pkgs/glew.h?


There's nothing wrong there, it's just a good practice to use shared libs on debian/ubuntu. Also, if someday it goes to the official repos, it must use shared libs.

Btw, talking about package, I could send it to debian, I think Supermodel only needs to save stuff at ~/.config/Supermodel/ instead the folder you launch it. And it should use SDL2 instead (SDL 1.2 will deprecated soon I think).

Could you merge the manpage too? http://bazaar.launchpad.net/~random-stu ... permodel.1
It's missing the new commands for old/new renderer (are there any place to get this info updated?)
sergio-br2
 
Posts: 22
Joined: Wed May 27, 2015 7:14 pm

Re: Linux fix patch

Postby sergio-br2 » Mon Apr 04, 2016 3:04 pm

In the case anyone wants to build Supermodel with glew and minizip from the Src/Pkgs/ :

Code: Select all
make -f Makefiles/Makefile.SDL.UNIX.GCC USE_MINIZIP_STATIC=1 USE_GLEW_STATIC=1


If you have libglew-dev and libminizip-dev in your system:

Code: Select all
make -f Makefiles/Makefile.SDL.UNIX.GCC
sergio-br2
 
Posts: 22
Joined: Wed May 27, 2015 7:14 pm

Re: Linux fix patch

Postby Bart » Mon Apr 04, 2016 3:06 pm

sergio-br2 wrote:
Bart wrote:Thanks. I'll take a look at this patch. I was able to build without the glew-related changes. What's wrong with Pkgs/glew.h?


There's nothing wrong there, it's just a good practice to use shared libs on debian/ubuntu. Also, if someday it goes to the official repos, it must use shared libs.


The drawback of shared libraries is that when the library changes, the code breaks. With code as stable as glew and even zlib, it makes sense to bundle as much together as possible in a static snapshot.

Btw, talking about package, I could send it to debian, I think Supermodel only needs to save stuff at ~/.config/Supermodel/ instead the folder you launch it. And it should use SDL2 instead (SDL 1.2 will deprecated soon I think).


I'll look into this when I build a new computer and install Linux (a project that is currently delayed because I had to return a defective motherboard and PSU). I'll have to think about how best to implement this because it's not ideal for Windows. Ideally, the config system should be completely rewritten but I won't have time for this.

Could you merge the manpage too? http://bazaar.launchpad.net/~random-stu ... permodel.1
It's missing the new commands for old/new renderer (are there any place to get this info updated?)


Where in the source tree should this go? Also, who will maintain it? It looks to me like there are hard-coded paths in there which will not be applicable to all Linux distros.
User avatar
Bart
Site Admin
 
Posts: 2064
Joined: Thu Sep 01, 2011 2:13 pm
Location: New York City

Re: Linux fix patch

Postby sergio-br2 » Mon Apr 04, 2016 3:51 pm

Bart wrote:The drawback of shared libraries is that when the library changes, the code breaks. With code as stable as glew and even zlib, it makes sense to bundle as much together as possible in a static snapshot.


glew and minizip are stable like you said, hardly will break the code.

Bart wrote:Where in the source tree should this go? Also, who will maintain it? It looks to me like there are hard-coded paths in there which will not be applicable to all Linux distros.


Yeah, right, better to maintain it in the deb package for now.
sergio-br2
 
Posts: 22
Joined: Wed May 27, 2015 7:14 pm

Re: Linux fix patch

Postby Bart » Mon Apr 04, 2016 9:31 pm

Can you try the latest Makefile I committed?
User avatar
Bart
Site Admin
 
Posts: 2064
Joined: Thu Sep 01, 2011 2:13 pm
Location: New York City

Re: Linux fix patch

Postby sergio-br2 » Tue Apr 05, 2016 6:43 pm

Bart wrote:Can you try the latest Makefile I committed?


It's working. But why this -I$(BOOST_INCLUDEPATH) ? Linux binary does not use boost at all here.

Are there any reason to avoid use += to CFLAGS and CPPFLAGS? And use CPPFLAGS over CXXFLAGS? And why hardcode the compiler to gcc ?

Debian/Ubuntu uses these flags in CFLAGS: -g -O2 -fstack-protector -Wformat -Werror=format-security
sergio-br2
 
Posts: 22
Joined: Wed May 27, 2015 7:14 pm

Re: Linux fix patch

Postby Bart » Tue Apr 05, 2016 7:37 pm

Whoops! Boost was needed for my rewrite of the 3D engine, which I abandoned and never committed. It's not necessary for now -- although it may be in the future. CPPFLAGS should ultimately be renamed to CXXFLAGS. Since I don't have a configure script, it is up to the user to set up paths and change the compiler if necessary.

I am always open to a better, more generic Makefile, however. Feel free to submit one. At work, we no longer use Makefiles but have a custom Python-based build system that automatically computes all dependencies and figures out what to build.
User avatar
Bart
Site Admin
 
Posts: 2064
Joined: Thu Sep 01, 2011 2:13 pm
Location: New York City

Next

Return to Alternative Fashion

Who is online

Users browsing this forum: No registered users and 1 guest