caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Adrien Nader <adrien@notk.org>
To: "Daniel Bünzli" <daniel.buenzli@erratique.ch>
Cc: Malcolm Matalka <mmatalka@gmail.com>, caml-list@inria.fr
Subject: Re: [Caml-list] Suggested way to determine platform specific capabilities in build system?
Date: Sun, 19 Apr 2015 08:47:22 +0200	[thread overview]
Message-ID: <20150419064722.GA25301@notk.org> (raw)
In-Reply-To: <A3109D1A77E44BD781BACFE3CD56F703@erratique.ch>

Hi,

On Tue, Apr 14, 2015, Daniel Bünzli wrote:
> Le mardi, 14 avril 2015 à 12:51, Malcolm Matalka a écrit :
> > What is the current suggested way to determine what, roughly, autoconf
> > would do for you? I have some platform specific functionality to be
> > included (or excluded) depending on the OS.
> 
> I don't know if there's a suggested way but here are various ways to proceed.
> 
> If you are using ocamlbuild, you can use `Sys.win32` since 4.01.0 or `Sys.os_type = "Win32"` to determine if you are on windows and otherwise get the (stripped and lowercased) result of `uname -s`, see e.g (but it's missing the win bit):  
> 
> https://github.com/dbuenzli/tsdl/blob/master/myocamlbuild.ml#L6
> 
> If you are using Makefiles you may want include `$(ocamlc -where)/lib/ocaml/Makefile.config` and use the `$SYSTEM` variable.
> 
> If this is only needed for C stubs you can also try solve this at the CPP level — but I guess this can be quite brittle — see e.g (here again missing the win bit as it's undefined for now):  
> 
> https://github.com/dbuenzli/mtime/blob/master/src-os/mtime_stubs.c#L11-L21
> 
> In any case make sure the value can be overridden from the command line for cross compilation scenarios.  

This is the wrong approach. Please do not test for systems but for
capabilities. Testing for systems hinders progress and is a huge
long-term cost.

Consider the case where you test for windows on the mingw-w64 toolchain.
Something isn't available and you therefore disable it. Then mingw-w64
add it and tt becomes available at the end of the year.
Either you must push a new release (typically a development one that is
completely experimental) or the packager must patch (and that's one of
the most annoying kind of patching to do) or the software never takes
advantage of the new feature.

The proper way to do it is to test for features instead. Want to know if
function foo is available in library bar? Well, just reference it and
see if compilation and/or linking fails. You can also try to run it, if
not cross-compiling; at which point you would have to guess (in practice
it's < 1% of cases).

-- 
Adrien Nader

  parent reply	other threads:[~2015-04-19  6:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-14 10:51 Malcolm Matalka
2015-04-14 11:23 ` Daniel Bünzli
2015-04-14 13:17   ` Thomas Gazagnaire
2015-04-19  6:47   ` Adrien Nader [this message]
2015-04-19  8:38     ` Daniel Bünzli
2015-04-19 10:13       ` David Allsopp
2015-04-19 12:11         ` Daniel Bünzli
2015-04-19 19:14           ` Emmanuel Surleau
2015-04-20  9:55             ` Ben Millwood
2015-04-17 10:38 ` Ivan Gotovchits
2015-04-21 21:36 ` Richard W.M. Jones

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=20150419064722.GA25301@notk.org \
    --to=adrien@notk.org \
    --cc=caml-list@inria.fr \
    --cc=daniel.buenzli@erratique.ch \
    --cc=mmatalka@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;
as well as URLs for NNTP newsgroup(s).