On 13 Nov 2023, at 16:18, Arnaud Charlet <char...@adacore.com> wrote:
> 
>>>>> OK, I thought there would be some defines that we could use for that, too 
>>>>> bad if there isn't
>>>>> and indeed we might need to perform another runtime check then as 
>>>>> suggested by Iain.
>>>> 
>>>> I can see a possible interface, operatingSystemVersion in NSProcessInfo.h 
>>>> - Objective C
>>>> needed, I think
>>> 
>>> Some of the NS interfaces are available to regular C (e.g. stuff in 
>>> CoreFoundation), and I am
>>> fairly/very sure that we will be able to find a machanism that does not 
>>> involve introducing an
>>> ObjC dep.  [I am obvioulsy not in any way against ObjC - since i’m the 
>>> maintainer ;) .. but it
>>> seems heavyweight for solving this issue].
>> 
>> It certainly would be heavyweight, since TargetConditionals.h includes 
>> TARGET_OS_OSX, 
>> which is 1 if we’re compiling for macOS and 0 otherwise (there’s a useful 
>> chart at :83 in the 
>> MacOSX13.1 SDK).
>> 
>> Two ways ahead here:
>> (1) just replace the current __arm__, __arm64__ test with this
> 
> That would be fine here (replace refs to *arm* by TARGET_OS_OSX), since this 
> was my original
> suggestion (copied at the top of this email).
> 
>> (2) as 1, but implement the runtime test for case sensitivity only for macOS
>> 
>> Whether (2) is acceptable depends, I suppose, on what issues Iain 
>> encountered on Darwin 9 
>> & Darwin 17. I’ll be content to go with (1).

I'm not sure whether this should have been a new [PATCH V2] thread?

Also, should the test code below (between %%%) be included in the
testsuite?

--8<--

In gcc/ada/adaint.c(__gnat_get_file_names_case_sensitive), the
current assumption for __APPLE__ is that file names are
case-insensitive unless __arm__ or __arm64__ are defined, in which
case file names are declared case-sensitive.

The associated comment is
  "By default, we suppose filesystems aren't case sensitive on
  Windows and Darwin (but they are on arm-darwin)."

This means that on aarch64-apple-darwin, file names are treated as
case-sensitive, which is not the default case.

Apple provide a header file <TargetConditionals.h> which permits a
compile-time check for the compiler target (e.g. OSX vs IOS). At Darwin
10.5 (Xcode 3) iOS wasn't supported, so it was adequate to check
TARGET_OS_MAC; nowadays, that covers many variants including macOS
and iOS, so one needs to check whether TARGET_OS_OSX is defined, and
if so whether it's set.

Bootstrapped on x86_64-apple-darwin with languages c,c++,ada and regression
tested (check-ada).

Likewise bootstrapped on aarch64-apple-darwin from the Github sources
corresponding to GCC 2023-11-05.

__gnat_get_file_names_case_sensitive() isn't exported to user code, so
implemented check code as below: each compiler (x86_64-apple-darwin and
aarch64-apple-darwin) reported that file names were not case sensitive.

%%%
with Ada.Text_IO;
with Interfaces.C;
procedure Check_Case_Sensitivity is
   type C_Boolean is (False, True)
     with Convention => C;
   function Get_File_Names_Case_Sensitive return C_Boolean
   with
     Import,
     Convention => C,
     External_Name => "__gnat_get_file_names_case_sensitive";
begin
   Ada.Text_IO.Put_Line ("GNAT thinks file names are " &
                           (case Get_File_Names_Case_Sensitive is
                               when False => "not case sensitive",
                               when True  => "case sensitive"));
end Check_Case_Sensitivity;
%%%

gcc/ada/Changelog:

2023-11-16 Simon Wright <si...@pushface.org>

  * gcc/ada/adaint.c
  (__gnat_get_file_names_case_sensitive): Split out the __APPLE__
  check and remove the checks for __arm__, __arm64__.
  File names are by default case sensitive unless TARGET_OS_OSX
  (or if this is an older OS release, in which case TARGET_OS_OSX
  is undefined, TARGET_OS_MAC) is set.

Signed-off-by: Simon Wright <si...@pushface.org>
---
 gcc/ada/adaint.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
index bb4ed2607e5..1ef529ec20b 100644
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -84,7 +84,7 @@
 #endif /* VxWorks */
 
 #if defined (__APPLE__)
-#include <unistd.h>
+#include <TargetConditionals.h>
 #endif
 
 #if defined (__hpux__)
@@ -613,12 +613,25 @@ __gnat_get_file_names_case_sensitive (void)
       else
        {
          /* By default, we suppose filesystems aren't case sensitive on
-            Windows and Darwin (but they are on arm-darwin).  */
-#if defined (WINNT) || defined (__DJGPP__) \
-  || (defined (__APPLE__) && !(defined (__arm__) || defined (__arm64__)))
+            Windows or DOS.  */
+#if defined (WINNT) || defined (__DJGPP__)
+         file_names_case_sensitive_cache = 0;
+#elif defined (__APPLE__)
+         /* By default, macOS volumes are case-insensitive, iOS
+            volumes are case-sensitive.  */
+#if defined (TARGET_OS_OSX)      /* In recent SDK.  */
+#if TARGET_OS_OSX                /* macOS.  */   
          file_names_case_sensitive_cache = 0;
 #else
          file_names_case_sensitive_cache = 1;
+#endif
+#elif TARGET_OS_MAC    /* macOS, in older SDK.  */
+         file_names_case_sensitive_cache = 0;
+#else
+         file_names_case_sensitive_cache = 1;
+#endif
+#else /* Neither Windows nor Apple.  */
+         file_names_case_sensitive_cache = 1;
 #endif
        }
     }
-- 
2.39.3 (Apple Git-145)

Reply via email to