From: Julien Moutinho <julien.moutinho@gmail.com>
To: Eric Merritt <cyberlync@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] getting the system architecture
Date: Fri, 3 Aug 2007 17:18:11 +0200 [thread overview]
Message-ID: <20070803151811.GA5501@jiyu.gnu> (raw)
In-Reply-To: <f69c840c0708021609r396cb01fj9778df0f1545f99f@mail.gmail.com>
On Thu, Aug 02, 2007 at 04:09:15PM -0700, Eric Merritt wrote:
> Is there anyway to get the system architecture natively in ocaml? I
> found Sys.os_type but have yet to find anything comparable for the
> architecture.
Grepping at the Ocaml sources I see a few uses of <sys/utsname.h>,
but none of them deals with the ``machine'' field.
Apparently, they never need a runtime check of the arch.
> The alternative is to build out a function to get this
> info in C but I would rather not complicate my build
I don't know exactly how portable you want to be,
but you can also try to launch uname -m or this awful config/gnu/config.guess
either in a sub-process or in a ./configure coupled with a camlp4 definition.
> (or code in C ;)
% cat c_arch.c
#include <sys/utsname.h>
#include <caml/memory.h>
#include <caml/compatibility.h>
CAMLprim value arch_get(value unit)
{
CAMLparam0(); /* ``unit'' is not used */
struct utsname utsbuf;
if (uname( &utsbuf ))
failwith( "Arch.get" );
CAMLreturn(copy_string( utsbuf.machine ));
}
% cat arch.ml
external get : unit -> string = "arch_get"
% cat test.ml
print_endline (Arch.get ())
% gcc -c c_arch.c
% ar rc libarch.a c_arch.o
% ocamlopt -c arch.ml
% ocamlopt -a -o arch.cmxa -cclib -larch arch.cmx
% ocamlopt -c test.ml
% ocamlopt -o test.opt -I . arch.cmxa test.cmx
% ./test.opt
i686
Hope this helps a bit.
next prev parent reply other threads:[~2007-08-03 15:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-02 23:09 Eric Merritt
2007-08-03 15:18 ` Julien Moutinho [this message]
[not found] ` <f69c840c0708030954o5654a1ddk6628bb67a1463f5b@mail.gmail.com>
2007-08-03 19:14 ` [Caml-list] " Julien Moutinho
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070803151811.GA5501@jiyu.gnu \
--to=julien.moutinho@gmail.com \
--cc=caml-list@inria.fr \
--cc=cyberlync@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox