#==============================================================
#
#  Abs:  Makefile to build EPICS Magnet Application
#
#  Name: Makefile
#
#  Desc: This file generates a database definition file
#        file for a soft ioc mgntSoft.dbd and for an
#        RTEMS ioc mgnt.dbd. 
#
#  Facility:  SLAC/LCLS
#
#  Auth: 26-Jul-2005, K. Luchini          (LUCHINI)
#  Rev:  dd-mmm-yyyy, Reviewer's Name     (USERNAME)
#--------------------------------------------------------------
#  Mod:
#       02-Feb-2016, K. Luchini           (LUCHINI):
#          add spy.dbd and rtemsutils library
#       20-Nov-2014, K. Luchini           (LUCHINI):
#          include systemCommand.c and systemCommand.dbd
#          for all architectures.
#       15-Apr-2014, K. Luchini           (LUCHINI):
#          build timing into rtems and linux-x86 only,
#          issue with linuxRT timing. Include EPICS V4
#          modules only for linux-x86 build.
#       09-Oct-2012, K. Luchini           (LUCHINI):
#          add checks for target linuxRT-x86 and 
#          add  systemCommands.c and systemCommand.dbd 
#          for linuxRT
#          add macro linuxRT as CFLAG for mgntMain.cpp build
#       04-Apr-2012, K. Luchini           (LUCHINI):
#          add devBusMapped.dbd
#          add epicspci.dbd
#          add drvPciMcor.dbd
#          add drvUioPciGen.dbd
#       18-Jan-2012, K. Luchini           (LUCHINI):
#          remove generalTimeLib, now in epics base R3.14.12
#       07-Sep-2011, K. Luchini           (LUCHINI):
#          add modbus and asyn libraries and dbds
#          remove drvXy9660.dbd now included in drvIpac.dbd
#       22-Aug-2010, D Rogind             (DROGIND):
#          add in pau seq to back propagate feedback value to PV
#       09-Jun-2010, K. Luchini           (LUCHINI):
#          remove soft reset lcl_bus_rst.c, which is
#          now included in the RTEMS release
#       02-Jun-2010, K. Luchini           (LUCHINI):
#          Move mgntRegister.c and mgntPauUsr.c to build
#          under RTEMS only.
#       03-Feb-2010, D. Rogind            (DROGIND):
#          add pau,fcom libs, added mgntPauUsr and mgntRegister srcs
#       24-Feb-2009, K. Luchini           (LUCHINI):
#          remove slc-aware lib and db
#       03-Feb-2009, K. Luchini           (LUCHINI):
#          temporily add Till's soft-reboot function
#          for rtems iocs. This will be in a later version
#          of rtems, at which time I'll remove this function
#          from magnets.
#       29-Oct-2008, K. Luchini           (LUCHINI):
#          change iocAdmin library to devIocStats
#          which is needed for the release of  iocAdmin-R2-0-0
#       14-Dec-2007, K. Luchini           (LUCHINI):
#          depricate the mgntSoftInclud.dbd 
#          and mgntInclude.dbd
#       11-Dec-2007, K. Luchini           (LUCHINI):
#          add genSubLib
#       18-Oct-2007, K. Luchini           (LUCHINI):
#          compile subsys.c locally
#          cmlog library is no longer needed.
#       29-Aug-2007, K. Luchini           (LUCHINI):
#          remove libXy9660.a since it is not included
#          in libIpac.a
#       03-Aug-2007, K. Luchini           (LUCHINI):
#          remove std library
#       24-Jul-2007, K. Luchini           (LUCHINI):
#          replaced iocMon with iocAdmin
#       23-July 2007 D. Rogind            (DROGIND):
#          remove drvSupport
#       12-July 2007 D. Rogind            (DROGIND):
#           remove iocCmlog
#       22-Jun-2007, K. Luchini           (LUCHINI):
#          remove drvUniverseDma and devBusMapped
#       09-May-2007, K. Luchini           (LUCHINI):
#          add iocMon library
#       02-May-2007, K. Luchini           (LUCHINI):
#          add vsam and vmeCardRecord libraries
#       01-May-2007, K. Luchini           (LUCHINI):
#          added autosave
#       30-Mar-2007, Kmgnt_LIBS += pau
#          decouple event software from slc-aware
#       21-Mar-2007, K. Luchini           (LUCHINI):
#          specify event package libraires rather than
#          use predefined variables.
#       28-Jan-2007, K. Luchini           (LUCHINI):
#          chg how event and slcaware libraries are added
#       26-Jan-2007, D. Rogind            (DROGIND):
#          add in event libraries
#       21-Sep-2006, K. Luchini           (LUCHINI):
#         add Hytec Ip-Adc-8413 library
#       29-Aug-2006, K. Luchini           (LUCHINI):
#         removed ip440,ip445, async support
#       19-Aug-2006, K. Luchini           (LUCHINI):
#         added Acromag ip231 dac support
#       28-Jul-2006, K. Luchini           (LUCHINI):
#         include asyn library only with RTEMS
#       13-Jul-2006, K. Luchini           (LUCHINI):
#         add ether_ip,asyn libs and slcaware debug flag
#       23-Mar-2006, K. Luchini           (LUCHINI):
#         add VSAM and remove Vipc664 drivers
#       12-Mar-2006, K. Luchini           (LUCHINI):
#         added subSys library.
#       07-Mar-2006, K. Luchini           (LUCHINI):
#         used the new files mgntInclude.dbd and mgntSoft.dbd
#         to generate mgnt.dbd and mgntSoft.dbd
#
#==============================================================
#
TOP=../..
include $(TOP)/configure/CONFIG
#----------------------------------------
#  ADD MACRO DEFINITIONS AFTER THIS LINE
#========================================
#
# Build an object
#
ifeq ($(OS_CLASS),RTEMS)
   PROD_IOC = mgnt 
else 
   PROD_IOC = mgntSoft
endif

# mgntSoft.dbd will be made up from these files:
DBD          = mgntSoft.dbd
mgntSoft_DBD += base.dbd
mgntSoft_DBD += iocAdmin.dbd
mgntSoft_DBD += dbRestore.dbd
mgntSoft_DBD += subSys.dbd
mgntSoft_DBD += sSubRecord.dbd
mgntSoft_DBD += genSubRecord.dbd
mgntSoft_DBD += system.dbd

# EPICS V4 service
#mgntSoft_DBD += dbPv.dbd

# Ethernet and serial devices
mgntSoft_DBD += devEtherPSC.dbd
mgntSoft_DBD += ether_ip.dbd
mgntSoft_DBD += modbus.dbd
mgntSoft_DBD += asyn.dbd
mgntSoft_DBD += stream.dbd
mgntSoft_DBD += drvAsynIPPort.dbd

# General magnet functions
mgntSoft_DBD += mgntSub.dbd
mgntSoft_DBD += mgntCtrl.dbd

# For mcor-ii
mgntSoft_DBD += epicspci.dbd
mgntSoft_DBD += devBusMapped.dbd
mgntSoft_DBD += drvUioPciGen.dbd
mgntSoft_DBD += drvPciMcor.dbd

# for linux system commands
mgntSoft_DBD += systemCommand.dbd
ifeq ($(T_A),linuxRT-x86)
mgntSoft_DBD += pciMcor.dbd
USR_CFLAGS += -DlinuxRT
endif

# mgnt.dbd will be made up from these files:
ifeq ($(OS_CLASS),RTEMS)
DBD      += mgnt.dbd
mgnt_DBD += mgntSoft.dbd

# For modbus
mgnt_DBD   += ModBusTCPClnt.dbd 
mgnt_DBD   += Bx9000_MBT.dbd

# For Timing
mgnt_DBD += evrSupport.dbd
mgnt_DBD += devMrfEr.dbd
mgnt_DBD += drvMrfEr.dbd

# For devlib2
mgnt_DBD += epicsvme.dbd

# For spy utility
mgnt_DBD += spy.dbd

mgnt_DBD += drvIpac.dbd
mgnt_DBD += IP231.dbd
mgnt_DBD += devHy8413.dbd
mgnt_DBD += vmeCardRecord.dbd
mgnt_DBD += devVSAM.dbd
mgnt_DBD += devVSAMCard.dbd

# For fast feedback
mgnt_DBD += drvPau.dbd
mgnt_DBD += devPau.dbd
mgnt_DBD += drvPauUsr.dbd
mgnt_DBD += sncPau.dbd
mgnt_DBD += fcomIocshSupport.dbd
mgnt_DBD += mgntRegister.dbd
mgnt_DBD += mgntPauUsr.dbd
endif

# For debugging - don't optimize
USR_CFLAGS += -O0
USR_CFLAGS += -DDEBUG_PRINT
#USR_CFLAGS_DEFAULT += -DHOST_TEST -g

# <name>_registerRecordDeviceDriver.cpp will be created from <name>.dbd
mgnt_SRCS         += mgnt_registerRecordDeviceDriver.cpp
mgntSoft_SRCS     += mgntSoft_registerRecordDeviceDriver.cpp


ifeq ($(T_A),linuxRT-x86)
mgntSoft_SRCS    += pciMcor.cpp
endif

USR_SRCS_DEFAULT  += mgntMain.cpp
mgnt_SRCS_vxWorks += -nil-
mgnt_SRCS_RTEMS   += -nil-

# The following adds support from base/src/vxWorks
mgnt_OBJS_vxWorks += $(EPICS_BASE_BIN)/vxComLibrary

# Add locally compiled object code
USR_SRCS  += systemCommand.c
USR_SRCS  += subSys.c
USR_SRCS  += mgntSub.c

ifeq ($(OS_CLASS),RTEMS)
USR_SRCS  += mgntRegister.c
USR_SRCS  += mgntPauUsr.c
endif

# Note: order of libraries for the event system is very important.
USR_LIBS  += devIocStats
USR_LIBS  += sSubRecord
USR_LIBS  += genSub
USR_LIBS  += miscUtils 

ifeq ($(OS_CLASS),RTEMS)
mgnt_LIBS += Bx9000_MBT
mgnt_LIBS += ModBusTCPClnt
endif

# EPICS V4 service
#USR_LIBS  += pvaSrv pvIOC pvAccess pvData pvMB

# For mcor-ii
USR_LIBS  += drvPciMcor
USR_LIBS  += drvUioPciGen
USR_LIBS  += devBusMapped
USR_LIBS  += epicspci

USR_LIBS  += etherPSC
USR_LIBS  += ether_ip
USR_LIBS  += modbus
USR_LIBS  += asyn
USR_LIBS  += stream

# Timing
ifeq ($(OS_CLASS),RTEMS)
USR_LIBS += evrSupport
USR_LIBS += devMrfEr

# Add in VME drivers.
# Note: order of libraries for the 
# event system is very important.
USR_LIBS += mrfVme64x

# For devlib2
USR_LIBS  += epicsvme

# For spy
USR_LIBS  += rtemsutils

# For VME modules
mgnt_LIBS += IP231
mgnt_LIBS += Hy8413
mgnt_LIBS += Ipac
mgnt_LIBS += vsam
mgnt_LIBS += vmeCardRecord

# For fast feedback
mgnt_LIBS += pau
mgnt_LIBS += fcom 
mgnt_LIBS += udpComm
mgnt_LIBS += fcomIocshSupport 
mgnt_LIBS += fcomUtil
endif

# This library must come after mrfVme64x
USR_LIBS  += restore

# Build SNL programs
# NOTE: to build SLN programs, SNCSEQ must be defined
# in the <top>/configure/RELEASE file
#
ifneq ($(SNCSEQ),)
 USR_SNCFLAGS += +r
 USR_SNCFLAGS += -a
 USR_SNCFLAGS += +c
 USR_SNCFLAGS += +d
 USR_SRCS     += mgntCtrl.st
 USR_LIBS     += seq pv
endif

USR_LIBS += $(EPICS_BASE_IOC_LIBS) 
USR_LIBS += $(CEXP_LIBS)

# Needed for static builds and stream device
ifeq ($(T_A),linux-x86)
USR_SYS_LIBS += pcre
endif

#========================================
include $(TOP)/configure/RULES
#----------------------------------------
#  ADD RULES AFTER THIS LINE
#========================================
#
# End of file
