[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] A Patch for -dumpmachine Option
From: |
Ziyao |
Subject: |
[Tinycc-devel] A Patch for -dumpmachine Option |
Date: |
Thu, 24 Mar 2022 18:35:55 +0800 |
User-agent: |
Mutt/1.9.4 (2018-02-28) |
Hi list,
I have made a small patch which adds option "-dumpmachine" support to
TinyCC.This option is widely supported by both gcc and clang.Some configure
scripts detect the platform information by passing this option to the
C compiler,such as musl libc.
And by the way,what is the proper way to contribute? Just send patches to
this maillist or what?Should I send a normal patch or formatted patch?
Thanks for answering.
(To avoid messing the plaintext mail readers up,I add my patch to the bottom
of this mail.)
Cheers,
Ziyao
--------------------------------------
diff --git a/libtcc.c b/libtcc.c
index b6dbb01..6e5cf17 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1456,6 +1456,7 @@ enum {
TCC_OPTION_g,
TCC_OPTION_c,
TCC_OPTION_dumpversion,
+ TCC_OPTION_DUMPMACHINE,
TCC_OPTION_d,
TCC_OPTION_static,
TCC_OPTION_std,
@@ -1488,7 +1489,7 @@ enum {
TCC_OPTION_MMD,
TCC_OPTION_x,
TCC_OPTION_ar,
- TCC_OPTION_impdef,
+ TCC_OPTION_impdef
};
#define TCC_OPTION_HAS_ARG 0x0001
@@ -1518,6 +1519,7 @@ static const TCCOption tcc_options[] = {
{ "g", TCC_OPTION_g, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "c", TCC_OPTION_c, 0 },
{ "dumpversion", TCC_OPTION_dumpversion, 0},
+ { "dumpmachine", TCC_OPTION_DUMPMACHINE , 0 },
{ "d", TCC_OPTION_d, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
{ "static", TCC_OPTION_static, 0 },
{ "std", TCC_OPTION_std, TCC_OPTION_HAS_ARG | TCC_OPTION_NOSEP },
@@ -1952,6 +1954,8 @@ reparse:
printf ("%s\n", TCC_VERSION);
exit(0);
break;
+ case TCC_OPTION_DUMPMACHINE:
+ return OPT_DUMPMACHINE;
case TCC_OPTION_x:
x = 0;
if (*optarg == 'c')
diff --git a/tcc.c b/tcc.c
index 42a251b..ed9c143 100644
--- a/tcc.c
+++ b/tcc.c
@@ -95,6 +95,7 @@ static const char help2[] =
" -isystem dir add 'dir' to system include path\n"
" -static link to static libraries (not
recommended)\n"
" -dumpversion print version\n"
+ " -dumpmachine print platform information\n"
" -print-search-dirs print search paths\n"
" -dt with -run/-E: auto-define 'test_...'
macros\n"
"Ignored options:\n"
@@ -289,6 +290,47 @@ redo:
return 0;
++opt;
}
+
+ if (opt == OPT_DUMPMACHINE) {
+ fputs(
+#ifdef TCC_TARGET_I386
+ "i386"
+#elif defined TCC_TARGET_X86_64
+ "x86_64"
+#elif defined TCC_TARGET_C67
+ "c67"
+#elif defined TCC_TARGET_ARM
+ "arm"
+# ifdef TCC_ARM_EABI
+ " eabi"
+# ifdef TCC_ARM_HARDFLOAT
+ "hf"
+# endif
+# endif
+#elif defined TCC_TARGET_ARM64
+ "aarch64"
+#elif defined TCC_TARGET_RISCV64
+ "riscv64"
+#endif
+ "-"
+#ifdef TCC_TARGET_PE
+ "windows"
+#elif defined(TCC_TARGET_MACHO)
+ "darwin"
+#elif TARGETOS_FreeBSD || TARGETOS_FreeBSD_kernel
+ "freebsd"
+#elif TARGETOS_OpenBSD
+ "openbsd"
+#elif TARGETOS_NetBSD
+ "netbsd"
+#else
+ "linux"
+#endif
+ "-tcc\n",stdout);
+ return 0;
+
+ }
+
if (opt == OPT_HELP2) {
fputs(help2, stdout);
return 0;
diff --git a/tcc.h b/tcc.h
index 9724848..3812241 100644
--- a/tcc.h
+++ b/tcc.h
@@ -1279,6 +1279,7 @@ ST_FUNC char *tcc_load_text(int fd);
#define OPT_PRINT_DIRS 4
#define OPT_AR 5
#define OPT_IMPDEF 6
+#define OPT_DUMPMACHINE 7
#define OPT_M32 32
#define OPT_M64 64
- [Tinycc-devel] A Patch for -dumpmachine Option,
Ziyao <=