Subject: Re: Compiling bmake under AIX?
To: Andrew Cagney <cagney@tpgi.com.au>
From: Brian C. Grayson <bgrayson@ece.utexas.edu>
List: tech-toolchain
Date: 03/13/1997 12:25:38
Andrew Cagney wrote:
> 
> Hello,
> 
> I've been informed that bmake won't compile under AIX.
> 
> If any one has an AIX machine (and a little spare time) then it would
> probably be worth checking this out.

  I took a quick look.  First of all, I can't compile 'make' on a
NetBSD system using Makefile.boot -- in make.h, we include
<sys/types.h>, which contains a prototype for truncate() that
contains a const char * as an arg.  In make.h, we later include
<unistd.h>, which also contains a prototype for truncate().  All
would be okay, except that in between, make.h define's 'const' as
'', leading to conflicting declarations as the 'const' in the
second declaration is whisked away.

  I also tried to compile on an AIX system, and noticed a few
things, most of which could be considered AIX's fault:
  1.  ARMAG and company have different names based on AIAMAG.
  2.  the ar_name member of the ar_hdr is contained in a union,
    and should be referenced as _ar_name.ar_name.  Same goes for
    ar_fmag ==> _ar_name.ar_fmag.

  These can be fixed by adding the following 5 lines to arch.c,
after the include of ar.h:
#define ar_name _ar_name.ar_name
#define ar_fmag _ar_name.ar_fmag
#define SARMAG  SAIAMAG
#define ARMAG   AIAMAG
#define ARFMAG  AIAFMAG

  3.  job.c is choking on the fd_set stuff.  fd_set is not
    defined in sys/types.h on AIX unless _BSD is defined.

  Add -D_BSD to job.c, before any includes.  (Don't put it in the
Makefile, because of #4.)

  4.  The WIF*() macros on AIX, when _BSD is defined, take a
    union rather than an int, so the compile dies when the macro
    tries to take a member of an int.

  Add an #undef _BSD before the include of wait.h

  5.  After all of that, setenv() isn't in libc.a, so the link fails.

  Write up a quicky version of setenv() in make.h.
(Alternatively, one could include -lisode, but traveling down
that path led to other problems.)

  6.  vfork() isn't in libc, so link fails.

  Add -lbsd to the LIBS variable in the Makefile.

  7.  After all that, I got an executable.  However, when I tried to
    run it to compile itself, it died with:
    make: no system rules (sys.mk).

  So, copy sys.mk from a BSD machine into the current directory.
Don't forget to remove .depend, also -- it probably has include
files listed that are not valid on the current machine.
  
  At this point, I was able to recompile bmake using the
Makefile.boot, and 'bmake -j2' also worked.  I then copied all of
/usr/share/mk into the current directory, and then bmake worked
with the 'ordinary' makefile until it ran into further AIXism
problems (lack of snprintf, time() defined in a different header
file (presumably), etc.) due to the differences between a
bootstrap build of make and an ordinary one.

  So, with a bit of hacking, it is possible to get BSD make to
compile on AIX.  We may want to add a README.AIX or something
containing sufficient patches to do most of the above, since I'm
sure the numbers of people cross-compiling on AIX machines will
increase as NetBSD-powerpc continues to gain momentum.

  Hope this helps someone out!

  Brian
-- 
Brian Grayson (bgrayson@ece.utexas.edu)
Graduate Student, Electrical and Computer Engineering
The University of Texas at Austin
Office:  ENS 406       (512) 471-8011
Finger bgrayson@orac.ece.utexas.edu for PGP key.