Cannot compile Google RE2 on Solaris

bejhan
bejhan used Ask the Experts™
on
I want to use Google's regular expression library, RE2 (http://code.google.com/p/re2/). But I can't get it to compile on Solaris. However, I have got it to compile on a generic linux (which has an older GCC) so I'm not sure what the problem is.

On the installation instructions (http://code.google.com/p/re2/wiki/Install) it says to use gmake which spits out some random error:
/bin/sh: syntax error at line 1: `(' unexpected
gmake: *** [obj/dbg/util/arena.o] Error 2

Open in new window


I have tried regular make, but it doesn't like the Makefile.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
it looks more a compiler and environment issue rather than other.

i would install newest gcc for solaris and sunstudio. the latter should allow you to create a makefile that is compatible to the environment which unfortunately is different than to that of most standard linux.

Sara

Author

Commented:
I don't have privilege to install another gcc. The gcc on the solaris box is newer than on the generic linux box (which I successfully built RE2 on). So the gcc version I have should be sufficient should it?

Is there anyway to get gmake to output some useful messages rather than that garbage so I can actually see what the problem is?
Top Expert 2016

Commented:
i doubt that gmake is the right command. unfortunately most environments of solaris i worked with had special home-made tools and i wasn't responsible for them. can you spot the gcc and try to use gcc directly not using a makefile? only to check if you have the right environment. if that works you may look for a makefile (any) named GNUMakefile (don't know exactly if i have the correct case so do a case-independent search on the file). if you find some you could step into the folder and try make. if that compiles you should be able to find out from that makefile how to adopt yours.

Sara

Author

Commented:
The Makefile is actually using g++, but I don't think I could use g++ directly because the Makefile is very complex with dependencies, etc.

Maybe we could get the Makefile to work with the regular make command (rather than gmake).

First make complains of an unexpected end of line on line 41:

40: ifeq ($(shell uname),Darwin)
41: MAKE_SHARED_LIBRARY=g++ -dynamiclib $(LDFLAGS) -exported_symbols_list libre2.symbols.darwin
42: else
43: MAKE_SHARED_LIBRARY=g++ -shared -Wl,-soname,libre2.so.0,--version-script=libre2.symbols $(LDFLAGS)
45: endif

Open in new window


Since I know we are using zsh not Darwin, I commented out lines 40, 41, 42, 45.

Now make complains of an unexpected end of line on line 207. Line 207 is just blank so I am confused.
Makefile
Top Expert 2016

Commented:
check the makefile with vi. it will show the end-of-line characters. you may have only linefeed 0x0a but not 0x0a0d.

i think it is not an error but only warning. does it compile with make?

Sara

Author

Commented:
It does not compile with make, this is a fatal error:
make: Fatal error in reader: Makefile, line 207: Unexpected end of line seen

Open in new window


Line 207 has a new line following the format of the newline on every other line.
I see no real difference with the target on lines 200-203 and the target on lines 204-207.

This error is really strange...
error-area.PNG

Author

Commented:
I think I should be using gmake, because this is GNU Make (where as my make command is some custom make that does not like this makefile).

I found an article (http://blog.leecarmichael.com/2009/02/weird-makegmake-error.html) which describes similar behaviour to my original gmake error
/bin/sh: syntax error at line 1: `(' unexpected
gmake: *** [obj/dbg/util/arena.o] Error 2

Open in new window


In the article he explains that the bash shell must be used with gmake so that certain features can be used.
However, my gmake is executing under sh instead of bash.

I have tried entering a bash shell (by typing bash), but gmake still uses sh.
I have tried aliasing sh to bash, same result.
I have tried adding #!/bin/sh to the top of the make file, same result.

Author

Commented:
After more investigation, I don't think it has to with the shell.

I used truss to investigate the actual commands being executed.
Prior to spitting out the error the following is executed:
16067:   argv: /bin/sh -c mkdir -p $(dirname obj/util/arena.o)

Open in new window


This seems incorrect because $(dirname obj/util/arena.o) should actually resolve to obj/util.

I think this is an aliasing problem (i.e. dirname is not an actual gmake function, the dir function seems to have the intended behavior though).
Commented:
Okay it seems I was half right on both counts.

I found that you can execute under bash script using:
SHELL=/bin/bash
export SHELL

Open in new window


Since GNU make does not take the SHELLvariable from the user's environment.

And it seems that bash has dirname function aliased or something like that because now compilation gets passed this error! However, I am getting some more errors. I will post in a few minutes.
Commented:
Replaced all "-pthread" options with "-pthreads" because it is different on Solaris.

Removed the "--version-script=libre2.symbols" option because this is not supported on Solaris.

Changed the "-soname" option to "-h" because it is different on Solaris.

Author

Commented:
Found own solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial