Not logged inOpenClonk Forum
Up Topic Development / Developer's Corner / patch (freebsd) and problems
- - By mdg [ca] Date 2010-03-12 00:42
Hello,

I am trying to make this compile and run on freebsd. Here is my patch so far:

[code]
diff -r fbe2b32500d5 src/C4WinMain.cpp
--- a/src/C4WinMain.cpp  Sun Mar 07 15:16:58 2010 +0100
+++ b/src/C4WinMain.cpp  Thu Mar 11 15:30:13 2010 -0800
@@ -143,6 +143,7 @@
# include <gtk/gtkwindow.h>
#endif

+#ifndef __FreeBSD__
#ifdef HAVE_EXECINFO_H
#include <execinfo.h>

@@ -182,6 +183,7 @@
   _exit(C4XRV_Failure);
   }
#endif
+#endif

#ifdef __APPLE__
void restart(char* args[]) {
@@ -206,6 +208,7 @@
     printf("Do not run %s as root!\n", argc ? argv[0] : "this program");
     return C4XRV_Failure;
     }
+#ifndef __FreeBSD__
#ifdef HAVE_EXECINFO_H
   // Set up debugging facilities
   signal(SIGBUS, crash_handler);
@@ -217,6 +220,7 @@
   signal(SIGFPE, crash_handler);
   signal(SIGTERM, crash_handler);
#endif
+#endif

   // FIXME: This should only be done in developer mode.
#ifdef WITH_DEVELOPER_MODE
diff -r fbe2b32500d5 src/lib/Standard.h
--- a/src/lib/Standard.h  Sun Mar 07 15:16:58 2010 +0100
+++ b/src/lib/Standard.h  Thu Mar 11 15:30:13 2010 -0800
@@ -187,8 +187,10 @@
   #define C4_OS "linux"
#elif defined(__APPLE__)
   #define C4_OS "mac"
+#elif defined(__FreeBSD__)
+  #define C4_OS "freebsd"
#else
-  #define C4_OS "unknown";
+  #define C4_OS "unknown"
#endif

// Color triplets
diff -r fbe2b32500d5 src/network/C4NetIO.cpp
--- a/src/network/C4NetIO.cpp  Sun Mar 07 15:16:58 2010 +0100
+++ b/src/network/C4NetIO.cpp  Thu Mar 11 15:30:13 2010 -0800
@@ -30,30 +30,6 @@
#include <fcntl.h>
#include <sys/stat.h>

-// platform specifics
-#ifdef _WIN32
-
-#include <process.h>
-#include <share.h>
-
-typedef int socklen_t;
-int pipe(int *phandles) { return _pipe(phandles, 10, O_BINARY); }
-
-#else
-
-#include <sys/ioctl.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <stdlib.h>
-
-#define ioctlsocket ioctl
-#define closesocket close
-#define SOCKET_ERROR (-1)
-
-#endif
-

#ifdef _MSC_VER
#pragma warning (disable : 4355)
diff -r fbe2b32500d5 src/network/C4NetIO.h
--- a/src/network/C4NetIO.h  Sun Mar 07 15:16:58 2010 +0100
+++ b/src/network/C4NetIO.h  Thu Mar 11 15:30:13 2010 -0800
@@ -21,6 +21,34 @@
#ifndef C4NETIO_H
#define C4NETIO_H

+/*
+ matt: Stuff in this file needs netinet/in.h, so I decided to move this here. Probably it should
+ be done somehow else?
+*/
+// platform specifics
+#ifdef _WIN32
+
+#include <process.h>
+#include <share.h>
+
+typedef int socklen_t;
+int pipe(int *phandles) { return _pipe(phandles, 10, O_BINARY); }
+
+#else
+
+#include <sys/ioctl.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <stdlib.h>
+
+#define ioctlsocket ioctl
+#define closesocket close
+#define SOCKET_ERROR (-1)
+
+#endif
+
#include "StdSync.h"
#include "StdBuf.h"
#include "StdCompiler.h"
[/code]

This builds for me, provided I put -march=i486 in CPPFLAGS, as the default arch for gcc in freebsd is i386, and then it would fail at StdSync.h with an undefined reference to __sync_add_and_fetch_4.

I've blocked out the backtrace, as I think that would have to have freebsd specific code, and I am not sure how that would be done. And I moved a bunch of includes in C4NetIO.h because that file needed netinet/in.h and it wasn't included soon enough. Then I think the apostrophe at the end of   #define C4_OS "unknown"; was causing problems for any other OS than the 3 listed.

It compiled and starts up, but then I have other problems. When I start, it asks for a new player, but then when I put one in it says "open: file not found". And it doesn't seem to save any changes I make in options. So I think it is having path issues. There is no graphic when it starts up, or behind the menu, but maybe there just isn't any yet?

Then when I click 'start game', it starts loading the list of missions, but then seems to hang. A few seconds later it aborts and I get this message in the console:

terminate called after throwing an instance of 'std::runtime_error'
  what():  DirectoryIterator::Read(const char*): Unable to read file system
Abort (core dumped)

Any ideas why?

I havn't yet tried 'make install' - but I would rather get this to work in a user directory first.

Matthew
Parent - - By Clonk-Karl [de] Date 2010-03-13 22:30
Hi Matthew,

thanks for the patch. I'd prefer if the #defines and the windows specific stuff stayed in the .cpp file, maybe also the includes not required in the header. Seems good to me otherwise. Can you fix that and attach the revised patch to your post (makes it easier to keep post and patch separate)? You can attach files after having posted, there will be an Attach link right below your post.

> This builds for me, provided I put -march=i486 in CPPFLAGS, as the default arch for gcc in freebsd is i386, and then it would fail at StdSync.h with an undefined reference to __sync_add_and_fetch_4.


You might want to add a check in CMakeLists.txt for that.

> There is no graphic when it starts up, or behind the menu, but maybe there just isn't any yet?


Correct, it should just be grey background.

> Then when I click 'start game', it starts loading the list of missions, but then seems to hang. A few seconds later it aborts and I get this message in the console


This might or might not have to do something with the path problems when creating a player file. You can get a backtrace from the crash with gdb. The line in question is platform/StdFile.cpp:912 in DirectoryIterator::Read - a first step would be to have a look at errno there.

You can also check whether directly starting a scenario works (./clonk Bla/Blub.c4s on the command line), without navigating through the menu to choose a scenario.

> I havn't yet tried 'make install' - but I would rather get this to work in a user directory first.


I don't think make install is even supported.
Reply
Parent - - By mdg [ca] Date 2010-03-18 21:50 Edited 2010-03-18 22:18
./clonk Worlds.c4f/Outset.c4s

That does go a little further, but:

[12:57:22] FATAL ERROR: Required object file Objects.c4d not available.

I got some backtraces. I am afraid I don't really know too much about this, but I've attached what I got.

It is doing something in /compat/linux - I can't figure out why it would ever do this? That is the linux emulation layer, which I am almost sure shouldn't be being accessed.

What is 'cwd'? There is a package: libcwd that isn't installed here.

Maybe the issue is using /proc? I don't know if that is supported on freebsd.

I understand if this is bother for no benefit - you probably won't get many users from freebsd. I just thought I will give it a shot.
Attachment: clonk_backtrace.txt (25k)
Attachment: backtrace_rofna.txt (1k)
Parent - By Newton [de] Date 2010-03-18 23:21
Objects.c4d is definitely in the same directory as the clonk executable?
Parent - By Günther [de] Date 2010-03-19 00:20
cwd is an abbreviation for current working directory.

The where-is-the-game-data and whats-the-working-directory part is one of the more ugly parts of the code. We inherited the principle of the game data being in the same directory as the game executable from the windows code. We should probably add proper code to find the game data in one of two places - the directory the source code is in, or a directory relative to the executable - on unix, that would probably be typically "../share/" C4ENGINENICK. The relevant code is in C4Config.cpp and StdXApp.cpp.
Reply
Parent - - By Günther [de] Date 2010-03-14 01:59

> +#ifndef __FreeBSD__
> #ifdef HAVE_EXECINFO_H


That's the wrong solution. (I know that we have #ifdef _WIN32 all over the code, but that's not a reason to add even more.) The right solution would be for configure and/or CMake to check whether the execinfo.h header is actually usable before defining HAVE_EXECINFO_H. Or perhaps to add a link to the library containing the functions - a quick internet search indicates that there might be one. It certainly would explain why your system has that GNU extension header at all. If you tell me whether your compiler or your linker complains without your patch, I'll add the necessary bits to configure, and if you can find out which library has the functions, I'll add that to configure as well.
Reply
Parent - - By mdg [ca] Date 2010-03-14 07:56
It does complain for execinfo.h functions, and there is a corresponding library
/usr/local/lib/libexecinfo.a
/usr/local/lib/libexecinfo.so
/usr/local/lib/libexecinfo.so.1
The functions are in there.
I guess for some reason these are not being linked in. Also, there is an installed package libexecinfo which I guess would be required on this system.

I will try to touch up the patch file and respond to the other questions later.
Parent - By Günther [de] Date 2010-03-14 20:04

> It


What "It"? I assume you mean the linker, but I'd like to be sure.

execinfo.h is a GNU libc extension, so you don't need an extra library on glibc systems like Linux, so there's no reason it would be linked in.
Reply
Parent - - By Günther [de] Date 2010-03-15 23:32
Does this patch work?
Attachment: source-hg_rev1028.patch - autotools: Also check for the backtrace function before using execinfo.h (3k)
Reply
Parent - - By mdg [ca] Date 2010-03-18 20:52
Yes, that seemed to work nicely.

config.log:
...
configure:4582: checking for execinfo.h
configure:4603: g++ -c -g -O2 -I/usr/local/include -march=i486 conftest.cpp >&5
configure:4610: $? = 0
configure:4627: result: yes
...

And it built without issues.

Here is another patch. Would this do?
Attachment: my2.patch (790B)
Parent - By Günther [de] Date 2010-03-19 00:24
That's a nice patch, but I'd like to know which definitions are missing without that include. Then, there should probably just be a comment "// For foo() and bar" above the include, and the include done on HAVE_NETINIT_IN_H or !_WIN32. Except if this is a bug in freebsd we're working around, not a dependency on Linux and Macosx doing more than POSIX specifies.
Reply
Up Topic Development / Developer's Corner / patch (freebsd) and problems

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill