Mac OS X

haschatan
New member
Posts: 8
Joined: Thu Apr 10, 2014 18:50

Mac OS X

by haschatan » Post

Hi!

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

User avatar
Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27

by Topywo » Post

There's not much about the Mac.

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

viewtopic.php?id=8532

haschatan
New member
Posts: 8
Joined: Thu Apr 10, 2014 18:50

by haschatan » Post

Ok. I do not understand why nobody want to compile Minetest on Mac OS. What a shame.

User avatar
Topywo
Member
Posts: 1721
Joined: Fri May 18, 2012 20:27

by Topywo » Post

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.

flake
Member
Posts: 13
Joined: Fri Jan 24, 2014 08:25

by flake » Post

I have minetest running in wine on OSX.

homebrew install, doctor, update,
brew install wine

wine /minetest/bin/minetest.exe

and go.....

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

by Morn76 » Post

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.
Sorry, OP, I really wanted to contribute a working OS X build here, but apparently it's not going to happen. :-(

Image
Last edited by Morn76 on Fri Apr 18, 2014 18:18, edited 1 time in total.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

by Morn76 » Post

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.
Last edited by Morn76 on Sat Apr 19, 2014 08:30, edited 1 time in total.

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

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

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

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

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

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

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

Morn76 wrote:
How did you set the architecture in Xcode, OmniStudent?
Change Architectures to "standard architectures".

Image

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

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 :(

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

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.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

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.

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

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

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

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.
Last edited by Morn76 on Sun Apr 20, 2014 17:04, edited 1 time in total.

User avatar
Inocudom
Member
Posts: 3121
Joined: Sat Sep 29, 2012 01:14
IRC: Inocudom
In-game: Inocudom

Re: Mac OS X

by Inocudom » Post

Eventually, a way will have to be found to allow for the compiling of development builds.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

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.

User avatar
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

by hoodedice » Post

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.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

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.

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

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 :(

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

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.

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

Cool that it at least gets somewhere, but the wait function probably only increments 0, returned from sem_getvalue()

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

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.

Morn76
Member
Posts: 659
Joined: Sun Feb 16, 2014 19:45

Re: Mac OS X

by Morn76 » Post

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).

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.)

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.

OmniStudent
Member
Posts: 261
Joined: Sat Nov 03, 2012 06:40

Re: Mac OS X

by OmniStudent » Post

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests