Thursday, June 14, 2012

Hacking Waverous changes into Stunt

A few months ago Todd Sundsted, the owner/developer of the Stunt LambdaMOO server code, emailed me inquiring about the effort it took to get LambdaMOO to compile as C++. I ventured it would be interesting to try to apply my changes in Waverous LambdaMOO to a branch of Stunt LambdaMOO. A month or so ago I did fork Stunt on Github and made a local clone. I then looked at the git log of Waverous and chose my first commit that converted some of the files from C to C++. Applying that as a patch to Stunt was about, I'd say, 65% successful: some of the hunks applied, some failed and gave me .rej files.
patching file ast.c
Hunk #9 succeeded at 209 (offset 11 lines).
Hunk #10 succeeded at 220 (offset 11 lines).
Hunk #11 succeeded at 344 (offset 29 lines).
Hunk #12 succeeded at 413 (offset 29 lines).
patching file ast.h
Hunk #1 succeeded at 83 (offset 7 lines).
Hunk #2 succeeded at 112 with fuzz 2 (offset 9 lines).
Hunk #3 succeeded at 190 (offset 11 lines).
patching file db.h
Hunk #1 succeeded at 298 (offset 62 lines).
patching file exceptions.h
Hunk #6 FAILED at 159.
Hunk #7 succeeded at 182 (offset 3 lines).
1 out of 7 hunks FAILED -- saving rejects to file exceptions.h.rej
patching file execute.h
Hunk #1 FAILED at 46.
Hunk #2 FAILED at 94.
2 out of 2 hunks FAILED -- saving rejects to file execute.h.rej
I didn't have oodles of time so I let it slide for a few weeks... my time was being taken up by a Udacity course, running LVDev, campaigning for a political candidate, working on a GreenerBlocks.org project and more! But the itch is there and wants scratching. Tonight I packed my laptop and went over to the Vegas Jelly in /usr/lib above The Beat Coffeehouse. It meets every Thursday night. The Linux, Bitcoin and All Things Open Source group was meeting in the conference room (Hi, Julian!) and I took a seat in the back of the room. I worked while a debate raged about the prospects of Bitcoin but I barely took notice. What I first found was gcc, make and friends were not present on my system anymore. I upgraded my laptop to OS X Lion recently when I participated in an iOS Boot Camp. But I installed XCode; wtf? Googling told me I needed to install the command line tools via Preferences -> Downloads. Completely obvious in retrospect, heh. I renamed configure.in to configure.ac, copied my Waverous version of the file over it and ran autoconf. All good. I ran ./configure:
bash-3.2$ ./configure
checking for bison... bison -y
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
configure: error: cannot find install-sh, install.sh, or shtool in "." "./.." "./../.."
Another wtf moment. I googled around but didn't really find anything specific enough for my situation; maybe upgrading the autotools? I did port update on autoconf and automake; but still the same error. Finally I just copied install-sh from the automake directory; this is scratch hacking after all, and with version control you never have to say you're sorry. (EDIT: Duh, I forgot to run automake --install-missing, was all).
bash-3.2$ ./configure
checking for bison... bison -y
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C++ preprocessor... g++ -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking whether gcc needs -traditional... no
checking how to run the C preprocessor... gcc -g -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for library containing strerror... none required
checking for strftime... yes
checking for gcc -g option to accept ISO C99... unsupported
checking for gcc -g option to accept ISO C89... (cached) none needed
checking for gcc -g option to accept ISO Standard C... (cached) none needed
checking sys/bsdtypes.h usability... no
checking sys/bsdtypes.h presence... no
checking for sys/bsdtypes.h... no
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking for memory.h... (cached) yes
checking for pid_t... yes
checking for mode_t... yes
checking for size_t... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for struct tm.tm_zone... yes
./configure: line 4810: syntax error near unexpected token `sqrt,'
./configure: line 4810: `MOO_HAVE_FUNC_LIBS(sqrt, -lm /lib/libm.a "-static -lm")'
OK, more wtf material... I called it an evening, had a nice discussion with a couple of the Linux guys about LambdaMOO and the problems of getting the masses to use new software, and headed home.

Back in my home office I googled the error a bit, editing out the particulars of the error message to make the search query more generic; somewhere I found one forum post where the reply was "Your aclocal got borked." Ah! Did I not move some of the MOO m4 macros to another file to reduce the size/complexity of configure.ac?

Indeed I did, and I left a helpful log entry in git to that effect.

So I copied acinclude.m4 over from the Waverous project, ran aclocal, ran autoconf and finally ./configure and everything went well. I now have a Makefile that will correctly call g++ for the project. Time to commit my work, push it to github and sleep on it a bit.

What comes next, should I undertake it, is a lot of bare knuckle hacking to resolve conflicts between Waverous's code base and Stunt's. Todd has made a lot of edits to the C sources, I'm sure, and I started from the most recent version of LambdaMOO on Sourceforge. It means I'll have to come to understand a lot of the changes Todd made, and that will be challenging.

1 comment:

  1. Thanks for hacking on this! It was your posting about Waverous on MOO Talk that motivated me to package up a bunch of hacking I did into a coherent set of extensions to LambdaMOO.

    Todd

    ReplyDelete