Subject: 28.0.50; `./configure --native-compilation` fails on FreeBSD if 'porttools' is installed

From: Yasuhiro Kimura <[email-masked]>
Date: Mon, 30 Aug 2021 07:48:02 +0900 (JST)

There is an port/package named 'porttools' in FreeBSD Ports/Packages
Collections. it includes shell script named `port`, and if it is
installed, `./configure --native-compilation` fails as following.

----------------------------------------------------------------------
checking for getpagesize... (cached) yes
checking for working mmap... (cached) yes
checking for main in -lXbsd... no
checking for pthread library... -lpthread
checking for thread support... yes
checking for getaddrinfo_a in -lanl... no
checking for gnutls >= 2.12.2... yes
checking for jansson >= 2.7... yes
checking for libkqueue... no
checking for library containing kqueue... none required
checking for library containing inflateEnd... -lz
checking for dlopen... (cached) yes
checking for dladdr... yes
checking for dlfunc... yes
usage: dirname string [...]
usage: dirname string [...]
checking for gcc_jit_context_acquire in -lgccjit... no
configure: error: ELisp native compiler was requested, but libgccjit was not found.
----------------------------------------------------------------------

I checked configure.ac and found following lines.

----------------------------------------------------------------------
# Check MacPorts on macOS.
AC_PATH_PROG(HAVE_MACPORTS, port)
----------------------------------------------------------------------

It means that configure script regards that OS is macOS and MacPorts
is installed if it finds `port` command in you PATH. As I wrote above
'porttools' package installs shell script named `port`. So if you
execute configure script on FreeBSD system that 'porttools' package is
installed, then it misinterprets thet OS is macOS and fails to detect
libgccjit. In fact configure script works fine if this line is
commented out.

According to my study about MacPorts,

1. MacPorts only works with macOS
2. If MacPort is installed, `port` command is used to interact with
   MacPorts.

So configure script should work as is expected even if the above lines
are chanaged as following.

----------------------------------------------------------------------
# Check MacPorts on macOS.
if test $opsys = darwin; then
  AC_PATH_PROG(HAVE_MACPORTS, port)
fi
----------------------------------------------------------------------

And it also prevents `port` command installed in non-macOS system from
being misdetected as the evidence that OS is macOS.

In GNU Emacs 28.0.50 (build 1, amd64-portbld-freebsd13.0)
Repository revision: 3572613
Repository branch: master
System Description: 13.0-RELEASE-p4

Configured using:
 'configure --disable-build-details --localstatedir=/var
 --without-libsystemd --without-selinux --with-sound=no
 --with-x-toolkit=no --without-cairo --without-dbus --without-gconf
 --without-gif --without-gsettings --without-imagemagick
 --without-jpeg --without-lcms2 --without-libotf --without-m17n-flt
 --without-png --without-rsvg --without-tiff
 --without-toolkit-scroll-bars --without-x --without-xim --without-xpm
 --without-xwidgets --enable-acl --without-cairo --without-dbus
 --without-gconf --without-gif --with-gnutls --without-gsettings
 --without-harfbuzz --without-jpeg --with-json
 --with-file-notification=kqueue --without-lcms2 --without-m17n-flt
 --without-imagemagick --without-mailutils --with-modules
 --with-native-compilation --without-libotf --without-png
 --without-toolkit-scroll-bars --without-rsvg --with-threads
 --without-tiff --without-xft --without-xim --with-xml2 --without-xpm
 --without-xwidgets --with-x-toolkit=no --prefix=/usr/local
 --mandir=/usr/local/man --disable-silent-rules
 --infodir=/usr/local/share/emacs/info/
 --build=amd64-portbld-freebsd13.0 'CFLAGS=-O2 -pipe
 -fstack-protector-strong -isystem /usr/local/include
 -fno-strict-aliasing ' 'CPPFLAGS=-isystem /usr/local/include'
 'LDFLAGS= -L/usr/local/lib/gcc11 -fstack-protector-strong
 -L/usr/local/lib ''

Configured features:
ACL GMP GNUTLS JSON LIBXML2 MODULES NATIVE_COMP NOTIFY KQUEUE PDUMPER
THREADS XIM ZLIB

Important settings:
  value of $LANG: ja_JP.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  shell-dirtrack-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t

Load-path shadows:
/usr/local/share/emacs/28.0.50/site-lisp/transient hides /usr/local/share/emacs/28.0.50/lisp/transient
/home/yasu/share/emacs/lisp/ruby-mode hides /usr/local/share/emacs/28.0.50/lisp/progmodes/ruby-mode
/usr/local/share/emacs/28.0.50/site-lisp/flim/sasl hides /usr/local/share/emacs/28.0.50/lisp/net/sasl

Features:
(shadow pp mew-varsx mew-unix mew-w3m w3m doc-view image-mode exif
timezone w3m-hist w3m-fb bookmark-w3m w3m-ems wid-edit w3m-favicon
w3m-image tab-line w3m-proc w3m-util mew-auth mew-config mew-imap2
mew-imap mew-nntp2 mew-nntp mew-pop mew-smtp mew-ssl mew-ssh mew-net
mew-highlight mew-sort mew-fib mew-ext mew-refile mew-demo mew-attach
mew-draft mew-message mew-thread mew-virtual mew-summary4 mew-summary3
mew-summary2 mew-summary mew-search mew-pick mew-passwd mew-scan
mew-syntax mew-bq mew-smime mew-pgp mew-header mew-exec mew-mark
mew-mime mew-edit mew-decode mew-encode mew-cache mew-minibuf
mew-complete mew-addrbook mew-local mew-vars3 mew-vars2 mew-vars
mew-env mew-lang-jp mew-mule3 mew-mule mew-gemacs mew-key mew-func
mew-blvs mew-const mew emacsbug sendmail eieio-opt speedbar ezimage
image dframe find-func shortdoc help-fns radix-tree pcase term/screen
term/xterm xterm jka-compr magit-version yaml-mode tmux mime-setup
mail-mime-setup alist semi-setup path-util apel-ver product semi-def
rng-nxml rng-valid rng-loc rng-uri rng-parse nxml-parse rng-match
rng-dt rng-util rng-pttrn nxml-ns nxml-mode nxml-outln nxml-rap
sgml-mode facemenu dom nxml-util nxml-enc xmltok edmacro kmacro
forge-list forge-commands forge-semi forge-bitbucket buck forge-gogs
gogs forge-gitea gtea forge-gitlab glab forge-github ghub-graphql
treepy gsexp ghub let-alist gnutls forge-notify forge-revnote
forge-pullreq forge-issue forge-topic yaml parse-time iso8601
bug-reference forge-post markdown-mode color noutline outline
forge-repo forge forge-core forge-db closql emacsql-sqlite advice
emacsql emacsql-compiler url-http url-auth url-gw nsm magit-submodule
magit-obsolete magit-blame magit-stash magit-reflog magit-bisect
magit-push magit-pull magit-fetch magit-clone magit-remote
magit-commit magit-sequence magit-notes magit-worktree magit-tag
magit-merge magit-branch magit-reset magit-files magit-refs
magit-status magit package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie url-domsuf url-util
mailcap url-handlers url-parse url-vars magit-repos magit-apply
magit-wip magit-log which-func imenu magit-diff smerge-mode diff
diff-mode git-commit log-edit easy-mmode message rmc puny dired
dired-loaddefs rfc822 mml mml-sec epa derived epg epg-config gnus-util
rmail rmail-loaddefs auth-source password-cache json map
text-property-search time-date mm-decode mm-bodies mm-encode
mail-parse rfc2231 rfc2047 rfc2045 mm-util ietf-drums mail-prsvr
mailabbrev mail-utils gmm-utils mailheader pcvs-util add-log
magit-core magit-autorevert autorevert filenotify magit-margin
magit-transient magit-process with-editor shell pcomplete comint ring
server ansi-color magit-mode transient comp regexp-opt comp-cstr
warnings cl-extra help-mode tool-bar format-spec magit-git
magit-section cl-seq magit-utils crm subr-x seq eieio byte-opt
bytecomp byte-compile cconv eieio-core cl-macs gv eieio-loaddefs dash
gitignore-mode gitconfig-mode conf-mode rx gitattributes-mode
thingatpt cl-loaddefs cl-lib japan-util iso-transl tooltip eldoc
electric uniquify ediff-hook vc-hooks lisp-float-type tabulated-list
replace newcomment text-mode elisp-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select mouse
jit-lock font-lock syntax font-core term/tty-colors frame minibuffer
cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese composite
charscript charprop case-table epa-hook jka-cmpr-hook help simple
abbrev obarray cl-preloaded nadvice button loaddefs faces cus-face
macroexp files window text-properties overlay sha1 md5 base64 format
env code-pages mule custom widget hashtable-print-readable backquote
threads kqueue multi-tty make-network-process native-compile emacs)

Memory information:
((conses 16 306358 12198)
 (symbols 48 26684 51)
 (strings 32 90103 9469)
 (string-bytes 1 2684385)
 (vectors 16 52613)
 (vector-slots 8 987918 20994)
 (floats 8 315 115)
 (intervals 56 400 0)
 (buffers 992 14))