Skip to content

Commit 9808a3f

Browse files
isurufkiranchandramohan
authored andcommitted
Support MacOS
- Check for clock_settime before using it - use __fenv_feenableexcept() from flt_env.c instead of feenableexcept() since it doesn't exist on macOS - Use POSIX limits.h - no rt for macos - Enable macos support - don't declare bzero() as it's likely a macro - Remove bad strcpy declaration
1 parent 697efdc commit 9808a3f

File tree

8 files changed

+25
-9
lines changed

8 files changed

+25
-9
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ endif()
3030
if( ${TARGET_OS} STREQUAL "Linux" )
3131
set(OS "LINUX")
3232
set(OSNAME "Linux")
33+
elseif( ${TARGET_OS} STREQUAL "Darwin" )
34+
set(OS "OSX")
35+
set(OSNAME "macOS")
3336
else()
3437
message("Unsupported OS: ${TARGET_OS}" )
3538
return()

runtime/flang/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ endif ()
1919
# flang* executables
2020
SET(CMAKE_Fortran_FLAGS "-B ${LLVM_RUNTIME_OUTPUT_INTDIR} ${CMAKE_Fortran_FLAGS}")
2121

22+
include(CheckSymbolExists)
23+
check_symbol_exists(clock_settime "time.h" HAVE_CLOCK_SETTIME)
24+
configure_file(libflang_config.h.in libflang_config.h)
25+
2226
SET(FTN_INTRINSICS_DESC_INDEP
2327
abort3f.c
2428
access3f.c
@@ -508,10 +512,12 @@ add_dependencies(flang_shared flang_static)
508512

509513
target_link_libraries(flang_shared flangrti_shared)
510514
# Resolve symbols against libm and librt
511-
if (NOT MSVC)
512-
target_link_libraries(flang_shared m rt)
513-
else()
515+
if (MSVC)
514516
set_target_properties(flang_shared PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
517+
elseif (APPLE)
518+
target_link_libraries(flang_shared m)
519+
else()
520+
target_link_libraries(flang_shared m rt)
515521
endif()
516522

517523
set(SHARED_LIBRARY FALSE)

runtime/flang/global.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ typedef char sbool; /* short boolean (for use in large structs) */
8181
#define assert(ex)
8282
#endif
8383

84-
extern char *strcpy();
8584
#define STASH(str) (strcpy((char *)malloc(strlen(str) + 1), str))
8685

8786
/* defs used by __fortio_error */

runtime/flang/libflang_config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#ifndef LIBFLANG_CONFIG_H
2+
#define LIBFLANG_CONFIG_H
3+
#cmakedefine HAVE_CLOCK_SETTIME
4+
#endif

runtime/flang/stime3f.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
/* stime3f.c - Implements LIB3F stime subprogram. */
1111

12-
#ifndef WINNT
13-
12+
#include "libflang_config.h"
1413
#include <time.h>
1514
#include "io3f.h"
1615
#include "ent3f.h"
1716

17+
#ifdef HAVE_CLOCK_SETTIME
18+
1819
int ENT3F(STIME, stime)(int *tp)
1920
{
2021
int i;
@@ -27,4 +28,4 @@ int ENT3F(STIME, stime)(int *tp)
2728
return i;
2829
}
2930

30-
#endif /* !WINNT */
31+
#endif /* HAVE_CLOCK_SETTIME */

runtime/flangrti/ktrap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ __ktrap(void)
5050
excepts |= FE_UNDERFLOW;
5151
if (bv & 0x100)
5252
excepts |= FE_INEXACT;
53+
#ifdef TARGET_OSX
54+
__fenv_feenableexcept(excepts);
55+
#else
5356
feenableexcept(excepts); /* glibc 2.2 extension to fenv.h */
57+
#endif
5458
}
5559
}
5660
}

runtime/flangrti/trace_lin.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#else
1414
#include <execinfo.h>
1515
#include <unistd.h>
16-
#include <linux/limits.h>
16+
#include <limits.h>
1717
#include <sys/types.h>
1818
#endif
1919
#include <stdioInterf.h>

tools/flang1/flang1exe/gbldefs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ char *mkfname(const char *, const char *, const char *); /* from miscutil.c: */
162162
bool is_xflag_bit(int);
163163
void set_xflag(int, INT);
164164
void set_yflag(int, INT);
165-
void bzero(void *, size_t);
166165
void list_init(FILE *); /* listing.c: */
167166
void list_line(const char *); /* listing.c */
168167
void list_page(void); /* listing.c */

0 commit comments

Comments
 (0)