commit e7b7bee395b734c0b34786809666dc6ccdb05f91 Author: Michael Davidsaver Date: Sun Mar 24 13:32:56 2013 -0400 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0f7a2a8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.pyc +*.pyo +*~ +O.* +bin +include +lib +db +dbd diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..f0d9ad7 --- /dev/null +++ b/Makefile @@ -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 + + diff --git a/configure/CONFIG b/configure/CONFIG new file mode 100644 index 0000000..c1a4703 --- /dev/null +++ b/configure/CONFIG @@ -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 + diff --git a/configure/CONFIG_SITE b/configure/CONFIG_SITE new file mode 100644 index 0000000..72b399d --- /dev/null +++ b/configure/CONFIG_SITE @@ -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= + +# 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 = diff --git a/configure/Makefile b/configure/Makefile new file mode 100644 index 0000000..9254309 --- /dev/null +++ b/configure/Makefile @@ -0,0 +1,8 @@ +TOP=.. + +include $(TOP)/configure/CONFIG + +TARGETS = $(CONFIG_TARGETS) +CONFIGS += $(subst ../,,$(wildcard $(CONFIG_INSTALLS))) + +include $(TOP)/configure/RULES diff --git a/configure/RELEASE b/configure/RELEASE new file mode 100644 index 0000000..df9cc70 --- /dev/null +++ b/configure/RELEASE @@ -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 diff --git a/configure/RULES b/configure/RULES new file mode 100644 index 0000000..6d56e14 --- /dev/null +++ b/configure/RULES @@ -0,0 +1,6 @@ +# RULES + +include $(CONFIG)/RULES + +# Library should be rebuilt because LIBOBJS may have changed. +$(LIBNAME): ../Makefile diff --git a/configure/RULES.ioc b/configure/RULES.ioc new file mode 100644 index 0000000..901987c --- /dev/null +++ b/configure/RULES.ioc @@ -0,0 +1,2 @@ +#RULES.ioc +include $(CONFIG)/RULES.ioc diff --git a/configure/RULES_DIRS b/configure/RULES_DIRS new file mode 100644 index 0000000..3ba269d --- /dev/null +++ b/configure/RULES_DIRS @@ -0,0 +1,2 @@ +#RULES_DIRS +include $(CONFIG)/RULES_DIRS diff --git a/configure/RULES_TOP b/configure/RULES_TOP new file mode 100644 index 0000000..d09d668 --- /dev/null +++ b/configure/RULES_TOP @@ -0,0 +1,3 @@ +#RULES_TOP +include $(CONFIG)/RULES_TOP + diff --git a/devsup/__init__.py b/devsup/__init__.py new file mode 100644 index 0000000..1181707 --- /dev/null +++ b/devsup/__init__.py @@ -0,0 +1,2 @@ + +VERSION = "0.1" diff --git a/devsup/locate.py b/devsup/locate.py new file mode 100644 index 0000000..a8299d4 --- /dev/null +++ b/devsup/locate.py @@ -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)] diff --git a/devsupApp/Db/Makefile b/devsupApp/Db/Makefile new file mode 100644 index 0000000..983981d --- /dev/null +++ b/devsupApp/Db/Makefile @@ -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 /db +# databases, templates, substitutions like this +#DB += xxx.db + +#---------------------------------------------------- +# If .db template is not named *.template add +# _template = + +include $(TOP)/configure/RULES +#---------------------------------------- +# ADD RULES AFTER THIS LINE + diff --git a/devsupApp/Makefile b/devsupApp/Makefile new file mode 100644 index 0000000..10e0126 --- /dev/null +++ b/devsupApp/Makefile @@ -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 + diff --git a/devsupApp/src/Makefile b/devsupApp/src/Makefile new file mode 100644 index 0000000..f5f5ced --- /dev/null +++ b/devsupApp/src/Makefile @@ -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 + diff --git a/devsupApp/src/devsupMain.cpp b/devsupApp/src/devsupMain.cpp new file mode 100644 index 0000000..a7a4234 --- /dev/null +++ b/devsupApp/src/devsupMain.cpp @@ -0,0 +1,23 @@ +/* devsupMain.cpp */ +/* Author: Marty Kraimer Date: 17MAR2000 */ + +#include +#include +#include +#include +#include + +#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); +} diff --git a/devsupApp/src/pyDevSup.dbd b/devsupApp/src/pyDevSup.dbd new file mode 100644 index 0000000..b09ebf3 --- /dev/null +++ b/devsupApp/src/pyDevSup.dbd @@ -0,0 +1 @@ +registrar(pySetupReg) diff --git a/devsupApp/src/setup.c b/devsupApp/src/setup.c new file mode 100644 index 0000000..db0ae1a --- /dev/null +++ b/devsupApp/src/setup.c @@ -0,0 +1,88 @@ +/* python has its own ideas about which version to support */ +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + +#include + +#include + +#include +#include +#include + +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 + +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 +epicsExportRegistrar(pySetupReg); diff --git a/test.cmd b/test.cmd new file mode 100644 index 0000000..a313d33 --- /dev/null +++ b/test.cmd @@ -0,0 +1,3 @@ +#!./bin/linux-x86-debug/devsup +dbLoadDatabase("dbd/devsup.dbd") +devsup_registerRecordDeviceDriver(pdbbase)