Compiling TGrep2 on an Intel Macintosh
When TGrep2 (Ed: a search tool for syntactic corpora in Penn Treebank format) was originally written, all Macs were PPC, but since late 2006 all Macs have been x86 and newer ones are even x86_64. In order to compile tgrep2 on an Intel Mac you have to make some small modifications to the TGrep2 and DRUtils source directories before you compile. This fix at least works on MacOS X 10.5 and 10.6. (Apologies for WordPress mangling the <code> blocks.)
First the patch for DRUtils:
--- DRUtils/Makefile 2004-01-13 12:26:49.000000000 -0500
+++ DRUtils.mac/Makefile 2007-11-15 14:32:15.000000000 -0500
@@ -1,6 +1,7 @@
-CC = gcc -Wall -O4 -march=i486
-FLAGS = -DMACHINE_LINUX
+CC = gcc -Wall -O2 -fPIC -march=i486
+FLAGS = -DMACHINE_MACINTOSH
DEBUG =
+HOSTTYPE = macintosh
# Windows:
ifeq ($(HOSTTYPE),i686)
@@ -9,7 +10,7 @@ endif
# Macintosh:
ifeq ($(HOSTTYPE),macintosh)
MAKE = make
- CC = cc -pipe -O3 -Wall -fno-common -arch ppc
+ CC = gcc -pipe -O2 -Wall -fPIC -arch i386 -arch x86_64
FLAGS = -DMACHINE_MACINTOSH
endif
# Alpha:
diff -uprN DRUtils/system.h DRUtils.mac/system.h
--- DRUtils/system.h 2004-01-13 12:31:19.000000000 -0500
+++ DRUtils.mac/system.h 2007-11-15 14:36:57.000000000 -0500
@@ -65,9 +65,9 @@ typedef unsigned int flag; /* a boolean.
#ifdef MACHINE_MACINTOSH
# include
# include
-# define NO_DRAND48
-# ifdef LITTLE_END
-# undef LITTLE_END
+/* # define NO_DRAND48 */
+# ifndef LITTLE_END
+# define LITTLE_END
# endif /* LITTLE_END */
#endif /* MACHINE_MACINTOSH */
@@ -153,10 +153,12 @@ because there is a bug in the xlc optimi
#ifdef LITTLE_END
# define NaNfbytes {{ 0, 0, 0xc0, 0x7f }}
# define NaNdbytes {{ 0, 0, 0, 0, 0, 0, 0xf8, 0xff }}
+/*
# define NTOHL(x) ntohl(x)
# define HTONL(x) htonl(x)
# define NTOHS(x) ntohs(x)
# define HTONS(x) htons(x)
+*/
#else
# define NTOHL(x) (x)
# define HTONL(x) (x)
And here’s the patch for TGrep2 itself:
--- TGrep2/Makefile 2009-03-18 16:30:35.000000000 -0400
+++ TGrep2.mac/Makefile 2007-11-15 14:44:41.000000000 -0500
@@ -2,7 +2,7 @@
UTIL_DIR= ${HOME}/DRUtils
UTIL_LIB= ${UTIL_DIR}/${HOSTTYPE}/libdrutils.a
-CC= gcc -O4 -Wall
+CC= gcc -O2 -Wall -DLITTLE_END -arch i386 -arch x86_64
#CC= gcc -g -Wall
tgrep2: tgrep2.c Makefile
Copy the first block and paste it into a text file with the name “drutils.patch” and copy the second block and paste it into a file with the name “tgrep2.patch”. TGrep2 expects the DRUtils directory to be in the base of your home directory (~/DRUtils/
), so it’s best to untar them both in your home directory. Assuming you do put the source directories there, at a Terminal type the following:
patch -p0 < drutils.patch
patch -p0 < tgrep2.patch
Assuming the patches succeed, you can then run make
in the DRUtils directory and then (assuming DRUtils successfully built) in the TGrep2 directory. I recommend then copying the tgrep2
binary to /usr/local/bin
.
April 9, 2011 at 2:13 pm
So I decompressed/unzipped the two downloads for tgrep2–drutils.tgz and tgrep2.tgz–in my home directory then created the above patch files and ran the first command:
$ patch -p0 < drutils.patch
and got this error:
patching file DRUtils/Makefile
patch: **** malformed patch at line 8: DEBUG =
I'm not a programmer so I just commented that out and tried again to get this result:
patching file DRUtils/Makefile
patch: **** malformed patch at line 11: ifeq ($(HOSTTYPE),i686)
Also, should I have these patch files in my home directory?
Thanks
LikeLike
April 20, 2011 at 10:23 am
Yes, the patch files should be in your home directory, not within the directories for the untar’d TGrep2 and DRUtils.
So in your home directory you should have:
drutils.patch
trgrep2.patch
DRUtils/
TGrep2/
Lines 8 and 11 of the DRUtils patch are context lines, which show an existing line in DRUtils/Makefile that the new stuff is going to be inserted around. I’m not sure how you tried commenting it out. I’m actually pretty sure that’s not even possible in a diff/patch file.
My guess is that something is getting mangled in the copying and pasting into or out of WordPress. I’ve cleanly applied the patch files that I pasted from on several different computers, so I know that they do work. Does the TGrep2 patch work for you? It’s smaller and less likely for something to go wrong.
LikeLike
July 22, 2011 at 12:46 pm
I have the same issue.
$ patch -p0 < drutils.patch
missing header for unified diff at line 1 of patch
can't find file to patch at input line 1
Perhaps you used the wrong -p or –strip option?
File to patch: DRUtils/Makefile
patching file DRUtils/Makefile
patch: **** malformed patch at line 6: DEBUG =
LikeLike
December 9, 2011 at 6:22 pm
For the record, I also got errors:
$ patch -p0 < drutils.patch
patching file DRUtils/Makefile
missing header for unified diff at line 13 of patch
can't find file to patch at input line 13
Perhaps you used the wrong -p or –strip option?
The text leading up to this was:
————————–
|DEBUG =
|+HOSTTYPE = macintosh
|
|# Windows:
|ifeq ($(HOSTTYPE),i686)
————————–
File to patch: DRUtils/Makefile
patching file DRUtils/Makefile
patch: **** malformed patch at line 13: — 11,10 —-
and
$ patch -p0 < tgrep2.patch
patching file TGrep2/Makefile
patch: **** malformed patch at line 3: — 3,2 —-
However, I did get TGrep2 installed, following the instructions here: http://blogs.umass.edu/xlum/2011/08/28/tgrep2/
LikeLike
December 9, 2011 at 6:31 pm
Hey Laurel, thanks for posting the link to the UMass Experimental Linguistics group. I am glad you found a way to get TGrep2 to work. This will be helpful for others, too.
Florian
LikeLike