diff mbox series

[7/7] cgcc: extract add_specs_os() from add_specs()

Message ID 20190217153131.94556-8-luc.vanoostenryck@gmail.com (mailing list archive)
State Rejected, archived
Headers show
Series cgcc: use gcc -dumpmachine | expand

Commit Message

Luc Van Oostenryck Feb. 17, 2019, 3:31 p.m. UTC
---
 cgcc | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)
diff mbox series

Patch

diff --git a/cgcc b/cgcc
index 170612b05..5fb458c40 100755
--- a/cgcc
+++ b/cgcc
@@ -93,7 +93,7 @@  if ($gendeps) {
 if ($do_check) {
     if (!$has_specs) {
 	$check .= &add_specs_arch;
-	$check .= &add_specs ('host_os_specs');
+	$check .= &add_specs_os;
     }
 
     $gcc_base_dir = qx($ccom -print-file-name=) if !$gcc_base_dir;
@@ -246,10 +246,16 @@  sub define_size_t {
 
 # -----------------------------------------------------------------------------
 
-sub add_specs {
-    my ($spec) = @_;
+sub add_specs_unix {
+	return ' -Dunix=1 -D__unix=1 -D__unix__=1';
+}
+
+sub add_specs_os {
+    my $spec = lc `uname -s`;
+    chomp $spec;
+
     if ($spec eq 'sunos') {
-	return &add_specs ('unix') .
+	return &add_specs_unix .
 	    ' -D__sun__=1 -D__sun=1 -Dsun=1' .
 	    ' -D__svr4__=1 -DSVR4=1' .
 	    ' -D__STDC__=0' .
@@ -257,30 +263,28 @@  sub add_specs {
 	    ' -D_SOLARIS_THREADS' .
 	    ' -DNULL="((void *)0)"';
     } elsif ($spec eq 'linux') {
-	return &add_specs ('unix') .
+	return &add_specs_unix .
 	    ' -D__linux__=1 -D__linux=1 -Dlinux=linux';
     } elsif ($spec eq 'gnu/kfreebsd') {
-	return &add_specs ('unix') .
+	return &add_specs_unix .
 	    ' -D__FreeBSD_kernel__=1';
     } elsif ($spec eq 'openbsd') {
-	return &add_specs ('unix') .
+	return &add_specs_unix .
 	    ' -D__OpenBSD__=1';
     } elsif ($spec eq 'freebsd') {
-	return &add_specs ('unix') .
+	return &add_specs_unix .
 	    ' -D__FreeBSD__=1';
     } elsif ($spec eq 'netbsd') {
-	return &add_specs ('unix') .
+	return &add_specs_unix .
 	    ' -D__NetBSD__=1';
     } elsif ($spec eq 'darwin') {
 	return
 	    ' -D__APPLE__=1 -D__MACH__=1';
     } elsif ($spec eq 'gnu') {		# Hurd
-	return &add_specs ('unix') .	# So, GNU is Unix, uh?
+	return &add_specs_unix .	# So, GNU is Unix, uh?
 	    ' -D__GNU__=1 -D__gnu_hurd__=1 -D__MACH__=1';
-    } elsif ($spec eq 'unix') {
-	return ' -Dunix=1 -D__unix=1 -D__unix__=1';
     } elsif ( $spec =~ /^cygwin/) {
-	return &add_specs ('unix') .
+	return &add_specs_unix .
 	    ' -D__CYGWIN__=1 -D__CYGWIN32__=1' .
 	    " -D'_cdecl=__attribute__((__cdecl__))'" .
 	    " -D'__cdecl=__attribute__((__cdecl__))'" .
@@ -289,7 +293,14 @@  sub add_specs {
 	    " -D'_fastcall=__attribute__((__fastcall__))'" .
 	    " -D'__fastcall=__attribute__((__fastcall__))'" .
 	    " -D'__declspec(x)=__attribute__((x))'";
-    } elsif ($spec eq 'i386') {
+    }
+
+    print "$0: unknown OS: $spec\n" if $verbose;
+}
+
+sub add_specs {
+    my ($spec) = @_;
+    if ($spec eq 'i386') {
 	return (
 		&float_types (1, 1, 21, [24,8], [53,11], [64,15]));
     } elsif ($spec eq 'sparc') {
@@ -333,10 +344,6 @@  sub add_specs {
     } elsif ($spec eq 'aarch64') {
 	return (' -m64' .
 		&float_types (1, 1, 36, [24,8], [53,11], [113,15]));
-    } elsif ($spec eq 'host_os_specs') {
-	my $os = `uname -s`;
-	chomp $os;
-	return &add_specs (lc $os);
     } else {
 	die "$0: invalid specs: $spec\n";
     }