Page 1 of 2

Mac OS X

PostPosted: Thu Apr 10, 2014 18:52
by haschatan
Hi!

I have not found how to install Minetest on OS X. Can someone help me please?
Thank you very much.

PostPosted: Thu Apr 10, 2014 19:07
by Topywo
There's not much about the Mac.

Some old info about even older info is in posts 16 and 18.

https://forum.minetest.net/viewtopic.php?id=8532

PostPosted: Fri Apr 18, 2014 06:29
by haschatan
Ok. I do not understand why nobody want to compile Minetest on Mac OS. What a shame.

PostPosted: Fri Apr 18, 2014 08:10
by Topywo
haschatan wrote:Ok. I do not understand why nobody want to compile Minetest on Mac OS. What a shame.


I guess there are not that many Mac users that like to play minetest and are able to compile it on the Mac OS.

Compiling minetest for Windows seems to be difficult too, but there are enough Window minetestplayers to bring forth some that are able and willing to compile it on Windows.

One alternative can be to use a virtual machine on your Mac on which you are able to play minetest under Windows or a Linux OS.

PostPosted: Fri Apr 18, 2014 12:58
by flake
I have minetest running in wine on OSX.

homebrew install, doctor, update,
brew install wine

wine /minetest/bin/minetest.exe

and go.....

PostPosted: Fri Apr 18, 2014 17:09
by Morn76
I can't even get Minetest to build without errors on OS X Mavericks:


Sorry, OP, I really wanted to contribute a working OS X build here, but apparently it's not going to happen. :-(

Image

PostPosted: Sat Apr 19, 2014 00:25
by Morn76
Update for compilation issue #3 in my previous post:

Apparently the line with "#include <CoreFoundation/CoreFoundation.h>" does not like to be included from within a C++ namespace. If I move the two OS X-specific includes from porting.cpp to porting.h (right before "namespace porting"), there are no more compilation errors.

Now minetest compiles but doesn't link on OS X. Apparently "-librt" is another Linux thing that needs to be disabled on OS X somehow.

Edit: Replaced "-lrt" with '"-framework CoreFoundation"' (the quotes are important) in src/CMakeLists.txt. Still doesn't link 100% though, apparently because the code gets compiled for 32 bit but the libraries are all 64 bit.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 06:23
by OmniStudent
Thankyou Morn76, your advice has gotten me quite far on compiling on osx.

Managed to compile on xcode 5.1 by setting architechture on all targets to x86_64, which I guess means I got a 64bit minecraft :)

Managed to build the "package" target too by putting an old "mac" folder inside the "misc" folder in minetest.

But at startup the program crashed due to

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
Assertion failed: (sem_init_retval == 0), function JSemaphore, file /Users/me/minetest/minetest/src/jthread/pthread/jsemaphore.cpp, line 28.


so I guess changing to sem_wait() returned to byte us in the ass :(

Update: it wasn't sem_wait, it was sem_init() in jsemaphore.cpp. Apparently this is not properly implemented on osx and returns -1

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 11:46
by Morn76
I also forgot to mention in my first post that the first thing to do is "cmake -G Xcode ." to get an Xcode project file. Then I also had to comment out the line with "install(FILES "misc/minetest.desktop" DESTINATION "${XDG_APPS_DIR}")" in CMakeLists.txt.

But back to our current progress.

OmniStudent wrote:Managed to compile on xcode 5.1 by setting architechture on all targets to x86_64, which I guess means I got a 64bit minecraft :)


How did you set the architecture in Xcode, OmniStudent?

OmniStudent wrote:But at startup the program crashed due to

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
Assertion failed: (sem_init_retval == 0), function JSemaphore, file /Users/me/minetest/minetest/src/jthread/pthread/jsemaphore.cpp, line 28.


it was sem_init() in jsemaphore.cpp. Apparently this is not properly implemented on osx and returns -1


Found this:

"Unnamed semaphores are not supported, you need to use named semaphores.

To use named semaphores instead of unnamed semaphores, use sem_open instead of sem_init, and use sem_close and sem_unlink instead of sem_destroy."


http://stackoverflow.com/questions/1413 ... it-on-os-x

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 12:35
by OmniStudent
Morn76 wrote:
How did you set the architecture in Xcode, OmniStudent?



Change Architectures to "standard architectures".

Image

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 12:42
by OmniStudent
Morn76 wrote:Found this:

"Unnamed semaphores are not supported, you need to use named semaphores.

To use named semaphores instead of unnamed semaphores, use sem_open instead of sem_init, and use sem_close and sem_unlink instead of sem_destroy."


http://stackoverflow.com/questions/1413 ... it-on-os-x


Tried to rewrite using sem_open this morning, but it was over my head :(

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 13:16
by Morn76
Thanks for your help with Xcode; now I can build Minetest too. So far, so good.

Apparently Sapier has written jsemaphore.cpp, so maybe we should contact him about this? Unfortunately, "Easter Sunday + German ethnicity" usually means we should not expect to get a reply before Tuesday or so. :-)

Alternatively we could grep through the code a bit and try to understand how exactly Minetest uses semaphores. E.g. I don't understand where "m_semaphore" comes from. I think there must be a list of semaphore variables that is administered somewhere else in the program.

According to the sem_overview man page on Linux, names have to look like "/something\0", so maybe we could just randomly generate a name that fits the pattern and use it?

Edit: Ah, now I see m_semaphore is defined as a private variable in jsemaphore.h. So I guess that is also where we could define the semaphore name.

Edit: OK, JSemaphore only seems to be used in three places:

$ find .|xargs grep -s JSema|grep JSema
./util/container.h: JSemaphore m_size;
./script/lua_api/l_async_events.h: JSemaphore m_JobQueueCounter;
./connection.h: JSemaphore m_send_sleep_semaphore;


So now the question is, how do we assign these three semaphores names that are guaranteed not to clash? Maybe the JSemaphore constructor needs to be changed to accept a semaphore name from the Minetest main source code.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 14:16
by Morn76
Apparently all this semaphore stuff does in Minetest is fix a minor problem with the modstore: https://github.com/minetest/minetest/co ... 71786fc01f
https://github.com/minetest/minetest/co ... 5c78ec04c7

So basically a version of Minetest that is older than about five months should work on OS X I think. Which makes sense because there have been successful OS X builds in the past.

P.S. This page (http://sourceforge.net/p/log4cplus/bugs/145/ ) has two fixes to turn unnamed semaphores into named ones. One in the first comment and one in the diff further down the page. I might give this a try.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 14:41
by OmniStudent
I've been taking the road of trying to compile earlier versions and have compiled
sha: 977232261388fa80bd6ab3bb849ae4d7a8ade73e
which is just before jsemaphores were introduced.

The packaging script is still screwed up but at least this is "proof of concept"

Image

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 14:57
by Morn76
Great, at least an older version works! Meanwhile, I've tried the "#define" macro workaround in jsemaphore.h, but there is some problem with sem_getvalue (which the #define method does not seem to implement). So this is no silver bullet either.

P.S. Apparently OX X does not implement sem_getvalue ( http://stackoverflow.com/questions/1665 ... mac-os-x-c ), so it's no wonder this workaround fails.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 15:05
by Inocudom
Eventually, a way will have to be found to allow for the compiling of development builds.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 15:21
by Morn76
I think ideally all required changes to build on OS X should be merged into the main codebase inside appropriate #ifdef's etc., so "cmake .; make" will produce a working MT binary on OS X.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 15:26
by hoodedice
I think either Morn or OmniStudent should try and report this to the Minetest GitHub issues page. That way, we can get an official fix for this 'semaphore' issue.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 16:14
by Morn76
Done: https://github.com/minetest/minetest/issues/1242

And I've sent an email to Sapier too, pointing him to this bug report, because he seems to be active on GH right now.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 17:16
by OmniStudent
Morn76 wrote:P.S. Apparently OX X does not implement sem_getvalue ( http://stackoverflow.com/questions/1665 ... mac-os-x-c ), so it's no wonder this workaround fails.
]

That's a pity, I thought that was the way to go :(

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 17:31
by Morn76
OmniStudent wrote:
Morn76 wrote:P.S. Apparently OX X does not implement sem_getvalue ( http://stackoverflow.com/questions/1665 ... mac-os-x-c ), so it's no wonder this workaround fails.
]

That's a pity, I thought that was the way to go :(


Especially as this is the solution Apple is using itself in its Radius implementation. Then again, after what I've read, sem_getvalue() should never be used, even on systems on which it is implemented, because its return value may be wrong.

There seems to be only a single line in MT that needs sem_getvalue(), so maybe I should make the method always return 0 or 1 or whatever and see what happens.

P.S. Now MT starts, but then hangs indefinitely in JSemaphore::Wait(). The lack of sem_timedwait() is apparently the problem.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 17:53
by OmniStudent
Cool that it at least gets somewhere, but the wait function probably only increments 0, returned from sem_getvalue()

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 18:05
by Morn76
StackOverflow also links to this monster: http://www.aao.gov.au/local/www/ks/uplo ... imedwait.c , but I don't even know how I would integrate this thing into the existing code. More fiddling with cmake would probably be needed.

I've tried their simpler "alarm(2)" approach from http://stackoverflow.com/questions/6411 ... lternative , but that seemed to exit the program when the timer was called.

Re: Mac OS X

PostPosted: Sun Apr 20, 2014 23:06
by Morn76
OmniStudent wrote:Managed to build the "package" target too by putting an old "mac" folder inside the "misc" folder in minetest.


Where did you get that mac folder from? When I run minetest from bin/Debug, all my keyboard input goes to a terminal instead of the MT window for some reason, so I'm very interested in bundle creation.

I could not get 97723226 to work (semaphore error mesages again), so I've built 122875c30cc2 (with the patch below).

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
git checkout 122875c30cc2
patch -p1 < mt.patch
cmake -G Xcode .
(change architecture in XCode to 64 bit and build)


mt.patch (I tried to post this as an attachment, but the forum software did not allow it.)
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 153e1c1..f171926 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -168,7 +168,6 @@ install(FILES "minetest.conf.example" DESTINATION "${EXAMPLE_CONF_DIR}")
 
 if(UNIX)
    install(FILES "doc/minetest.6" "doc/minetestserver.6" DESTINATION "${MANDIR}/man6")
-   install(FILES "misc/minetest.desktop" DESTINATION "${XDG_APPS_DIR}")
    install(FILES "misc/minetest-icon.svg" DESTINATION "${ICONDIR}/hicolor/scalable/apps")
 endif()
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 90f5867..a0917ca 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -160,7 +160,7 @@ else()
       endif(APPLE)
    endif(BUILD_CLIENT)
    find_package(ZLIB REQUIRED)
-   set(PLATFORM_LIBS -lpthread -lrt ${CMAKE_DL_LIBS})
+   set(PLATFORM_LIBS -lpthread "-framework CoreFoundation" ${CMAKE_DL_LIBS})
    #set(CLIENT_PLATFORM_LIBS -lXxf86vm)
    # This way Xxf86vm is found on OpenBSD too
    find_library(XXF86VM_LIBRARY Xxf86vm)
@@ -170,7 +170,6 @@ endif()
 
 find_package(Sqlite3 REQUIRED)
 find_package(Json REQUIRED)
-find_package(OpenGLES2)
 
 if(USE_FREETYPE)
    find_package(Freetype REQUIRED)
diff --git a/src/porting.h b/src/porting.h
index ea7f31b..e08eea8 100644
--- a/src/porting.h
+++ b/src/porting.h
@@ -188,7 +188,10 @@
 #else // Posix
    #include <sys/time.h>
    #include <time.h>
-   
+#ifdef __MACH__
+#include <mach/clock.h>
+#include <mach/mach.h>
+#endif   
    inline u32 getTimeS()
    {
       struct timeval tv;
@@ -213,7 +216,18 @@
    inline u32 getTimeNs()
    {
       struct timespec ts;
+#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
+        clock_serv_t cclock;
+        mach_timespec_t mts;
+        host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
+        clock_get_time(cclock, &mts);
+        mach_port_deallocate(mach_task_self(), cclock);
+        ts.tv_sec = mts.tv_sec;
+        ts.tv_nsec = mts.tv_nsec;
+       
+#else
       clock_gettime(CLOCK_REALTIME, &ts);
+#endif
       return ts.tv_sec * 1000000000 + ts.tv_nsec;
    }

Re: Mac OS X

PostPosted: Mon Apr 21, 2014 04:34
by OmniStudent
Morn76 wrote:Where did you get that mac folder from? When I run minetest from bin/Debug, all my keyboard input goes to a terminal instead of the MT window for some reason, so I'm very interested in bundle creation.


That is a known problem when running MT from terminal in OSX. I used the mac folder in

https://github.com/toabi/minetest.git

and adapted my minetest/cmakelist file according to toabi's cmakelist.
To get the game working, I then have to manually move files: minetest to applications, and then the folders textures and builtin (and probably more, to get everything working) into the folder /Applications/minetest.app/Contents/Resources/bin/share.

I would post a github on my files, only I lost my latest work while building the git :(

Morn76 wrote:I could not get 97723226 to work (semaphore error mesages again), so I've built 122875c30cc2 (with the patch below).


That's strange, 97723226 is supposed to be before semaphores where added. Are you sure you got the correct commit? Can't find 122875c30cc2 on github but that's just because one can't search for sha numbers there.

Re: Mac OS X

PostPosted: Mon Apr 21, 2014 05:34
by OmniStudent
Morn76 wrote:StackOverflow also links to this monster: http://www.aao.gov.au/local/www/ks/uplo ... imedwait.c , but I don't even know how I would integrate this thing into the existing code. More fiddling with cmake would probably be needed.


That looks promising though, I will have a look at it.

Re: Mac OS X

PostPosted: Mon Apr 21, 2014 09:57
by Morn76
OmniStudent wrote:That's strange, 97723226 is supposed to be before semaphores where added. Are you sure you got the correct commit? Can't find 122875c30cc2 on github but that's just because one can't search for sha numbers there.


Yes, unfortunately OS X's git does not seem to come with gitk. Maybe install the Homebrew git? GitHub is nice but it does not replace the functionality of gitk.

122875c30cc2553a4db41308e597e928c8e6e7ad
Bump version to 0.4.8 by kwolekr (2013-11-24)
This one works for me.

jsemaphore was introduced in
2e66aca35722e7fee786027d545fe371786fc01f
Fix modstore/favourites hang by adding asynchronous lua job support by sapier (2013-11-26)

977232261388fa80bd6ab3bb849ae4d7a8ade73e
Add alpha setting to font shadow by BlockMen (2013-12-12)
This already has the jsemaphore stuff in the tree, so it's no wonder it doesn't work for me.

OmniStudent wrote:
Morn76 wrote:StackOverflow also links to this monster: http://www.aao.gov.au/local/www/ks/uplo ... imedwait.c , but I don't even know how I would integrate this thing into the existing code. More fiddling with cmake would probably be needed.


That looks promising though, I will have a look at it.


It needs "sem_timedwait.h" apparently though, and I can't find that anywhere online.

Basically it should be enough to include mach/semaphore.h instead of semaphore.h and then call semaphore_timedwait() because the Mach kernel on OS X actually has this function. Like it's done here: https://github.com/constcast/vermont/tr ... /osdep/osx Unfortunately I have not been able to do this with the MT code successfully though, I always get lots of compilation errors when I change the include file to mach.

If Sapier could rewrite his MT code so sem_getvalue() and sem_timedwait() were no longer needed, we could use the Apple macros to transform the remaining sem_*() calls and everything should be solved. I don't know if this is possible though.

The devs have really painted themselves into the proverbial corner with all this jsemaphore stuff in MT. IMO Sapier's commit should have been rejected in November as non-portable, but unfortunately nobody seems to have checked portability at the time. So now we are a bit stuck.

Re: Mac OS X

PostPosted: Mon Apr 21, 2014 10:47
by OmniStudent
Morn76 wrote:It needs "sem_timedwait.h" apparently though, and I can't find that anywhere online.


It should be possible to look at the cpp file and write the h file from this. I'm trying to include an arbitrary file in my xcode mt project now, and am writing a small h file for this.

Morn76 wrote:Basically it should be enough to include mach/semaphore.h instead of semaphore.h and then call semaphore_timedwait() because the Mach kernel on OS X actually has this function. Like it's done here: https://github.com/constcast/vermont/tr ... /osdep/osx Unfortunately I have not been able to do this with the MT code successfully though, I always get lots of compilation errors when I change the include file to mach.


Does it help that I have succesfully included these from porting.h line 225 ?
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#else // Posix
   #include <sys/time.h>
   #include <time.h>

#include <mach/mach_time.h>
#include <mach/mach.h>
#include <mach/mach_init.h>
#include <mach/thread_policy.h>
#define CLOCK_REALTIME 0
#define CLOCK_MONOTONIC 0
   
   inline u32 getTimeS()


as part of earlier experimentation.

Morn76 wrote:
If Sapier could rewrite his MT code so sem_getvalue() and sem_timedwait() were no longer needed, we could use the Apple macros to transform the remaining sem_*() calls and everything should be solved. I don't know if this is possible though.

The devs have really painted themselves into the proverbial corner with all this jsemaphore stuff in MT. IMO Sapier's commit should have been rejected in November as non-portable, but unfortunately nobody seems to have checked portability at the time. So now we are a bit stuck.


There hasn't been much interest in osx, so it's been neglected for a long time. Sapier seems pretty thorough though, so maybe he'll fix this code. Or we :)

Re: Mac OS X

PostPosted: Mon Apr 21, 2014 11:02
by Morn76
Yes, I suppose it's possible to construct a .h with just the function definition. Of course there might be other defines and macros in the .h that we don't know about.

My fiddling with mach/semaphore.h in MT's jsemaphore.h looks like this so far:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#if defined(WIN32)
#include <windows.h>
#include <assert.h>
#define MAX_SEMAPHORE_COUNT 1024
#else
#include <mach/semaphore.h>
#include <pthread.h>
//#include <semaphore.h>
#include <mach/mach.h>
#include <mach/task.h>
#undef sem_t
#define sem_t semaphore_t
#undef sem_init
#define sem_init(s,p,c) semaphore_create(mach_task_self(),s,SYNC_POLICY_FIFO,c)
#undef sem_wait
#define sem_wait(s) semaphore_wait(*s)
#undef sem_post
#define sem_post(s) semaphore_signal(*s)
#undef sem_destroy
#define sem_destroy(s) semaphore_destroy(mach_task_self(),*s)
#undef sem_timedwait
#define sem_timedwait(s,t) semaphore_timedwait(*s,t)
#endif


Strangely enough the other Mach calls like semaphore_wait don't need the mach include file, but semaphore_timedwait does.

The main problem is that Sapier apparently does not have a Mac himself, so coming up with a working fix is not that easy for him. Then again, he is the one who broke portability, so he should fix it. :-)

Re: Mac OS X

PostPosted: Mon Apr 21, 2014 11:14
by OmniStudent
Stumbled into this

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
#define sem_init(s, p, v)   fuse_sem_init(s, p, v)
#define sem_destroy(s)      fuse_sem_destroy(s)
#define sem_getvalue(s, v)  fuse_sem_getvalue(s, v)
#define sem_post(s)         fuse_sem_post(s)
#define sem_timedwait(s, t) fuse_sem_timedwait(s, t)
#define sem_trywait(s)      fuse_sem_trywait(s)
#define sem_wait(s)         fuse_sem_wait(s)


in fuse_darwin.h, a file from MacFuse. Perhaps its possible to use this?