From d648e92188f6cb6d115a72a834c3d2376eaaa554 Mon Sep 17 00:00:00 2001 From: Georg Sauthoff Date: Tue, 23 Aug 2016 21:13:46 +0200 Subject: [PATCH] fix build on Solaris 10 Solaris 10 is too old for POSIX.2008, thus wcsdup() is missing --- CMakeLists.txt | 10 ++++++++-- README.md | 14 ++++++++++++++ bin/read.cc | 1 + bin/read2.cc | 1 + bin/rep.cc | 2 ++ comp/wcsdup.c | 16 ++++++++++++++++ comp/wcsdup.h | 19 +++++++++++++++++++ config.h.in | 7 +++++++ lib/bsd/bsd.cc | 3 +++ lib/mksh/macro.cc | 2 ++ 10 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 comp/wcsdup.c create mode 100644 comp/wcsdup.h create mode 100644 config.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 5da1198..ab088bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,12 @@ # 2016, Georg Sauthoff -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.0) project(somake C CXX) +include(CheckFunctionExists) +check_function_exists(wcsdup HAVE_WCSDUP) +configure_file(config.h.in config.h) + add_library(mksh STATIC lib/mksh/dosys.cc lib/mksh/globals.cc lib/mksh/i18n.cc lib/mksh/macro.cc lib/mksh/misc.cc lib/mksh/mksh.cc lib/mksh/read.cc @@ -25,12 +29,14 @@ add_executable(${PROJECT_NAME} bin/main.cc bin/misc.cc bin/nse_printdep.cc bin/parallel.cc bin/pmake.cc bin/read.cc bin/read2.cc bin/rep.cc bin/state.cc - comp/progname.c + lib/bsd/bsd.cc + comp/progname.c comp/wcsdup.c ) set_property(TARGET ${PROJECT_NAME} mksh vroot PROPERTY INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} ) target_link_libraries(${PROJECT_NAME} diff --git a/README.md b/README.md index 3715302..887673a 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,11 @@ Although those changes target Linux, they aren't really Linux specific. That means that the ported make should also compile on other modern [POSIXy][posix] operating systems. +So far, the port was successfully tested under: + +- Fedora 23/x86-64 +- Solaris 10/SPARC + ## Naming @@ -306,6 +311,14 @@ differently, e.g.: -- Installing: dest/usr/bin/somake [..] +### Tweaks + +If you are compiling on a legacy platform with ancient libraries +you may need to tweak the cmake call a little bit. For example, +to compile with GCC on a Solaris 10 system: + + $ CC=gcc CXX=g++ LDFLAGS='-lnsl /opt/csw/lib/libintl.so.8' \ + cmake -DCMAKE_BUILD_TYPE=Release ../somake ### Manual Installation @@ -329,6 +342,7 @@ the following order: 5. `/usr/share/lib/make/make.rules` 6. `/etc/default/make.rules` + ## License Perhaps not required by the CDDL, but I license my changes diff --git a/bin/read.cc b/bin/read.cc index 0f99c52..ff7e27f 100644 --- a/bin/read.cc +++ b/bin/read.cc @@ -44,6 +44,7 @@ #include #include +#include /* * typedefs & structs diff --git a/bin/read2.cc b/bin/read2.cc index 2abab50..595e8e2 100644 --- a/bin/read2.cc +++ b/bin/read2.cc @@ -40,6 +40,7 @@ #include #include +#include /* * Defined macros diff --git a/bin/rep.cc b/bin/rep.cc index f0cb9e1..b907e94 100644 --- a/bin/rep.cc +++ b/bin/rep.cc @@ -36,6 +36,8 @@ #include /* retmem() */ #include /* NSE_DEPINFO */ +#include + /* * Static variables */ diff --git a/comp/wcsdup.c b/comp/wcsdup.c new file mode 100644 index 0000000..98b6c98 --- /dev/null +++ b/comp/wcsdup.c @@ -0,0 +1,16 @@ +// 2016, Georg Sauthoff , CDDL and WTFPL +#include "wcsdup.h" + +#ifndef HAVE_WCSDUP + + #include + + // this function is part of POSIX.2008 + wchar_t * wcsdup(const wchar_t *s) + { + size_t n = wcslen(s) + 1; + wchar_t r = malloc(n * sizeof(wchar_t)); + return r ? return wmemcpy(r, s, n) : 0; +} + +#endif diff --git a/comp/wcsdup.h b/comp/wcsdup.h new file mode 100644 index 0000000..222e511 --- /dev/null +++ b/comp/wcsdup.h @@ -0,0 +1,19 @@ +// 2016, Georg Sauthoff , CDDL +#ifndef COMPAT_WCSDUP_H +#define COMPAT_WCSDUP_H + +#include + +#include "config.h" + +#ifndef HAVE_WCSDUP + #if defined(__cplusplus) + extern "C" { + #endif + wchar_t * wcsdup (const wchar_t *s); + #if defined(__cplusplus) + } + #endif +#endif + +#endif diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..07c409d --- /dev/null +++ b/config.h.in @@ -0,0 +1,7 @@ +// 2016, Georg Sauthoff , CDDL and WTFPL +#ifndef SOMAKE_CONFIG_H +#define SOMAKE_CONFIG_H + +#cmakedefine HAVE_WCSDUP 1 + +#endif diff --git a/lib/bsd/bsd.cc b/lib/bsd/bsd.cc index 931a528..d975691 100644 --- a/lib/bsd/bsd.cc +++ b/lib/bsd/bsd.cc @@ -23,6 +23,7 @@ * Use is subject to license terms. */ +#if defined(__sun) #include @@ -71,3 +72,5 @@ bsd_signals (void) return; } + +#endif diff --git a/lib/mksh/macro.cc b/lib/mksh/macro.cc index b815105..4c01e68 100644 --- a/lib/mksh/macro.cc +++ b/lib/mksh/macro.cc @@ -41,6 +41,8 @@ #include +#include + /* * File table of contents */