Skip to content

Commit 534baa2

Browse files
authored
Partially revert 9d342d5 (#19)
Context: #10 Context: 9d342d5 Context: dotnet/android#8806 (comment) Revert the portion of 9d342d5 which modified the way command-line arguments are parsed. The `cxxopt` C++ library that was used turns out not to support some GNU-style options (e.g. `-mfpu=vpf3`) which breaks the MonoAOT compiler that uses them. Instead, copy `getopt.c` (BSD 2-clause + MIT/X11 licenses) and `getopt.h` (Public Domain license) implementations from the MinGW project and use `getopt` across all platforms. Additionally, fix generation of the artifact package by making sure that all the executable files are, in fact, executable by setting the correct permissions.
1 parent 5ce8e53 commit 534baa2

File tree

6 files changed

+813
-102
lines changed

6 files changed

+813
-102
lines changed

package.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ function prepare()
107107
else
108108
cp -P -a "${artifacts_source_bin}/${b}" "${artifacts_dest_bin}/${dest_b}"
109109
fi
110+
chmod 755 "${artifacts_dest_bin}/${dest_b}"
110111

111112
if [ -n "${src_pdb}" -a -f "${artifacts_source_bin}/${src_pdb}" ]; then
112113
cp -P -a "${artifacts_source_bin}/${src_pdb}" "${artifacts_dest_bin}/${dest_pdb}"

src/compat-include/getopt.h

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#ifndef __GETOPT_H__
2+
/**
3+
* DISCLAIMER
4+
* This file has no copyright assigned and is placed in the Public Domain.
5+
* This file is part of the mingw-w64 runtime package.
6+
*
7+
* The mingw-w64 runtime package and its code is distributed in the hope that it
8+
* will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR
9+
* IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to
10+
* warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11+
*/
12+
13+
#define __GETOPT_H__
14+
15+
/* All the headers include this file. */
16+
#include <crtdefs.h>
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
extern int optind; /* index of first non-option in argv */
23+
extern int optopt; /* single option character, as parsed */
24+
extern int opterr; /* flag to enable built-in diagnostics... */
25+
/* (user may set to zero, to suppress) */
26+
27+
extern char *optarg; /* pointer to argument of current option */
28+
29+
extern int getopt(int nargc, char * const *nargv, const char *options);
30+
31+
#ifdef __cplusplus
32+
}
33+
#endif
34+
/*
35+
* POSIX requires the `getopt' API to be specified in `unistd.h';
36+
* thus, `unistd.h' includes this header. However, we do not want
37+
* to expose the `getopt_long' or `getopt_long_only' APIs, when
38+
* included in this manner. Thus, close the standard __GETOPT_H__
39+
* declarations block, and open an additional __GETOPT_LONG_H__
40+
* specific block, only when *not* __UNISTD_H_SOURCED__, in which
41+
* to declare the extended API.
42+
*/
43+
#endif /* !defined(__GETOPT_H__) */
44+
45+
#if !defined(__GETOPT_BSD_H__) && defined(_BSD_SOURCE)
46+
#define __GETOPT_BSD_H__
47+
/*
48+
* BSD adds the non-standard `optreset' feature, for reinitialisation
49+
* of `getopt' parsing. We support this feature, for applications which
50+
* proclaim their BSD heritage, before including this header; however,
51+
* to maintain portability, developers are advised to avoid it.
52+
*/
53+
# define optreset __mingw_optreset
54+
extern int optreset;
55+
#endif /* !defined(__GETOPT_BSD_H__) && defined(_BSD_SOURCE) */
56+
57+
#if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
58+
#define __GETOPT_LONG_H__
59+
60+
#ifdef __cplusplus
61+
extern "C" {
62+
#endif
63+
64+
struct option /* specification for a long form option... */
65+
{
66+
const char *name; /* option name, without leading hyphens */
67+
int has_arg; /* does it take an argument? */
68+
int *flag; /* where to save its status, or NULL */
69+
int val; /* its associated status value */
70+
};
71+
72+
enum /* permitted values for its `has_arg' field... */
73+
{
74+
no_argument = 0, /* option never takes an argument */
75+
required_argument, /* option always requires an argument */
76+
optional_argument /* option may take an argument */
77+
};
78+
79+
extern int getopt_long(int nargc, char * const *nargv, const char *options,
80+
const struct option *long_options, int *idx);
81+
extern int getopt_long_only(int nargc, char * const *nargv, const char *options,
82+
const struct option *long_options, int *idx);
83+
/*
84+
* Previous MinGW implementation had...
85+
*/
86+
#ifndef HAVE_DECL_GETOPT
87+
/*
88+
* ...for the long form API only; keep this for compatibility.
89+
*/
90+
# define HAVE_DECL_GETOPT 1
91+
#endif
92+
93+
#ifdef __cplusplus
94+
}
95+
#endif
96+
97+
#endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */

0 commit comments

Comments
 (0)