This commit is contained in:
Michael Davidsaver
2013-03-24 13:32:56 -04:00
commit e7b7bee395
19 changed files with 426 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
*.pyc
*.pyo
*~
O.*
bin
include
lib
db
dbd

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
#Makefile at top of application tree
TOP = .
include $(TOP)/configure/CONFIG
DIRS := $(DIRS) $(filter-out $(DIRS), configure)
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard *App))
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard iocBoot))
define DIR_template
$(1)_DEPEND_DIRS = configure
endef
$(foreach dir, $(filter-out configure,$(DIRS)),$(eval $(call DIR_template,$(dir))))
iocBoot_DEPEND_DIRS += $(filter %App,$(DIRS))
include $(TOP)/configure/RULES_TOP

29
configure/CONFIG Normal file
View File

@ -0,0 +1,29 @@
# CONFIG - Load build configuration data
#
# Do not make changes to this file!
# Allow user to override where the build rules come from
RULES = $(EPICS_BASE)
# RELEASE files point to other application tops
include $(TOP)/configure/RELEASE
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH).Common
ifdef T_A
-include $(TOP)/configure/RELEASE.Common.$(T_A)
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH).$(T_A)
endif
CONFIG = $(RULES)/configure
include $(CONFIG)/CONFIG
# Override the Base definition:
INSTALL_LOCATION = $(TOP)
# CONFIG_SITE files contain other build configuration settings
include $(TOP)/configure/CONFIG_SITE
-include $(TOP)/configure/CONFIG_SITE.$(EPICS_HOST_ARCH).Common
ifdef T_A
-include $(TOP)/configure/CONFIG_SITE.Common.$(T_A)
-include $(TOP)/configure/CONFIG_SITE.$(EPICS_HOST_ARCH).$(T_A)
endif

33
configure/CONFIG_SITE Normal file
View File

@ -0,0 +1,33 @@
# CONFIG_SITE
# Make any application-specific changes to the EPICS build
# configuration variables in this file.
#
# Host/target specific settings can be specified in files named
# CONFIG_SITE.$(EPICS_HOST_ARCH).Common
# CONFIG_SITE.Common.$(T_A)
# CONFIG_SITE.$(EPICS_HOST_ARCH).$(T_A)
# CHECK_RELEASE controls the consistency checking of the support
# applications pointed to by the RELEASE* files.
# Normally CHECK_RELEASE should be set to YES.
# Set CHECK_RELEASE to NO to disable checking completely.
# Set CHECK_RELEASE to WARN to perform consistency checking but
# continue building anyway if conflicts are found.
CHECK_RELEASE = YES
# Set this when you only want to compile this application
# for a subset of the cross-compiled target architectures
# that Base is built for.
#CROSS_COMPILER_TARGET_ARCHS = vxWorks-68040
# To install files into a location other than $(TOP) define
# INSTALL_LOCATION here.
#INSTALL_LOCATION=</path/name/to/install/top>
# Set this when your IOC and the host use different paths
# to access the application. This will be needed to boot
# from a Microsoft FTP server or with some NFS mounts.
# You must rebuild in the iocBoot directory for this to
# take effect.
#IOCS_APPL_TOP = </IOC/path/to/application/top>

8
configure/Makefile Normal file
View File

@ -0,0 +1,8 @@
TOP=..
include $(TOP)/configure/CONFIG
TARGETS = $(CONFIG_TARGETS)
CONFIGS += $(subst ../,,$(wildcard $(CONFIG_INSTALLS)))
include $(TOP)/configure/RULES

32
configure/RELEASE Normal file
View File

@ -0,0 +1,32 @@
# RELEASE - Location of external support modules
#
# IF YOU MAKE ANY CHANGES to this file you must subsequently
# do a "gnumake rebuild" in this application's top level
# directory.
#
# The build process does not check dependencies against files
# that are outside this application, thus you should do a
# "gnumake rebuild" in the top level directory after EPICS_BASE
# or any other external module pointed to below is rebuilt.
#
# Host- or target-specific settings can be given in files named
# RELEASE.$(EPICS_HOST_ARCH).Common
# RELEASE.Common.$(T_A)
# RELEASE.$(EPICS_HOST_ARCH).$(T_A)
#
# This file should ONLY define paths to other support modules,
# or include statements that pull in similar RELEASE files.
# Build settings that are NOT module paths should appear in a
# CONFIG_SITE file.
TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
# If using the sequencer, point SNCSEQ at its top directory:
#SNCSEQ=$(EPICS_BASE)/../modules/soft/seq
# EPICS_BASE usually appears last so other apps can override stuff:
EPICS_BASE=/home/mdavidsaver/work/epics/epics-git
# Set RULES here if you want to take build rules from somewhere
# other than EPICS_BASE:
#RULES=/path/to/epics/support/module/rules/x-y

6
configure/RULES Normal file
View File

@ -0,0 +1,6 @@
# RULES
include $(CONFIG)/RULES
# Library should be rebuilt because LIBOBJS may have changed.
$(LIBNAME): ../Makefile

2
configure/RULES.ioc Normal file
View File

@ -0,0 +1,2 @@
#RULES.ioc
include $(CONFIG)/RULES.ioc

2
configure/RULES_DIRS Normal file
View File

@ -0,0 +1,2 @@
#RULES_DIRS
include $(CONFIG)/RULES_DIRS

3
configure/RULES_TOP Normal file
View File

@ -0,0 +1,3 @@
#RULES_TOP
include $(CONFIG)/RULES_TOP

2
devsup/__init__.py Normal file
View File

@ -0,0 +1,2 @@
VERSION = "0.1"

86
devsup/locate.py Normal file
View File

@ -0,0 +1,86 @@
"""
Locate an EPICS installation
"""
import os, os.path, platform
__all__ = [
'base'
'hostarch',
'binpath',
'dbpath',
'dbdpath',
'cpppath',
]
# Existance of these files is required
_files = ['include/epicsVersion.h', 'dbd/base.dbd']
_possible = [
'/usr/local/epics/base',
'/usr/local/epics/base/current',
'/usr/local/lib/epics',
'/opt/epics',
'/opt/epics/base',
'/opt/epics/base/current',
'/usr/lib/epics',
]
try:
envbase = os.environ['EPICS_BASE']
if os.path.isdir(envbase):
_possible.insert(-1, envbase)
else:
import warnings
warnings.warn("'%s' does not name a directory"%envbase, RuntimeWarning)
del envbase
except KeyError:
pass
def _findbase(poss):
for p in poss:
if not os.path.isdir(p):
continue
for f in _files:
fp = os.path.join(p,f)
if not os.path.isfile(fp):
break
return p
raise RuntimeError("Failed to locate EPICS Base")
base = _findbase(_possible)
del _possible
del _findbase
try:
_dbg = bool(int(os.environ.get('EPICS_DEBUG', '0')))
except ValueError:
_dbg = False
cpppath = [os.path.join(base,'include')]
def _findarch():
_plat = platform.system()
if _plat=='Windows':
cpppath.append(os.path.join(base, 'os', 'WIN32'))
raise RuntimeError("Windows support not complete")
elif _plat=='Linux':
cpppath.append(os.path.join(base, 'include', 'os', _plat))
archs = {'32bit':'x86', '64bit':'x86_64'}
arch = archs[platform.architecture()[0]]
return 'linux-%s%s' % (arch, '-debug' if _dbg else '')
else:
raise RuntimeError('Unsupported platform %s'%_plat)
hostarch = _findarch()
del _findarch
ldpath = [os.path.join(base,'lib',hostarch)]
binpath = [os.path.join(base,'bin',hostarch)]
dbpath = [os.path.join(base,'db',hostarch)]
dbdpath = [os.path.join(base,'dbd',hostarch)]

22
devsupApp/Db/Makefile Normal file
View File

@ -0,0 +1,22 @@
TOP=../..
include $(TOP)/configure/CONFIG
#----------------------------------------
# ADD MACRO DEFINITIONS AFTER THIS LINE
#----------------------------------------------------
# Optimization of db files using dbst (DEFAULT: NO)
#DB_OPT = YES
#----------------------------------------------------
# Create and install (or just install) into <top>/db
# databases, templates, substitutions like this
#DB += xxx.db
#----------------------------------------------------
# If <anyname>.db template is not named <anyname>*.template add
# <anyname>_template = <templatename>
include $(TOP)/configure/RULES
#----------------------------------------
# ADD RULES AFTER THIS LINE

8
devsupApp/Makefile Normal file
View File

@ -0,0 +1,8 @@
TOP = ..
include $(TOP)/configure/CONFIG
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard *src*))
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard *Src*))
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard *db*))
DIRS := $(DIRS) $(filter-out $(DIRS), $(wildcard *Db*))
include $(TOP)/configure/RULES_DIRS

52
devsupApp/src/Makefile Normal file
View File

@ -0,0 +1,52 @@
TOP=../..
include $(TOP)/configure/CONFIG
#----------------------------------------
# ADD MACRO DEFINITIONS AFTER THIS LINE
#=============================
PYTHON = python
# EG 2.7
PY_VER = $(shell $(PYTHON) -c 'from distutils.sysconfig import get_config_var; print get_config_var("VERSION")')
# EG -I/usr/include/python2.7
PY_CFLAGS := -I$(shell $(PYTHON) -c 'from distutils.sysconfig import get_python_inc; print get_python_inc()')
# EG -L/usr/lib
PY_LIBDIR := -L$(shell $(PYTHON) -c 'from distutils.sysconfig import get_config_var; print get_config_var("LIBDIR")')
USR_CPPFLAGS += $(PY_CFLAGS)
USR_LDFLAGS += $(PY_LIBDIR)
#=============================
# Build the IOC application
PROD_IOC = devsup
# devsup.dbd will be created and installed
DBD += devsup.dbd
# devsup.dbd will be made up from these files:
devsup_DBD += base.dbd
devsup_DBD += pyDevSup.dbd
devsup_SYS_LIBS += python$(PY_VER)
# devsup_registerRecordDeviceDriver.cpp derives from devsup.dbd
devsup_SRCS += devsup_registerRecordDeviceDriver.cpp
# Build the main IOC entry point on workstation OSs.
devsup_SRCS_DEFAULT += devsupMain.cpp
devsup_SRCS_vxWorks += -nil-
devsup_SRCS += setup.c
# Add support from base/src/vxWorks if needed
#devsup_OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary
# Finally link to the EPICS Base libraries
devsup_LIBS += $(EPICS_BASE_IOC_LIBS)
#===========================
include $(TOP)/configure/RULES
#----------------------------------------
# ADD RULES AFTER THIS LINE

View File

@ -0,0 +1,23 @@
/* devsupMain.cpp */
/* Author: Marty Kraimer Date: 17MAR2000 */
#include <stddef.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "epicsExit.h"
#include "epicsThread.h"
#include "iocsh.h"
int main(int argc,char *argv[])
{
if(argc>=2) {
iocsh(argv[1]);
epicsThreadSleep(.2);
}
iocsh(NULL);
epicsExit(0);
return(0);
}

View File

@ -0,0 +1 @@
registrar(pySetupReg)

88
devsupApp/src/setup.c Normal file
View File

@ -0,0 +1,88 @@
/* python has its own ideas about which version to support */
#undef _POSIX_C_SOURCE
#undef _XOPEN_SOURCE
#include <Python.h>
#include <stdio.h>
#include <epicsThread.h>
#include <epicsExit.h>
#include <initHooks.h>
static PyThreadState *main_state;
static void cleanupPy(void *junk)
{
PyEval_RestoreThread(main_state);
Py_Finalize();
}
/* Initialize the interpreter environment
*/
static void setupPyOnce(void *junk)
{
Py_Initialize();
PyEval_InitThreads();
epicsAtExit(&cleanupPy, NULL);
main_state = PyEval_SaveThread();
}
static epicsThreadOnceId setupPyOnceId = EPICS_THREAD_ONCE_INIT;
void evalPy(const char* code)
{
PyEval_RestoreThread(main_state);
if(PyRun_SimpleStringFlags(code, NULL)!=0)
PyErr_Print();
main_state = PyEval_SaveThread();
}
void evalFilePy(const char* file)
{
FILE *fp;
PyEval_RestoreThread(main_state);
fp = fopen(file, "r");
if(!fp) {
fprintf(stderr, "Failed to open: %s\n", file);
perror("open");
} else {
if(PyRun_SimpleFileExFlags(fp, file, 1, NULL)!=0)
PyErr_Print();
}
/* fp closed by python */
main_state = PyEval_SaveThread();
}
#include <iocsh.h>
static const iocshArg argCode = {"python code", iocshArgString};
static const iocshArg argFile = {"file", iocshArgString};
static const iocshArg* const codeArgs[] = {&argCode};
static const iocshArg* const fileArgs[] = {&argFile};
static const iocshFuncDef codeDef = {"evalPy", 1, codeArgs};
static const iocshFuncDef fileDef = {"evalFilePy", 1, fileArgs};
static void codeRun(const iocshArgBuf *args){evalPy(args[0].sval);}
static void fileRun(const iocshArgBuf *args){evalFilePy(args[0].sval);}
static void pySetupReg(void)
{
epicsThreadOnce(&setupPyOnceId, &setupPyOnce, NULL);
iocshRegister(&codeDef, &codeRun);
iocshRegister(&fileDef, &fileRun);
}
#include <epicsExport.h>
epicsExportRegistrar(pySetupReg);

3
test.cmd Normal file
View File

@ -0,0 +1,3 @@
#!./bin/linux-x86-debug/devsup
dbLoadDatabase("dbd/devsup.dbd")
devsup_registerRecordDeviceDriver(pdbbase)