From 3f88273d0ff229f6baffffe7e25b4982af9f951d Mon Sep 17 00:00:00 2001
From: Andrew Johnson
Date: Mon, 8 Sep 2014 17:57:18 -0500
Subject: [PATCH] Linux builds: Define _GNU_SOURCE and _DEFAULT_SOURCE
These replace the mixture of macros used to pick the features
presented by the standard system header files on Linux.
Updated the section of the CA reference manual that showed some
example compile lines to correct for 3.15 build changes.
Removed unused code & out-of-date comments.
---
configure/os/CONFIG.Common.linuxCommon | 9 ++---
src/ca/client/CAref.html | 48 ++++++++++++++------------
src/libCom/osi/os/Linux/osdSock.h | 11 ------
src/libCom/osi/os/posix/osdThread.c | 12 -------
4 files changed, 28 insertions(+), 52 deletions(-)
diff --git a/configure/os/CONFIG.Common.linuxCommon b/configure/os/CONFIG.Common.linuxCommon
index a230d1734..98ee158e9 100644
--- a/configure/os/CONFIG.Common.linuxCommon
+++ b/configure/os/CONFIG.Common.linuxCommon
@@ -12,17 +12,14 @@ include $(CONFIG)/os/CONFIG.Common.UnixCommon
OS_CLASS = Linux
-CODE_CPPFLAGS = -D_REENTRANT
-
-POSIX_CPPFLAGS = -D_POSIX_C_SOURCE=200112L -D_POSIX_THREADS -D_XOPEN_SOURCE=500
+# Define _GNU_SOURCE and _DEFAULT_SOURCE for maximum portability
+POSIX_CPPFLAGS = -D_GNU_SOURCE -D_DEFAULT_SOURCE
POSIX_LDLIBS = -lpthread
-# -D_BSD_SOURCE for gethostname() in unistd.h as needed by cacChannelIO.cpp.
-OP_SYS_CPPFLAGS += -D_BSD_SOURCE
OP_SYS_CPPFLAGS += -Dlinux
OP_SYS_LDLIBS += -lrt -ldl
-# Added here for cross-target builds which include this file
+# Linker flags for static & shared-library builds
STATIC_LDFLAGS_YES= -Wl,-Bstatic
STATIC_LDFLAGS_NO=
STATIC_LDLIBS_YES= -Wl,-Bdynamic
diff --git a/src/ca/client/CAref.html b/src/ca/client/CAref.html
index 98dbdd5e5..c198ed56a 100644
--- a/src/ca/client/CAref.html
+++ b/src/ca/client/CAref.html
@@ -959,53 +959,55 @@ base>/lib/<architechture>".
-If you do not use the EPICS build environemnt (layered make files) then it
+
If you do not use the EPICS build environment (layered make files) then it
may be helpful to run one of the EPICS make files and watch the compile/link
lines. This may be the simplest way to capture the latest system and compiler
-specific options required by your build environment. I have included some
-snapshots of typical build lines below, but expect some risk of this
-information becoming dated.
+specific options required by your build environment. Some snapshots of typical
+build lines are shown below, but this information may be out of date.
Typical Linux Build Options
-/usr/bin/gcc -c -D_POSIX_C_SOURCE=199506L -D_POSIX_THREADS
--D_XOPEN_SOURCE=500 -DOSITHREAD_USE_DEFAULT_STACK -D_X86_ -DUNIX -D_BSD_SOURCE
--Dlinux -D_REENTRANT -ansi -O3 -Wall -I. -I.. -I../../../include/os/Linux
--I../../../include ../acctst.c
+gcc -D_GNU_SOURCE -DOSITHREAD_USE_DEFAULT_STACK -D_X86_ -DUNIX -Dlinux
+-O3 -g -Wall -I. -I.. -I../../../../include/compiler/gcc
+-I../../../../include/os/Linux -I../../../../include -c ../acctst.c
-/usr/bin/g++ -o acctst
--L/home/user/epicsR3.14/epics/base/lib/linux-x86/
--Wl,-rpath,/mnt/bogart_home/hill/epicsR3.14/epics/base/lib/linux-x86
+g++ -o acctst -L/home/user/epics/base-3.15/lib/linux-x86
+-Wl,-rpath,/home/user/epics/base-3.15/lib/linux-x86
acctstMain.o acctst.o -lca -lCom
Typical Solaris Build Options
/opt/SUNWspro/bin/cc -c -D_POSIX_C_SOURCE=199506L -D_XOPEN_SOURCE=500
-DOSITHREAD_USE_DEFAULT_STACK -DUNIX -DSOLARIS=9 -mt -D__EXTENSIONS__ -Xc -v
--xO4 -I. -I.. -I./../../../include/os/solaris -I./../../../include
-../acctst.c
+-xO4 -I. -I.. -I../../../../include/compiler/solStudio
+-I../../../../include/os/solaris -I../../../../include ../acctst.c
/opt/SUNWspro/bin/CC -o acctst
--L/home/phoebus1/JHILL/epics/base/lib/solaris-sparc/ -mt -z ignore -z combreloc
--z lazyload -R/home/disk1/user/epics/base/lib/solaris-sparc acctstMain.o
+-L/home/user/epics/base-3.15/lib/solaris-sparc/ -mt -z ignore -z combreloc
+-z lazyload -R/home/user/epics/base-3.15/lib/solaris-sparc acctstMain.o
acctst.o -lca -lCom
Typical Windows Build Options
cl -c /nologo /D__STDC__=0 /Ox /GL /W3 /w44355 /MD -I. -I..
--I..\\..\\..\\include\\os\\WIN32 -I..\\..\\..\\include ..\\acctst.c
+-I..\\..\\..\\..\\include\\compiler\\msvc -I..\\..\\..\\..\\include\\os\\WIN32
+-I..\\..\\..\\..\\include ..\\acctst.c
-link -nologo /LTCG /incremental:no /opt:ref /release /version:3.14
+link -nologo /LTCG /incremental:no /opt:ref /release /version:3.15
-out:acctst.exe acctstMain.obj acctst.obj
-d:/user/R3.14.clean/epics/base/lib/WIN32-x86/ca.lib
-d:/user/R3.14.clean/epics/base/lib/WIN32-x86/
+d:/user/epics/base-3.15/lib/win32-x86/ca.lib
+d:/user/epics/base-3.15/lib/win32-x86/Com.lib
Typical vxWorks Build Options
-/usr/local/xcomp/ppc/bin/ccppc -c -D_POSIX_SOURCE -DCPU=PPC603
--DvxWorks -include /home/vx/tornado20/target/h/vxWorks.h -ansi -O3 -Wall
--mcpu=603 -mstrict-align -fno-builtin -I. -I.. -I../../../include/os/vxWorks
--I../../../include -I/home/vx/tornado20/target/h ../acctst.c
+/usr/local/vxWorks-6.9/gnu/4.3.3-vxworks-6.9/x86-linux2/bin/ccppc
+-DCPU=PPC32 -DvxWorks=vxWorks -O2 -Wall -mstrict-align -mlongcall -fno-builtin
+-include /usr/local/vxWorks-6.9/vxworks-6.9/target/h/vxWorks.h
+-I. -I../O.Common -I.. -I../../../../include/compiler/gcc
+-I../../../../include/os/vxWorks -I../../../../include
+-I/usr/local/vxWorks-6.9/vxworks-6.9/target/h
+-I/usr/local/vxWorks-6.9/vxworks-6.9/target/h/wrn/coreip
+-c ../acctst.c
Other Systems and Compilers
diff --git a/src/libCom/osi/os/Linux/osdSock.h b/src/libCom/osi/os/Linux/osdSock.h
index e689526eb..bb1665adc 100644
--- a/src/libCom/osi/os/Linux/osdSock.h
+++ b/src/libCom/osi/os/Linux/osdSock.h
@@ -9,17 +9,6 @@
/*
* Linux specific socket include
- *
- * Under Linux if we dont define _POSIX_C_SOURCE or _XOPEN_SOURCE
- * then none of the POSIX stuff (such as signals) can be used
- * with cc -v. However if one of _POSIX_C_SOURCE or _XOPEN_SOURCE
- * are defined then we cant use the socket library. Therefore I
- * have been adding the following in order to use POSIX signals
- * and also sockets on Linux with cc -v. What a pain....
- *
- * #ifdef linux
- * #define __EXTENSIONS__
- * #endif
*/
#ifndef osdSockH
diff --git a/src/libCom/osi/os/posix/osdThread.c b/src/libCom/osi/os/posix/osdThread.c
index 90e8de7c3..f9bea4b7d 100644
--- a/src/libCom/osi/os/posix/osdThread.c
+++ b/src/libCom/osi/os/posix/osdThread.c
@@ -527,17 +527,6 @@ epicsShareFunc epicsThreadId epicsShareAPI epicsThreadCreate(const char *name,
return(pthreadInfo);
}
-/*
- * Cleanup routine for threads not created by epicsThreadCreate().
- */
-/* static void nonEPICSthreadCleanup(void *arg)
-{
- epicsThreadOSD *pthreadInfo = (epicsThreadOSD *)arg;
-
- free(pthreadInfo->name);
- free(pthreadInfo);
-} */
-
/*
* Create dummy context for threads not created by epicsThreadCreate().
*/
@@ -570,7 +559,6 @@ static epicsThreadOSD *createImplicit(void)
free_threadInfo(pthreadInfo);
return NULL;
}
-/* pthread_cleanup_push(nonEPICSthreadCleanup, pthreadInfo); */
return pthreadInfo;
}