RS6000 compile notes (long)

Agustin Lobo suggested that I post my notes on changes I had
to make to the GRASS 4.1 code to get it to compile on the
RS6000. So, here are the notes.

By the way, has anyone gotten the s.db.rim and v.db.rim
to compile on an RS6000?

---------------------------------
Here is a description of how I got GRASS 4.1 to compile on
an RS/6000 model 320, with AIX 3.2.2. I compiled the standard
GRASS things, Xgrass, and a couple specific device drivers for
painting, digitizing, etc.

Most of the problems had to do with things in standard header
files being redefined, redeclared, or sometimes changed.
The corrections usually involved removing the appropriate
redefinition line. I infer from some of the source code that
malloc(), calloc(), realloc(), and free() used to be defined
in malloc.h, but are now being explicitly defined in the GRASS
source, either in the *.c files or by calling src/include/std-incs.h.
On the RS6000 they are also defined in stdio.h and stdlib.h,
which is why the redefinition errors occur.

NOTE: I have not extensively tested the results; all I can say
is that the compile worked, and our initial few days use of the
system haven't revealed any obvious errors.

1. The setup procedure pretty much involved using the default
   and suggested options, as I recall. The head/RS6000 file
   is appended at the end of this document. Note that specific
   data directories and default region names will differ on
   other systems.

2. The compile failed at the following places, and I made the
   noted corrections:

   a) general/g.help: menu.c
      menu.c - printf redeclared relative to stdio.h
             - malloc and realloc redeclared relative to stdlib.h
      Solution:
               edit main.c
                    line 70 : remove definition of *malloc()
                    line 261 : remove definition of *malloc()
                    line 415 : remove definition of *malloc()
                    line 651 : remove definition of *malloc()

   b) raster/r.mapcalc/polish/y.tab.c, lex.yy.c, pol.y
      - printf, malloc, realloc redeclared.
        Because the above .c files are created by yacc and
        lex, editing the .c files isn't adequate.
      Solution:
               1. run until error, so that lex and yacc create
                  lex.yy.c and y.tab.c
               2. edit Gmakefile
               3. copy stdio.h and stdlib.h here, from /usr/include
               4. edit lex.yy.c and y.tab.c so that #include <stdio.h>
                  becomes #include "stdio.h", and #include <stdlib.h>
                  becomes #include "stdlib.h".

   c) src.alpha/sites/s.surf.tps
      - main.c, lines 10 - 13 : calloc, free, malloc, realloc redefined
      - quad.c, lines 9 - 12 : as above
      - userl.c, lines 10 - 13 : as above
      - user2.c, lines 10 - 13 : as above
      - user3.c, lines 10 - 13 : as above
      - user4.c, lines 10 - 13 : as above
      Solution:
               remove the offending definition lines from each file.

   d) src.alpha/misc/m.lulc.USGS
      - main.c, line 3 : calloc redeclared
                line 4 : free redeclared.
                line 5 : malloc redeclared.
                line 6 : realloc redeclared.

      Solution:
               edit main.c, remove the offending definition lines.

   e) src/xgrass/libes/Xgd
      - src/include/std-incs.h, line 8 : *calloc() redefined
                                line 9 : *malloc() redefined
                                line 10 : *realloc() redefined
      Solution:
               edit include/std_incs.h, remove the three offending
               definition lines.

   f) src/xgrass/libes/Xgi
      - dirlist.c, line 40 : readdir redefined
      - line 51 : operands are pointers to wrong type
                              *dp should be type dirent, not type
                              direct.
      - line 109 : readdir redefined again
      Solution:
                edit dirlist.c,
                     line 39 : uncomment struct dirent *dp;
                                comment out unwanted one.
                     line 40 : remove struct direct *readdir();
                     line 107 : uncomment struct dirent *dp;
                                comment out unwanted one.

   g) display/devices/XDRIVER/XDRIVER
      - SWITCHER.c, line 45 : parameter list contains fewer parameters
                                than required by macro
      - line 1240 : malloc() redeclared
      Solution:
               edit SWITCHER.c,
                    line 45 : remove *malloc(),
                    line 1239 : remove char *malloc(), *realloc();

Here is the head file that I used:
-----------------------------------------------------

CC = cc
ARCH = RS6000

GISBASE = /usr/local/grass4.1/RS6000
UNIX_BIN = /usr/local/bin

DEFAULT_DATABASE = /usr/local/grass.data
DEFAULT_LOCATION = alberta

COMPILE_FLAGS = -O
LDFLAGS = -s

XCFLAGS = -D_NO_PROTO
XLDFLAGS =
XINCPATH =
XMINCPATH =
XLIBPATH = -L/usr/lib
XTLIBPATH = -L/usr/lib
XMLIBPATH = -L/usr/lib
XLIB = -lX11
XTLIB = -lXt
XMLIB = -lXm
XEXTRALIBS =

TERMLIB =
CURSES = -lcurses $(TERMLIB)
MATHLIB = -lm

# LIBRULE = ar ruv $@ $?
# LIBRULE = ar ruv $@ $?; ranlib $@
# LIBRULE = ar ruv $@ $?; ar ts $@
# LIBRULE = ar rc $@ `lorder $(OBJ) | tsort`
LIBRULE = ar ruv $@ $?

USE_TERMIO = -DUSE_TERMIO
USE_MTIO =
USE_FTIME =
DIGITFLAGS = -DUSE_SETREUID -DUSE_SETEUID -DUSE_SETPRIORITY
VECTLIBFLAGS =
GETHOSTNAME = -DGETHOSTNAME_OK

-------------------------------------------------------------
  Tim Martin *
  Spatial Information Systems * These opinions are my own:
  University of Alberta * My employer has none!
  martin@ulysses.sis.ualberta.ca *
-------------------------------------------------------------