Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mono / utils / mono-hwcap.c
1 /**
2  * \file
3  * Hardware feature detection
4  *
5  * Authors:
6  *    Alex Rønne Petersen (alexrp@xamarin.com)
7  *    Elijah Taylor (elijahtaylor@google.com)
8  *    Miguel de Icaza (miguel@xamarin.com)
9  *    Neale Ferguson (Neale.Ferguson@SoftwareAG-usa.com)
10  *    Paolo Molaro (lupus@xamarin.com)
11  *    Rodrigo Kumpera (kumpera@gmail.com)
12  *    Sebastien Pouliot (sebastien@xamarin.com)
13  *    Zoltan Varga (vargaz@xamarin.com)
14  *
15  * Copyright 2003 Ximian, Inc.
16  * Copyright 2003-2011 Novell, Inc
17  * Copyright 2006 Broadcom
18  * Copyright 2007-2008 Andreas Faerber
19  * Copyright 2011-2013 Xamarin Inc
20  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
21  */
22
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "mono/utils/mono-hwcap.h"
27
28 #define MONO_HWCAP_VAR(NAME) gboolean mono_hwcap_ ## NAME = FALSE;
29 #include "mono/utils/mono-hwcap-vars.h"
30 #undef MONO_HWCAP_VAR
31
32 static gboolean hwcap_inited = FALSE;
33
34 void
35 mono_hwcap_init (void)
36 {
37         char *verbose = g_getenv ("MONO_VERBOSE_HWCAP");
38         char *conservative = g_getenv ("MONO_CONSERVATIVE_HWCAP");
39
40         if (hwcap_inited)
41                 return;
42
43         if (!conservative || strncmp (conservative, "1", 1))
44                 mono_hwcap_arch_init ();
45
46         if (verbose && !strncmp (verbose, "1", 1))
47                 mono_hwcap_print ();
48
49         g_free (verbose);
50         g_free (conservative);
51 }
52
53 void
54 mono_hwcap_print (void)
55 {
56         g_print ("[mono-hwcap] Detected following hardware capabilities:\n\n");
57
58 #define MONO_HWCAP_VAR(NAME) g_print ("\t" #NAME " = %s\n", mono_hwcap_ ## NAME ? "yes" : "no");
59 #include "mono/utils/mono-hwcap-vars.h"
60 #undef MONO_HWCAP_VAR
61
62         g_print ("\n");
63 }