# [email protected] / 2010-02-11 08:47:16 +0100:
> Roman Neuhauser a écrit :
> > Hello,
> >
> > I'm having trouble with nekoml on FreeBSD 9.0-CURRENT.
[...]
> If you know any good way to easily know the current executable path on
> *BSD (and not the calling executable path) I'm open for patches. Both
> windows and OSX have OS-specific functions already.
I wrote in another email that I got a working nekoml "with a trivial
change applied to neko-1.8.1", but it was the FreeBSD port, not vanilla
code.
Here's a patch that makes neko buildable on FreeBSD "out of the box".
See the current port of neko for comparison:
http://www.freebsd.org/cgi/cvsweb.cgi/ports/lang/neko/files/
http://www.freebsd.org/cgi/cvsweb.cgi/ports/lang/neko/Makefile?rev=1.14
(post-patch target)
I've tried to stick to the style of the surrounding code, but it's
more than possible that I deviated from it in a few places. If you
need me to redo something, just let me know.
Patch description for exposition in list archives:
Building neko on FreeBSD requires a few changes to the code and the port
achieves them in fairly straightforward ways (shotgun sedding). This
diff recreates the changes such that they're hopefully committable
upstream. With this patch applied, neko builds (libraries not checked)
on FreeBSD with "LD=$CC FREEBSD=1 gmake", provided that dependencies
such as Boehm GC are installed using ports or packages.
Summary of the changes:
* Makefile
libdl doesn't exist on FreeBSD and libgc is split into libgc and
libgc-threaded; ${LOCALBASE} (/usr/local by default) is used by the
ports system
* libs/std/process.c
wait.h seems to be Linux-specific, all the major BSD systems have
sys/wait.h and OS X seems to be the same[1]; I guess you got away
without this include on OS X because it leaks through another
system header
* libs/std/sys.c
* vm/neko.h
none of {Free,Net,Open}BSD have xlocale.h AFAICT, so I changed
the flag tested in set_time_locale to NEKO_HAVE_LOCALE_T, and
define it in vm/neko.h
* src/tools/install.neko
threaded programs on FreeBSD require linking with gcc, not ld[2],
but I don't know the situation on other BSDs so I kept the old
default behavior and made it configurable through getenv("LD")
[1] http://www.opengroup.org/onlinepubs/009695399/functions/waitpid.html
http://www.freebsd.org/cgi/man.cgi?query=waitpid&manpath=FreeBSD+8.0-RELEASE
http://netbsd.gw.com/cgi-bin/man-cgi?waitpid++NetBSD-5.0
http://www.openbsd.org/cgi-bin/man.cgi?query=waitpid&manpath=OpenBSD+4.6
http://gemma.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man2/waitpid.2.html
[2] http://www.freebsd.org/doc/en/books/porters-handbook/dads-pthread.html
--
Roman Neuhauser
# HG changeset patch
# User neuhauser
# Date 1266184412 -3600
# Node ID 35c92addaa580132ee87871ff33cb521f2b7407b
# Parent adaa2a0917cbc727a64701438813f36898be7997
neko buildable on FreeBSD
Building neko on FreeBSD requires a few changes to the code and the port
achieves them in fairly straightforward ways (shotgun sedding). This
diff recreates the changes such that they're hopefully committable
upstream. With this patch applied, neko builds (libraries not checked)
on FreeBSD with "LD=$CC FREEBSD=1 gmake", provided that dependencies
such as Boehm GC are installed using ports or packages.
Summary of the changes:
* Makefile
libdl doesn't exist on FreeBSD and libgc is split into libgc and
libgc-threaded; ${LOCALBASE} (/usr/local by default) is used by the
ports system
* libs/std/process.c
wait.h seems to be Linux-specific, all the major BSD systems have
sys/wait.h and OS X seems to be the same[1]; I guess you got away
without this include on OS X because it leaks through another
system header
* libs/std/sys.c
* vm/neko.h
none of {Free,Net,Open}BSD have xlocale.h AFAICT, so I changed
the flag tested in set_time_locale to NEKO_HAVE_LOCALE_T, and
define it in vm/neko.h
* src/tools/install.neko
threaded programs on FreeBSD require linking with gcc, not ld[2],
but I don't know the situation on other BSDs so I kept the old
default behavior and made it configurable through getenv("LD")
[1] http://www.opengroup.org/onlinepubs/009695399/functions/waitpid.html
http://www.freebsd.org/cgi/man.cgi?query=waitpid&manpath=FreeBSD+8.0-RELEASE
http://netbsd.gw.com/cgi-bin/man-cgi?waitpid++NetBSD-5.0
http://www.openbsd.org/cgi-bin/man.cgi?query=waitpid&manpath=OpenBSD+4.6
http://gemma.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man2/waitpid.2.html
[2] http://www.freebsd.org/doc/en/books/porters-handbook/dads-pthread.html
diff -r adaa2a0917cb -r 35c92addaa58 Makefile
--- a/Makefile Sun Feb 14 11:45:03 2010 +0100
+++ b/Makefile Sun Feb 14 22:53:32 2010 +0100
@@ -6,7 +6,9 @@
EXTFLAGS = -pthread
MAKESO = $(CC) -shared -WBsymbolic
LIBNEKO_NAME = libneko.so
-LIBNEKO_LIBS = -ldl -lgc -lm
+LIBNEKO_LIBS = ${LIBDL} ${LIBGC} -lm
+LIBDL = -ldl
+LIBGC = -lgc
NEKOVM_FLAGS = -Lbin -lneko
STD_NDLL_FLAGS = ${NEKOVM_FLAGS} -lrt
INSTALL_FLAGS =
@@ -35,6 +37,23 @@
# CFLAGS += -DLOW_MEM
# For MINGW/MSYS
+#
+# WIN32 = 1
+
+# For FreeBSD
+#
+# FREEBSD = 1
+
+### FreeBSD specific
+
+ifeq (${FREEBSD}, 1)
+LIBDL =
+LOCALBASE ?= /usr/local
+CFLAGS += -I${LOCALBASE}/include
+LIBGC = -L${LOCALBASE}/lib -lgc-threaded
+endif
+
+### MINGW/MSYS specific
ifeq (${WIN32}, 1)
CFLAGS = -g -Wall -O3 -momit-leaf-frame-pointer -I vm -I /usr/local/include
diff -r adaa2a0917cb -r 35c92addaa58 libs/std/process.c
--- a/libs/std/process.c Sun Feb 14 11:45:03 2010 +0100
+++ b/libs/std/process.c Sun Feb 14 22:53:32 2010 +0100
@@ -22,8 +22,10 @@
# include <sys/types.h>
# include <unistd.h>
# include <errno.h>
-# ifndef NEKO_MAC
+# ifdef NEKO_LINUX
# include <wait.h>
+# else
+# include <sys/wait.h>
# endif
#endif
diff -r adaa2a0917cb -r 35c92addaa58 libs/std/sys.c
--- a/libs/std/sys.c Sun Feb 14 11:45:03 2010 +0100
+++ b/libs/std/sys.c Sun Feb 14 22:53:32 2010 +0100
@@ -35,7 +35,9 @@
# include <termios.h>
# include <sys/time.h>
# include <sys/times.h>
-# include <xlocale.h>
+# ifdef NEKO_HAVE_LOCALE_T
+# include <xlocale.h>
+# endif
#endif
#ifdef NEKO_MAC
@@ -123,7 +125,7 @@
<doc>Set the locale for LC_TIME, returns true on success</doc>
**/
static value set_time_locale( value l ) {
-#ifdef NEKO_POSIX
+#ifdef NEKO_HAVE_LOCALE_T
locale_t lc, old;
val_check(l,string);
lc = newlocale(LC_TIME_MASK,val_string(l),NULL);
diff -r adaa2a0917cb -r 35c92addaa58 src/tools/install.neko
--- a/src/tools/install.neko Sun Feb 14 11:45:03 2010 +0100
+++ b/src/tools/install.neko Sun Feb 14 22:53:32 2010 +0100
@@ -112,7 +112,8 @@
if( system == "Linux" ) cflags += " -pthread";
cc = getenv("CC");
if( cc == null ) cc = "gcc";
-linkcmd = switch system { "BSD" => "ld" default => cc };
+linkcmd = getenv("LD");
+if( linkcmd == null ) linkcmd = switch system { "BSD" => "ld" default => cc };
linkneko = "-lneko";
linkoptions = switch system {
"Mac" => "-bundle -undefined dynamic_lookup -L../../bin"
diff -r adaa2a0917cb -r 35c92addaa58 vm/neko.h
--- a/vm/neko.h Sun Feb 14 11:45:03 2010 +0100
+++ b/vm/neko.h Sun Feb 14 22:53:32 2010 +0100
@@ -67,6 +67,10 @@
# define NEKO_POSIX
#endif
+#if defined(NEKO_POSIX) && !defined(NEKO_BSD)
+# define NEKO_HAVE_LOCALE_T
+#endif
+
#if defined(NEKO_GCC)
# define NEKO_THREADED
# define NEKO_DIRECT_THREADED
--
Neko : One VM to run them all
(http://nekovm.org)