diff --git a/CMakeLists.txt b/CMakeLists.txt index 419c7abd9be..e2b71d974ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,20 @@ if( ${TARGET_OS} STREQUAL "Linux" ) message("Unsupported architecture: ${TARGET_ARCHITECTURE}" ) return() endif() +elseif( ${TARGET_OS} STREQUAL "OpenBSD") + set(OS "OPENBSD") + set(OSNAME "OpenBSD") + if ( ${TARGET_ARCHITECTURE} STREQUAL "amd64" ) + set(ARCHNAME x86-64) + set(ARCH X86) + set(WRDSZ 64) + set(TARGET_ARCHITECTURE x86_64) + elseif( ${TARGET_ARCHITECTURE} STREQUAL "arm64" ) + set(ARCHNAME aarch64) + set(ARCH ARM) + set(WRDSZ 64) + set(TARGET_ARCHITECTURE aarch64) + endif() else() message("Unsupported OS: ${TARGET_OS}" ) return() diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index d8285d1fc7a..098e56f5de0 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -29,6 +29,13 @@ add_definitions( -DPGI_LITTLE_ENDIAN ) +if( ${TARGET_OS} STREQUAL "OpenBSD" ) + add_definitions( + -DTARGET_OPENBSD + -DOPENBSD + } +endif() + if( ${TARGET_ARCHITECTURE} STREQUAL "x86_64" ) add_definitions( -DTARGET_X8664 diff --git a/runtime/flang/CMakeLists.txt b/runtime/flang/CMakeLists.txt index c4300b9b2e7..0e928575e04 100644 --- a/runtime/flang/CMakeLists.txt +++ b/runtime/flang/CMakeLists.txt @@ -420,7 +420,7 @@ set(I8_FILES_DIR I8_sources) # Fortran files with macros as module names need to be preprocessed. add_custom_command( OUTPUT "${I8_FILES_DIR}/ieee_arithmetic.F95" - COMMAND "${CMAKE_C_COMPILER}" -E + COMMAND "${CMAKE_C_COMPILER}" -E -x c "${CMAKE_CURRENT_SOURCE_DIR}/ieee_arithmetic.F95" -DDESC_I8 > "${I8_FILES_DIR}/ieee_arithmetic.F95" COMMENT "Preprocessing ieee_arithmetic.F95" @@ -429,7 +429,7 @@ add_custom_command( add_custom_command( OUTPUT "${I8_FILES_DIR}/ieee_exceptions.F95" - COMMAND "${CMAKE_C_COMPILER}" -E + COMMAND "${CMAKE_C_COMPILER}" -E -x c "${CMAKE_CURRENT_SOURCE_DIR}/ieee_exceptions.F95" -DDESC_I8 > "${I8_FILES_DIR}/ieee_exceptions.F95" COMMENT "Preprocessing ieee_exceptions.F95" diff --git a/runtime/flangrti/CMakeLists.txt b/runtime/flangrti/CMakeLists.txt index 5f868afd3fe..2096e8d6531 100644 --- a/runtime/flangrti/CMakeLists.txt +++ b/runtime/flangrti/CMakeLists.txt @@ -113,6 +113,11 @@ find_library( HINTS ${CMAKE_BINARY_DIR}/lib) target_link_libraries(flangrti_shared ${LIBPGMATH}) +# BSDs need libexecinfo +if( ${TARGET_OS} STREQUAL "OpenBSD" ) + target_link_libraries(flangrti_shared ${FLANG_LIBEXECINFO}) +endif() + if( ${TARGET_ARCHITECTURE} STREQUAL "aarch64" ) target_compile_definitions(flangrti_static PRIVATE TARGET_LINUX_ARM) target_compile_definitions(flangrti_shared PRIVATE TARGET_LINUX_ARM) diff --git a/runtime/flangrti/aarch64-Linux/dumpregs.c b/runtime/flangrti/aarch64-Linux/dumpregs.c index 53eae37ceee..0e01806c908 100644 --- a/runtime/flangrti/aarch64-Linux/dumpregs.c +++ b/runtime/flangrti/aarch64-Linux/dumpregs.c @@ -15,6 +15,7 @@ * */ +#ifndef TARGET_OPENBSD #include void @@ -29,3 +30,17 @@ getRegs(ucontext_t *u) return (gregset_t *)0; } +#else + +void +dumpregs(void *regs) +{ +} + +void * +getRegs(void *u) +{ + return (void *)0; +} + +#endif diff --git a/runtime/flangrti/dumpregs.h b/runtime/flangrti/dumpregs.h index ef84a58ed0e..fec640b0c26 100644 --- a/runtime/flangrti/dumpregs.h +++ b/runtime/flangrti/dumpregs.h @@ -21,6 +21,14 @@ * Declare routines that access the machine registers */ +#ifndef TARGET_OPENBSD + void dumpregs(gregset_t *regs); gregset_t *getRegs(ucontext_t *u); +#else + +void dumpregs(void *regs); +void *getRegs(ucontext_t *u); + +#endif diff --git a/runtime/flangrti/x86_64-Linux/dumpregs.c b/runtime/flangrti/x86_64-Linux/dumpregs.c index 1b5e147b329..f66f82bc90a 100644 --- a/runtime/flangrti/x86_64-Linux/dumpregs.c +++ b/runtime/flangrti/x86_64-Linux/dumpregs.c @@ -15,7 +15,7 @@ * */ -#if !defined(TARGET_WIN) +#if !defined(TARGET_WIN) && !defined(TARGET_OPENBSD) #include #endif #include "stdioInterf.h" @@ -40,7 +40,7 @@ #define RSP 15 #define RIP 16 -#if defined(TARGET_OSX) || defined(TARGET_WIN) +#if defined(TARGET_OSX) || defined(TARGET_WIN) || defined(TARGET_OPENBSD) /* no gregs and/or ucontext defined in for OSX or Windows */ void * getRegs(void *u) diff --git a/tools/flang2/CMakeLists.txt b/tools/flang2/CMakeLists.txt index ef8837c241d..a30aa299750 100644 --- a/tools/flang2/CMakeLists.txt +++ b/tools/flang2/CMakeLists.txt @@ -38,6 +38,11 @@ if( ${TARGET_OS} STREQUAL "Linux" ) set(X86_64 ON) set(LINUX86 ON) endif() +if( ${TARGET_OS} STREQUAL "OpenBSD" ) + if( ${TARGET_ARCHITECTURE} STREQUAL "x86_64" ) + set(X86_64 ON) + set(LINUX86 ON) + endif() endif() add_subdirectory(include) diff --git a/tools/flang2/flang2exe/CMakeLists.txt b/tools/flang2/flang2exe/CMakeLists.txt index 962a43e1428..2db7327c436 100644 --- a/tools/flang2/flang2exe/CMakeLists.txt +++ b/tools/flang2/flang2exe/CMakeLists.txt @@ -28,6 +28,12 @@ elseif( ${TARGET_ARCHITECTURE} STREQUAL "ppc64le" ) ) endif() +if( ${TARGET_OS} STREQUAL "Linux" ) + set(TARGET_CLASS "Linux") +elseif( ${TARGET_OS} STREQUAL "OpenBSD" ) + set(TARGET_CLASS "Linux") +endif() + set(SOURCES ${ARCH_DEP_FILES} @@ -101,7 +107,7 @@ set(INCLUDE_DIRS ${FLANG_SOURCE_DIR}/lib/scutil ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_ARCHITECTURE}-${TARGET_OS} + ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_ARCHITECTURE}-${TARGET_CLASS} ${UTILS_SYMTAB_BIN_DIR} # Symbol table headers ${UTILS_ILI_BIN_DIR} # ILI IR headers ${UTILS_ILM_BIN_DIR} # ILM IR headers