Hi Steven, On 10/04/2013 11:33 PM, Steven Chamberlain wrote: > Hi, > > osgearth fails to build on kfreebsd-* because it tries to directly use a > Linux-specific syscall: > > https://buildd.debian.org/status/package.php?p=osgearth&suite=sid >> cd /«BUILDDIR»/osgearth-2.4.0+dfsg/build/src/osgEarth && /usr/bin/c++ >> -DOSGEARTH_LIBRARY -DQT_CORE_LIB -DQT_GUI_LIB -DQT_NO_DEBUG -DTIXML_USE_STL >> -DosgEarth_EXPORTS -g -O2 -fstack-protector --param=ssp-buffer-size=4 >> -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -O3 -DNDEBUG -fPIC >> -isystem /usr/include/qt4 -isystem /usr/include/qt4/QtGui -isystem >> /usr/include/qt4/QtCore -I/«BUILDDIR»/osgearth-2.4.0+dfsg/src >> -I/usr/include/gdal -I/usr/include/curl -o >> CMakeFiles/osgEarth.dir/ThreadingUtils.cpp.o -c >> /«BUILDDIR»/osgearth-2.4.0+dfsg/src/osgEarth/ThreadingUtils.cpp >> /«BUILDDIR»/osgearth-2.4.0+dfsg/src/osgEarth/ThreadingUtils.cpp: In function >> 'unsigned int osgEarth::Threading::getCurrentThreadId()': >> /«BUILDDIR»/osgearth-2.4.0+dfsg/src/osgEarth/ThreadingUtils.cpp:42:30: >> error: 'SYS_gettid' was not declared in this scope >> return (unsigned)::syscall(SYS_gettid); >> ^ > > osgearth also knows how to use Windows and Mac OS X--specific syscalls > to get a thread ID. This is not portable and there is nothing directly > equivalent on FreeBSD, see: > http://lists.freebsd.org/pipermail/freebsd-hackers/2010-June/031992.html > > A workaround may be to use pthread_self(), except that the exported > getCurrentThreadId function has to return 'unsigned int'. On > kfreebsd-amd64 a 64-bit pointer to a pthread_t is not absolutely > guaranteed to be unique if truncated to 32 bits, but it is extremely > likely, and certainly better than nothing... > > Please refer to attached patch which fixes package build at least. Thanks!
Thanks for the patch. Another option I've looked at is to use the undocumented thr_self(2) syscall, this was recommended over pthread_self() on freebsd-hackers@: http://lists.freebsd.org/pipermail/freebsd-hackers/2010-June/031991.html The attached patch is what I was working on, but it breaks the build even worse than without it. I'll have another go at making my patch work, otherwise I'll apply your patch to at least get the package to build. I had changed the package to linux-any since upstream doesn't support FreeBSD, but that's not really a fix for the problem. Kind Regards, Bas -- GnuPG: 0xE88D4AF1 (new) / 0x77A975AD (old)
Index: osgearth/src/osgEarth/ThreadingUtils.cpp =================================================================== --- osgearth.orig/src/osgEarth/ThreadingUtils.cpp 2013-10-05 00:21:18.000000000 +0200 +++ osgearth/src/osgEarth/ThreadingUtils.cpp 2013-10-05 01:02:46.000000000 +0200 @@ -23,6 +23,9 @@ #else # include <unistd.h> # include <sys/syscall.h> +# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +# include <sys/thr.h> +# endif #endif using namespace osgEarth::Threading; @@ -39,6 +42,12 @@ #elif __APPLE__ return ::syscall(SYS_thread_selfid); #else - return (unsigned)::syscall(SYS_gettid); + if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + long lwpid; + thr_self( &lwpid ); + return (unsigned) lwpid; + else + return (unsigned)::syscall(SYS_gettid); + endif #endif } Index: osgearth/CMakeModules/FindFREEBSD_THR.cmake =================================================================== --- /dev/null 1970-01-01 00:00:00.000000000 +0000 +++ osgearth/CMakeModules/FindFREEBSD_THR.cmake 2013-10-05 00:21:18.000000000 +0200 @@ -0,0 +1,14 @@ +execute_process(COMMAND uname -r OUTPUT_VARIABLE FREEBSD_KERNEL_RELEASE OUTPUT_STRIP_TRAILING_WHITESPACE) + +set(FREEBSD_KERNEL_HEADERS_DIR "/usr/src/kfreebsd-headers-${FREEBSD_KERNEL_RELEASE}/") + +FIND_PATH(FREEBSD_THR_INCLUDE_DIR + NAMES "sys/thr.h" + PATH_SUFFIXES sys + PATHS ${FREEBSD_KERNEL_HEADERS_DIR} +) + +set(FREEBSD_THR_INCLUDE_DIRS ${FREEBSD_THR_INCLUDE_DIR}) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(FREEBSD_THR DEFAULT_MSG FREEBSD_THR_INCLUDE_DIR) +mark_as_advanced(FREEBSD_THR_INCLUDE_DIR) Index: osgearth/CMakeLists.txt =================================================================== --- osgearth.orig/CMakeLists.txt 2013-10-05 00:21:18.000000000 +0200 +++ osgearth/CMakeLists.txt 2013-10-05 00:22:50.000000000 +0200 @@ -196,6 +196,12 @@ #FIND_PACKAGE(GDAL) +FIND_PACKAGE(FREEBSD_THR) + +if(NOT FREEBSD_THR_FOUND) + message(FATAL_ERROR "FreeBSD kernel header sys/thr.h could not be found and is a mandatory dependency") +endif(NOT FREEBSD_THR_FOUND) + ################################################################################ # Create bin and lib directories if required Index: osgearth/src/osgEarth/CMakeLists.txt =================================================================== --- osgearth.orig/src/osgEarth/CMakeLists.txt 2013-10-05 00:21:18.000000000 +0200 +++ osgearth/src/osgEarth/CMakeLists.txt 2013-10-05 02:01:12.000000000 +0200 @@ -236,6 +236,10 @@ INCLUDE_DIRECTORIES(${GDAL_INCLUDE_DIR} ${CURL_INCLUDE_DIR} ${OSG_INCLUDE_DIR} ) +if(FREEBSD_THR_FOUND) + include_directories(${FREEBSD_THR_INCLUDE_DIR}) +endif(FREEBSD_THR_FOUND) + IF (TINYXML_FOUND) INCLUDE_DIRECTORIES(${TINYXML_INCLUDE_DIR}) ENDIF (TINYXML_FOUND)