Mac OS X
There's not much about the Mac.
Some old info about even older info is in posts 16 and 18.
viewtopic.php?id=8532
Some old info about even older info is in posts 16 and 18.
viewtopic.php?id=8532
I guess there are not that many Mac users that like to play minetest and are able to compile it on the Mac OS.haschatan wrote:Ok. I do not understand why nobody want to compile Minetest on Mac OS. What a shame.
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.
I can't even get Minetest to build without errors on OS X Mavericks:

- clock_gettime() works differently in OS X if you want to get the time in nanoseconds (in porting.h). Thankfully StackExchange has a workaround for this: http://stackoverflow.com/questions/5167 ... n-mac-os-x
- sem_timedwait() does not exist under OS X (in jsemaphore.cpp); SE again has several workarounds: http://stackoverflow.com/questions/6411 ... lternative I've just replaced it with sem_wait and hoped for the best.
- But there is some error with OSHostByteOrder() that occurs inside the Apple frameworks (see screenshot), so now I'm completely lost.

Last edited by Morn76 on Fri Apr 18, 2014 18:18, edited 1 time in total.
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.
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.
Last edited by Morn76 on Sat Apr 19, 2014 08:30, edited 1 time in total.
-
- Member
- Posts: 261
- Joined: Sat Nov 03, 2012 06:40
Re: Mac OS X
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
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
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
Code: Select all
Assertion failed: (sem_init_retval == 0), function JSemaphore, file /Users/me/minetest/minetest/src/jthread/pthread/jsemaphore.cpp, line 28.
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
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.
"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
But back to our current progress.
How did you set the architecture in Xcode, OmniStudent?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 :)
Found this:OmniStudent wrote: But at startup the program crashed due to
it was sem_init() in jsemaphore.cpp. Apparently this is not properly implemented on osx and returns -1Code: Select all
Assertion failed: (sem_init_retval == 0), function JSemaphore, file /Users/me/minetest/minetest/src/jthread/pthread/jsemaphore.cpp, line 28.
"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
-
- Member
- Posts: 261
- Joined: Sat Nov 03, 2012 06:40
Re: Mac OS X
Change Architectures to "standard architectures".Morn76 wrote:
How did you set the architecture in Xcode, OmniStudent?

-
- Member
- Posts: 261
- Joined: Sat Nov 03, 2012 06:40
Re: Mac OS X
Tried to rewrite using sem_open this morning, but it was over my head :(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
Re: Mac OS X
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.
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
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.
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.
-
- Member
- Posts: 261
- Joined: Sat Nov 03, 2012 06:40
Re: Mac OS X
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"

sha: 977232261388fa80bd6ab3bb849ae4d7a8ade73e
which is just before jsemaphores were introduced.
The packaging script is still screwed up but at least this is "proof of concept"

Re: Mac OS X
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.
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.
Last edited by Morn76 on Sun Apr 20, 2014 17:04, edited 1 time in total.
Re: Mac OS X
Eventually, a way will have to be found to allow for the compiling of development builds.
Re: Mac OS X
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.
- hoodedice
- Member
- Posts: 1374
- Joined: Sat Jul 06, 2013 06:33
- GitHub: hoodedice
- IRC: hoodedice
- In-game: hoodedice
- Location: world
- Contact:
Re: Mac OS X
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
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.
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.
-
- Member
- Posts: 261
- Joined: Sat Nov 03, 2012 06:40
Re: Mac OS X
]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
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.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 :(
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.
-
- Member
- Posts: 261
- Joined: Sat Nov 03, 2012 06:40
Re: Mac OS X
Cool that it at least gets somewhere, but the wait function probably only increments 0, returned from sem_getvalue()
Re: Mac OS X
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.
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
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.OmniStudent wrote: Managed to build the "package" target too by putting an old "mac" folder inside the "misc" folder in minetest.
I could not get 97723226 to work (semaphore error mesages again), so I've built 122875c30cc2 (with the patch below).
Code: Select all
git checkout 122875c30cc2
patch -p1 < mt.patch
cmake -G Xcode .
(change architecture in XCode to 64 bit and build)
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;
}
Last edited by Morn76 on Sat Apr 26, 2014 22:31, edited 2 times in total.
-
- Member
- Posts: 261
- Joined: Sat Nov 03, 2012 06:40
Re: Mac OS X
That is a known problem when running MT from terminal in OSX. I used the mac folder inMorn76 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.
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 :(
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.Morn76 wrote: I could not get 97723226 to work (semaphore error mesages again), so I've built 122875c30cc2 (with the patch below).