From 84603d804c285c75f4bf81f9d79f0ebd0ca68fea Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 3 Mar 2014 15:47:08 +0100 Subject: [PATCH] Haiku: Enable CMake builtin ELF editor Co-Author: Brad King --- Source/CMakeLists.txt | 18 ++++++++++++++++++ Source/cmELF.cxx | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 762470fc2..27d099d40 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -18,6 +18,23 @@ else() endif() if(HAVE_ELF_H) set(CMAKE_USE_ELF_PARSER 1) +elseif(HAIKU) + # On Haiku, we need to include elf32.h from the private headers + set(CMake_HAIKU_INCLUDE_DIRS + /boot/system/develop/headers/private/system + /boot/system/develop/headers/private/system/arch/x86 + ) + + set(CMAKE_REQUIRED_INCLUDES ${CMake_HAIKU_INCLUDE_DIRS}) + CHECK_INCLUDE_FILE("elf32.h" HAVE_ELF32_H) + unset(CMAKE_REQUIRED_INCLUDES) + + if(HAVE_ELF32_H) + set(CMAKE_USE_ELF_PARSER 1) + else() + unset(CMake_HAIKU_INCLUDE_DIRS) + set(CMAKE_USE_ELF_PARSER) + endif() else() set(CMAKE_USE_ELF_PARSER) endif() @@ -57,6 +74,7 @@ include_directories( ${CMAKE_EXPAT_INCLUDES} ${CMAKE_TAR_INCLUDES} ${CMAKE_COMPRESS_INCLUDES} + ${CMake_HAIKU_INCLUDE_DIRS} ) # let cmake know it is supposed to use it diff --git a/Source/cmELF.cxx b/Source/cmELF.cxx index bc1c25ba1..dc6772c1b 100644 --- a/Source/cmELF.cxx +++ b/Source/cmELF.cxx @@ -23,6 +23,26 @@ #if defined(__OpenBSD__) # include # include +#elif defined(__HAIKU__) +# include +# include + typedef struct Elf32_Ehdr Elf32_Ehdr; + typedef struct Elf32_Shdr Elf32_Shdr; + typedef struct Elf32_Sym Elf32_Sym; + typedef struct Elf32_Rel Elf32_Rel; + typedef struct Elf32_Rela Elf32_Rela; +# define ELFMAG0 0x7F +# define ELFMAG1 'E' +# define ELFMAG2 'L' +# define ELFMAG3 'F' +# define ET_NONE 0 +# define ET_REL 1 +# define ET_EXEC 2 +# define ET_DYN 3 +# define ET_CORE 4 +# define EM_386 3 +# define EM_SPARC 2 +# define EM_PPC 20 #else # include #endif