Subject: bug#5051: 23.1.50; Issues with Cocoa port on OS X

From: Ulrich Mueller <[email-masked]>
Date: Thu, 26 Nov 2009 20:28:44 +0100

This is a forward of Gentoo bug 268793,
<http://bugs.gentoo.org/268793>

While trying to package Emacs for Gentoo on OS X (i686-apple-darwin9)
with "configure --with-ns --disable-ns-self-contained", we observed
the following two issues:

1)
configure.in contains the following code:

   if test "${HAVE_NS}" = yes; then
     # [...]
     # set up packaging dirs
     exec_prefix=${ns_appbindir}
     libexecdir=${ns_appbindir}/libexec
     if test "${EN_NS_SELF_CONTAINED}" = yes; then
        prefix=${ns_appresdir}
     fi
   fi

Now on Gentoo / OS X _not_ everything should be put inside the .app,
but the installation should follow the lines of a traditional Unix
install. That means that exec_prefix and libexecdir should be set to
<some_prefix>/usr and <some_prefix>/usr/libexec, respectively.

Unfortunately, this is not possible because the above code
unconditionally overrides the two variables, ignoring any paths that
are explicitly set by the --exec-prefix and --libexecdir configure
options.

I suggest that the two assignments are moved into the block of the
following "if" statement, so that they are overridden only in the
"self-contained" case.

2)
The top-level Makefile.in contains the following "gem" in the
install-arch-dep target:

	if test "${ns_appdir}" != ""; then \
	  ( cd ${ns_appresdir} ; \
	    if test -d share/emacs ; then dir=share/emacs/*/*; $(MV_DIRS); fi;\
	    if test -d share/info ; then dir=share/info; $(MV_DIRS) ; fi ; \
	    rm -fr share ) ; \
	  ( cd ${ns_appbindir}/libexec ; dir=emacs/*/*/* ; $(MV_DIRS); \
	    rm -fr emacs ) ; \
	  ( cd ${ns_appbindir}/bin ; rm -f emacs emacs-23* ; \
	    ln -sf ../libexec/* .) ; \
	else true ; fi

where MV_DIRS is defined a few lines above as follows:

   MV_DIRS = for i in $$dir; do rm -fr `basename "$$i"` ; mv "$$i" . ; done

As can be seen from the build log at
<http://bugs.gentoo.org/attachment.cgi?id=211254&action=view>
this code fails in a horrible way, thereby removing the complete
contents of the build directory.

The relevant lines of the log are the following:
/Users/tetsushi/Gentoo26/bin/bash: line 5: cd: /Users/tetsushi/Gentoo26/var/tmp/portage/app-editors/emacs-23.1/work/emacs-23.1/nextstep/Emacs.app/Contents/MacOS/libexec: No such file or directory
mv: cannot stat `emacs/*/*/*': No such file or directory

What happens is that the "cd ${ns_appbindir}/libexec" command fails.
Note that there is no checking for errors; so make continues, staying
in the top-level directory. Of course it cannot find any subdirectory
named "emacs" there.

Hence, MV_DIRS will call basename on unexpanded "emacs/*/*/*", which
will return "*" as target for "rm -fr" (and remember, we are still in
the top-level dir). Ugh.

(Unfortunately, I don't have access to an OS X system, so for lack of
testing I can't prepare a patch myself.)

Configure options are as follows:

./configure \
  --prefix=/Users/tetsushi/Gentoo26/usr \
  --build=i686-apple-darwin9 \
  --host=i686-apple-darwin9 \
  --mandir=/Users/tetsushi/Gentoo26/usr/share/man \
  --infodir=/Users/tetsushi/Gentoo26/usr/share/info \
  --datadir=/Users/tetsushi/Gentoo26/usr/share \
  --sysconfdir=/Users/tetsushi/Gentoo26/etc \
  --localstatedir=/Users/tetsushi/Gentoo26/var/lib \
  --program-suffix=-emacs-23 \
  --infodir=/Users/tetsushi/Gentoo26/usr/share/info/emacs-23 \
  --without-sound \
  --without-x \
  --with-ns \
  --disable-ns-self-contained \
  --without-hesiod  \
  --without-kerberos \
  --without-kerberos5 \
  --without-gpm \
  --without-dbus

Configured for `i686-apple-darwin9'.

  Where should the build process find the source code?    /Users/tetsushi/Gentoo26/var/tmp/portage/app-editors/emacs-23.1/work/emacs-23.1
  What operating system and machine description files should Emacs use?
        `s/darwin.h' and `m/intel386.h'
  What compiler should emacs be built with?               i686-apple-darwin9-gcc -O2 -march=nocona -pipe
  Should Emacs use the GNU version of malloc?             no
    (The GNU allocators don't work with this system configuration.)
  Should Emacs use a relocating allocator for buffers?    no
  Should Emacs use mmap(2) for buffer allocation?         no
  What window system should Emacs use?                    nextstep
  What toolkit should Emacs use?                          none
  Where do we find X Windows header files?                NONE
  Where do we find X Windows libraries?                   NONE
  Does Emacs use -lXaw3d?                                 no
  Does Emacs use -lXpm?                                   no
  Does Emacs use -ljpeg?                                  no
  Does Emacs use -ltiff?                                  no
  Does Emacs use a gif library?                           no 
  Does Emacs use -lpng?                                   no
  Does Emacs use -lrsvg-2?                                no
  Does Emacs use -lgpm?                                   no
  Does Emacs use -ldbus?                                  no
  Does Emacs use -lfreetype?                              no
  Does Emacs use -lm17n-flt?                              no
  Does Emacs use -lotf?                                   no
  Does Emacs use -lxft?                                   no
  Does Emacs use toolkit scroll bars?                     yes