Author Topic: Compiling Mac WeiDU on Intel Macs  (Read 4813 times)

Offline GammaLeak

  • Planewalker
  • *****
  • Posts: 23
Compiling Mac WeiDU on Intel Macs
« on: March 01, 2012, 10:04:48 PM »
EDIT: See below the break for the original post. What follows is now instructions for how to get WeiDU to compile properly on an Intel Mac running OS X 10.6. If you are running OS X 10.5, 10.7, or 10.8 these instructions may or may not require some modifications.

Requirements:
a) Intel Mac running OS X 10.6 (10.5, 10.7, and 10.8 may also work with these instructions, but no guarantees)
b) Xcode 3.2 (or the appropriate Xcode for your version of OS X)
c) Working knowledge of how to use the Terminal applications
d) MacPorts installed and a working knowledge of how to use it
e) Working knowledge of how to use make and makefiles

Instructions:
  • Install ocaml via MacPorts. You're going to need the labltk variant so use this command: sudo port install ocaml +labltk
  • Take note of the directory that MacPorts installs ocaml to. For a normal MacPorts install this should be /opt/local/bin, /opt/local/lib/ocaml, and /opt/local/lib/ocaml/camlp4
  • Use Terminal to navigate to /opt/local/lib/ocaml. Then type in this command: sudo ln /usr/local/lib/ocaml/libcamlstr.a /usr/local/lib/ocaml/libstr.a
  • Download and extract the copy of elkhound that the_bigg links to on the compile page (http://www.weidu.org/~thebigg/compile.html), i.e., this one: http://www.weidu.org/~thebigg/elkhound-2009.01.26.tar.gz
  • Navigate to the extracted elkhound folder and run ./configure

At this point you'll end up going down one of two paths. If you're running a 32-bit system. You should be able to just run make and everything will compile just fine. However, if you're running a 64-bit system (which is very likely... I'm not sure Apple has sold a 32-bit system for a long time) you're going to have to convert a number of (int) casts of void* types into (intptr_t) casts. That's because the int type is only 32 bits, but on a 64-bit system void* is going to be 64 bits. The pointers get chopped in half with the code as it is. However, intptr_t is guaranteed to be large enough (64 bits), so you'll have to change a number of those. I will proceed to list them for you here...

Instances where an (int) cast of void* (or sometimes other pointer types) must be changed to (intptr_t) (all folders assumed to originate from the elkhound root folder - note that one of the subfolders in the elkhound root is called elkhound itself):
  • smbase/mysig.cc, line 80
  • elkhound/c/c_type.h, line 49
  • elkhound/c/c_type.h, line 238
  • elkhound/c/c.ast, line 253
  • elkhound/c/c_type.cc, line 229

Now that that is done...
  • Run make in the elkhound root. At this point it should build without a problem.
  • Copy the resulting elkhound executable to /usr/local/bin so that the weidu build can use it.
  • Navigate to the WeiDU source code folder. Open the Configuration file.
  • Uncomment section (2) and change the paths from beginning with /usr to beginning with /opt. Do the same down in the "autodetection" section
  • If everything else was done correctly, this should build successfully and the obj folder will have a Mac executable called weidu.asm.exe

So that's how to build WeiDU on the Mac. It's not exactly a one-click solution, but it gets the job done. Since the first instruction had you install the labltk variant of ocaml you should be able to build everything except weimorph, which seems to be sort of in the "not so supported" category (see the bigg's comment below).


ORIGINAL POST:

OK... from the pinned "How to compile" thread it's clear that devSin is still compiling WeiDU for Mac on a PowerPC machine. Very cool! Especially for those still running the original Mac version of the BG games.

On the other hand... most modern Mac players of the game are going to be using the PC version via Wine.

That's where I step in. I'm willing to help or even take ownership of the issue of getting WeiDU to compile on Intel Macs. But I'm going to need some help. I'm a total newbie to OCaml and I'm not exactly a makefile wizard either.

So I'm going to use this thread for asking questions to get this all figured out if possible. If anyone from the community is able to give me clues, tips, pointers, help, etc. I would sincerely appreciate it.

Thanks!
« Last Edit: March 09, 2012, 05:40:09 PM by GammaLeak »

Offline GammaLeak

  • Planewalker
  • *****
  • Posts: 23
Re: Compiling Mac WeiDU on Intel Macs
« Reply #1 on: March 03, 2012, 08:45:25 AM »
Well that wasn't so bad.

I got it figured out. Even using the very latest version of ocaml.

Here's a high-level description of what I had to do. Later I might post more details.
  • Installed ocaml via Macports
  • Changed the OS X section of the "Configuration" file for WeiDU's makefile to point to ocaml at /opt/local/bin, /opt/local/lib/ocaml, and /opt/local/lib/ocaml/camlp4  -- note that Macports installs bins, libs, etc to /opt and not /usr
  • Downloaded the_bigg's link to elkhound-2009.01.26, extracted it and ran ./configure
  • A series of make attempts on elkhound kept producing "cast from void* to int loses precision" errors in various elkhound files. Per some suggestions on the internet, I changed the (int) casts to (intptr_t). The build throws a warning over this, but no longer errors out.
  • Created a link in the ocaml directory so that libstr.a refers to libcamlstr.a (this file name appears to have changed since ocaml 3.10?) - the command was sudo ln /opt/local/lib/ocaml/libcamlstr.a /opt/local/lib/ocaml/libstr.a

After all of that it finally compiled. The resulting executable comes out as "weidu.asm.exe". Although it's a thoroughly "un-Mac" kind of filename, it runs. I haven't tried using it to actually apply a mod yet, so that is still to be seen. But at least I can produce an executable that runs.

Offline GammaLeak

  • Planewalker
  • *****
  • Posts: 23
Re: Compiling Mac WeiDU on Intel Macs
« Reply #2 on: March 03, 2012, 09:20:58 AM »
One caveat: weigui and weimorph won't build. However, I've got currently got the HEAD checkin from github, so just possibly that's a result of current tinkering in the code.

Offline GammaLeak

  • Planewalker
  • *****
  • Posts: 23
Re: Compiling Mac WeiDU on Intel Macs
« Reply #3 on: March 03, 2012, 06:16:01 PM »
Another quick update: I used my locally compiled WeiDU to run the_bigg's generalized biffing mod and it worked like a charm. So, to a certain extent at least, it works.

Now to think about some ways to deal with the biff_path_separator bug...

Offline Turambar90

  • Planewalker
  • *****
  • Posts: 32
  • Gender: Male
Re: Compiling Mac WeiDU on Intel Macs
« Reply #4 on: March 04, 2012, 02:59:36 AM »
Some questions, which could be useful for mods such as BGT, DSotSC and similar...
- What is the WEIDU_ARCH variable set to, if you use your version of weidu? try using a tp2 containing PRINT ~%WEIDU_ARCH%~
What does it indicate when weidu for ppc (if I've understood correctly, that's what dev_sin's executable is) is running on an intel computer?
- Did you manage to compile tisunpack (which is usually packed together with WeiDU)? I guess that is also usually compiled for PPC. Other binaries which are used in various mods: mosunpack (by wisp), tis2bg2, and sox (for audio conversion; I guess there is a PPC and an Intel version of it somewhere...)
FWIK, all macs up to Snow Leopard can run PPC executables, and all macs from Lion are 64bit, so there should be no need for x86 binaries?

Since some mods need extra binaries, using WEIDU_ARCH could be useful to use the correct binary for mac; we must be careful, though, that 64 bit binaries don't run on 32bit, but the opposite does work (just a bit less efficiently), and I don't think WEIDU_ARCH detects 64bit. It could be necessary to compile in 32 bit for that reason.

Offline GammaLeak

  • Planewalker
  • *****
  • Posts: 23
Re: Compiling Mac WeiDU on Intel Macs
« Reply #5 on: March 05, 2012, 05:40:31 AM »
Some questions, which could be useful for mods such as BGT, DSotSC and similar...
- What is the WEIDU_ARCH variable set to, if you use your version of weidu? try using a tp2 containing PRINT ~%WEIDU_ARCH%~
What does it indicate when weidu for ppc (if I've understood correctly, that's what dev_sin's executable is) is running on an intel computer?
- Did you manage to compile tisunpack (which is usually packed together with WeiDU)? I guess that is also usually compiled for PPC. Other binaries which are used in various mods: mosunpack (by wisp), tis2bg2, and sox (for audio conversion; I guess there is a PPC and an Intel version of it somewhere...)
FWIK, all macs up to Snow Leopard can run PPC executables, and all macs from Lion are 64bit, so there should be no need for x86 binaries?

Since some mods need extra binaries, using WEIDU_ARCH could be useful to use the correct binary for mac; we must be careful, though, that 64 bit binaries don't run on 32bit, but the opposite does work (just a bit less efficiently), and I don't think WEIDU_ARCH detects 64bit. It could be necessary to compile in 32 bit for that reason.

I changed the generalized biffing mod to print out WEIDU_OS and WEIDU_ARCH. Then I used both the PPC and the Intel executable.
  • The results were the same for both the PPC executable and the Intel executable
  • WEIDU_OS = "osx"
  • WEIDU_ARCH = "mac"

The WeiDU source code download doesn't appear to have source for tisunpack, mospack/mosunpack, etc. It would be great if there were a place that could host the source for all of that stuff along with WeiDU all in one place.

Regarding 32bit binaries... yes it can be done. In fact, that's probably a better and more elegant solution, although it involves editing a larger number of files. Basically, all the makefiles need to have '-m32' added to their invocation of gcc/g++. It's easy when the makefile declares gcc/g++ as a "variable" up at the top... just add -m32 to the end of it. But some of the elkhound makefiles are sloppy and invoke g++ directly instead of using a variable.

I'll update the instructions later with regard to making everything compile in 32bit.
« Last Edit: March 05, 2012, 05:47:33 AM by GammaLeak »

Offline the bigg

  • The Avatar of Fighter / Thieves
  • Moderator
  • Planewalker
  • *****
  • Posts: 3804
  • Gender: Male
Re: Compiling Mac WeiDU on Intel Macs
« Reply #6 on: March 05, 2012, 03:25:50 PM »
To answer points in a random order:

To compile weigui you need the ocaml/tk bindings (no idea what is it called like on Mac Ports, on Ubuntu it's liblabltk and liblabltk-dev), as well as whatever version of tcl/tk that is compiled against.
I haven't attempted to compile WeiMorph since.. well, never; it's the basis for Tutu and Icewind Gate 2, but you should use the source for those specific mods instead.
For tisunpack, mosunpack etc. you should google around, there are some threads with the zip.
Elkhound is an external tool that is run once during compilation but is not included in any form in the final binary, so you don't need the 32 bit version.
For the biff_path_separator thing, the optimal solution would be to detect it from the .ini rather than statically.

I'm still lurking (what with going in production at work next week and ME3 coming out), but I thought I should help a fellow developer!
Author or Co-Author: WeiDU (http://j.mp/bLtjOn) - Widescreen (http://j.mp/aKAiqG) - Generalized Biffing (http://j.mp/aVgw3U) - Refinements (http://j.mp/bLHoCc) - TB#Tweaks (http://j.mp/ba02Eg) - IWD2Tweaks (http://j.mp/98OFYY) - TB#Characters (http://j.mp/ak8J55) - Traify Tool (http://j.mp/g1Ry9A) - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics (http://j.mp/9UeIwB) - Nalia Mod (http://j.mp/dng9l0) - Nvidia Fix (http://j.mp/aRWjjg)
Code dumps: Detect custom secondary types (http://j.mp/hVzzXG) - Stutter Investigator (http://j.mp/gdtBn8)

If possible, send diffs, translations and other contributions using Git (http://j.mp/aBZFrq).

Offline GammaLeak

  • Planewalker
  • *****
  • Posts: 23
Re: Compiling Mac WeiDU on Intel Macs
« Reply #7 on: March 05, 2012, 07:06:08 PM »
Thanks so much for the tips! I really appreciate it! I may not be able to make too many changes during the week... schoolwork takes precedence... but I'm itching for the next weekend already so I can dig into this stuff again.

Offline GammaLeak

  • Planewalker
  • *****
  • Posts: 23
Re: Compiling Mac WeiDU on Intel Macs
« Reply #8 on: March 09, 2012, 05:25:09 PM »
OK, I played around a bit with the idea of compiling everything as 32-bit binaries but I've sort of hit a wall. It appears that the Macports version of ocaml is only x86_64. If I try to tell it to download and build the i386 version all I get is x86_64 binaries. At least, that's the case on Snow Leopard. Maybe on Leopard or Tiger it would work... I don't know.

It also appears that ocaml doesn't have any flags to tell it to compile a 32-bit binary?

So the upshot is that even though I can make a 32-bit elkhound at the end of the day I can't make a 32-bit WeiDU.

However, keeping in mind that there aren't any Macs being released anymore that are 32-bit only, I don't think I need to worry if I release 64-bit only binaries. devSin's builds will run via Rosetta for anyone who needs 32-bit binaries and for anyone that has OS X 10.7 or 10.8 (which don't support Rosetta) they explicitly have a 64-bit machine and could run my bins. It stinks to have more than one version, though. If somebody can get me unstuck with regard to making ocaml compile 32 bit binaries I'd be happy to go back and make that happen.

I also realized during the week though that in order to do a full BGT (or other mods) on an Intel Mac without depending on Rosetta I'm going to have to build all the other tools (at least the most common ones). So... mospack/unpack, tispack/unpack, tis2bg2, etc. I already tried a little to compile tis2bg2 and that's going to be a bear. Ugh.

And just for posterity, if one were determined to compile everything 32-bit, here are the instructions for elkhound anyway: http://www.filedropper.com/elkhound-32bit-compile
« Last Edit: March 09, 2012, 05:34:51 PM by GammaLeak »

Offline GammaLeak

  • Planewalker
  • *****
  • Posts: 23
Re: Compiling Mac WeiDU on Intel Macs
« Reply #9 on: March 09, 2012, 05:41:27 PM »
I modified the instructions above to include the labltk variant of ocaml so that weigui and weinstall will compile. Yay!

Offline Turambar90

  • Planewalker
  • *****
  • Posts: 32
  • Gender: Male
Re: Compiling Mac WeiDU on Intel Macs
« Reply #10 on: March 10, 2012, 02:46:02 AM »
I also realized during the week though that in order to do a full BGT (or other mods) on an Intel Mac without depending on Rosetta I'm going to have to build all the other tools (at least the most common ones). So... mospack/unpack, tispack/unpack, tis2bg2, etc. I already tried a little to compile tis2bg2 and that's going to be a bear. Ugh.
I think this will require the WEIDU_ARCH variable to be revisited (by adding an x64 possible result and using that for both GammaLeak's version and an eventual Linux 64 bit version), otherwise it will become more difficult to use the correct external tools; this could also be useful for this report of 64 bit only Linux.

Offline GammaLeak

  • Planewalker
  • *****
  • Posts: 23
Re: Compiling Mac WeiDU on Intel Macs
« Reply #11 on: March 10, 2012, 10:49:57 AM »
I think I was wrong last night that there's only a 64-bit version of ocaml for Macports. However, here's the annoying part, Macports requires you to ONLY use ALL 64-bit or ALL 32-bit binaries with its system. So if you want to switch to one kind or the other you have to uninstall everything, edit the .conf file, and then reinstall what you want again. That's why it was ignoring me telling it to install a 32-bit ocaml.

That's a major pain in the rear and, frankly, unless there's a really good reason I don't think I'm willing to uninstall all my Macports apps and reinstall them as 32-bit. I hope that doesn't seem too selfish.  :-[

So, yeah, regarding the architecture thing... I suppose that could be changed. But I'll leave that one up to the bigg. I don't think that's my call.  :)

 

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Name: Email:
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image
Type the letters shown in the picture:
What color is grass?:
What is the seventh word in this sentence?:
What is five minus two (use the full word)?: