#-include MIDAS-env.mk --- split the environment setup in a seperate file? # initialized flags #CC = icc #FC = ifort #LD = ld CFLAGS = -g -O3 -Wall -Wuninitialized -DINCLUDE_FTPLIB ########################################################################### ## Environments setup for building MIDAS/PSI ## Prefix ifndef PREFIX PREFIX = /usr/local endif # User defined flags for compiler USERFLAGS = # Do you need to compile the shared library? If so, set "1" here. NEED_SHLIB = # If RPATH needed ... NEED_RPATH = # If static ROOT libaries needed ... NEED_LIBROOTA = # If strlcpy.o needed ... NEED_STRLCPY = 1 # If zlib needed ... NEED_ZLIB = 1 # MIDAS max event size MIDAS_MAX_EVENT_SIZE = # OS specific programs included SPECIFIC_OS_PRG = # ..? Why it is needed? MIDAS_PREF_FLAGS = # Build examples or not? If so, set "1" here ... EXAMPLES_NEED = 1 ## installer INSTALL = $(shell which install) # **** CAUTION **** # **** On MacOS Tiger, "/usr/bin/install" doesn't accept "-D" option! # **** NEED to be fixed ... ifndef INSTALL INSTALL = ./install.sh else INS_OPTS = -v -D endif # MXML dir ifndef MXML_DIR MXML_DIR = ../mxml endif # MySQL # **** CAUTION **** # **** On MacOS Tiger (10.4.11), the "MYSQL_CONFIG" will be always defined because # **** "which" will always return something whether it finds the exec or not! # **** NEED to be fixed! MYSQL_CONFIG := $(shell which mysql_config 2> /dev/null) ifdef MYSQL_CONFIG MYSQLINCDIR := $(shell mysql_config --cflags | sed -e 's,^.*-I\([^ ]*\).*$$,\1,' -e s/\'//g) NEED_MYSQL := $(shell if test -e $(MYSQLINCDIR)/mysql.h ; then echo 1; fi) endif ########################################################################### ## Check OS Type for OS-specified flags # *** CAUTION *** Does "tr" exist on all POSIX platform? OSTYPE = $(shell uname | tr '[A-Z]' '[a-z]') ifeq ($(OSTYPE), linux) # > 2GB file support CFLAGS += -D_LARGEFILE64_SOURCE CFLAGS += -DOS_LINUX -fPIC -Wno-unused-function LDFLAGS += -lutil -lpthread NEED_ZLIB = 1 SPECIFIC_OS_PRG += mlxspeaker dio endif ifeq ($(OSTYPE), osf1) CFLAGS += -DOS_OSF1 FFLAGS += -nofor_main -D 40000000 -T 20000000 LDFLAGS += -lc -lbsd endif ifeq ($(OSTYPE), ultrix) CFLAGS += -DOS_ULTRIX -DNO_PTY endif ifeq ($(OSTYPE), freebsd) CFLAGS += -DOS_FREEBSD LDFLAGS += -lbsd -lcompat endif ifeq ($(OSTYPE), darwin) CFLAGS += -DOS_LINUX -DOS_DARWIN -DHAVE_STRLCPY -fPIC -Wno-unused-function LDFLAGS += -lpthread NEED_RANLIB = 1 SPECIFIC_OS_PRG += mlxspeaker endif ifeq ($(OSTYPE), cygwin_nt-5.1) OSTYPE = cygwin endif ifeq ($(OSTYPE), cygwin) CFLAGS += -DOS_LINUX -DOS_CYGWIN -Wno-unused-function LDFLAGS += -lutil -lpthread endif ifeq ($(OSTYPE), solaris) CFLAGS += -DOS_SOLARIS LDFLAGS += -lsocket -lnsl endif ########################################################################### ## Processing environment for building flags CFLAGS += $(MIDAS_PREF_FLAGS) $(USERFLAGS) ifdef MIDAS_MAX_EVENT_SIZE CFLAGS += -DMAX_EVENT_SIZE=$(MIDAS_MAX_EVENT_SIZE) endif # MIDAS_MAX_EVENT_SIZE ifdef NEED_MYSQL CFLAGS += -DHAVE_MYSQL $(shell $(MYSQL_CONFIG) --include) LDFLAGS += $(shell $(MYSQL_CONFIG) --libs) NEED_ZLIB = 1 endif # NEED_MYSQL ifdef ROOTSYS ROOTLIBS := $(shell $(ROOTSYS)/bin/root-config --libs) ROOTCFLAGS := $(shell $(ROOTSYS)/bin/root-config --cflags) ifdef NEED_RPATH ROOTLIBS += -Wl,-rpath,$(ROOTSYS)/lib endif ifdef NEED_LIBROOTA ROOTLIBS := $(ROOTSYS)/lib/libRoot.a -lssl -ldl -lcrypt endif CFLAGS += $(ROOTCFLAGS) endif # ROOTSYS ifdef NEED_ZLIB CFLAGS += -DHAVE_ZLIB LDFLAGS += -lz endif # ZLIB ########################################################################### ## Processing building targets ## Directories needed INC_DIR = include SRC_DIR = src UTL_DIR = utils DRV_DIR = drivers EXM_DIR = examples ## Driectories which will be created OS_DIR = $(OSTYPE) LIB_DIR = $(OS_DIR)/lib BIN_DIR = $(OS_DIR)/bin DIRS = $(OS_DIR) $(LIB_DIR) $(BIN_DIR) CFLAGS += -I$(INC_DIR) -I$(DRV_DIR) -I$(MXML_DIR) ## Directories for install INSTDIR_BIN = $(PREFIX)/bin INSTDIR_INC = $(PREFIX)/include INSTDIR_LIB = $(PREFIX)/lib INSTDIR_DRV = $(PREFIX)/driver ## Utilities UTILS = mserver mhttpd mlogger odbedit mtape mhist \ mstat mcnaf mdump mhdump mchart odbhist \ melog webpaw lazylogger stripchart.tcl \ $(SPECIFIC_OS_PRG) # Utilities need to change SUID mode UTILS_SUID_NEED = dio mhttpd webpaw UTILS_SUID = $(UTILS_SUID_NEED:%=$(BIN_DIR)/%) ## Analyzer objects ANALYZER = $(LIB_DIR)/mana.o ifdef CERNLIB ANALYZER += $(LIB_DIR)/hmana.o endif ifdef ROOTSYS ANALYZER += $(LIB_DIR)/rmana.o endif ## Objects for building $(LIBMIDAS_A) and $(LIBMIDAS_SO) OBJS4LIB_ALL = midas.o system.o mrpc.o odb.o ybos.o ftplib.o history.o alarm.o elog.o OBJS4LIB_A = $(OBJS4LIB_ALL:%=$(LIB_DIR)/%) $(LIB_DIR)/cnaf_callback.o OBJS4LIB_SO = $(OBJS4LIB_ALL:%=$(LIB_DIR)/%) ## MXML OBJS MXML_OBJS_NEED = mxml.o ifdef NEED_STRLCPY MXML_OBJS_NEED += strlcpy.o endif MXML_OBJS = $(MXML_OBJS_NEED:%=$(LIB_DIR)/%) ## Objects for install OBJS_INS_NEED = mfe.o fal.o OBJS_INS = $(OBJS_INS_NEED:%=$(LIB_DIR)/%) ## library LIBMIDAS_A = $(LIB_DIR)/libmidas.a ifdef NEED_SHLIB LIBMIDAS_SO = $(LIB_DIR)/libmidas.so CFLAGS += -shared -fPIC LDFLAGS += -shared # if need to link utilities dynamically with libmidas.so, add this flag... LDFLAGS_SH += -shared -L$(LIB_DIR) -lmidas endif # NEED_SHLIB ## Examples EXAMPLES = consume produce rpc_test msgdump minirc odb_test #minife - failed building! ## All executables EXECS = $(UTILS:%=$(BIN_DIR)/%) ifdef EXAMPLES_NEED EXECS += $(EXAMPLES:%/$(BIN_DIR)/%) endif ########################################################################### CXXFLAGS = $(CFLAGS) ifdef ROOTSYS CXXFLAGS += -DHAVE_ROOT endif all: check-mxml $(DIRS) $(LIBMIDAS_A) $(LIBMIDAS_SO) \ $(ANALYZER) $(OBJS_INS) $(EXECS) .PHONY: clean examples: $(LIBMIDAS_A) $(EXAMPLES:%=$(BIN_DIR)/%) ## Static static: @rm -f $(EXECS) @$(MAKE) USERFLAGS=-static ## Install install: install-utils install-includes install-libs \ install-drivers install-src install-examples @echo "..." @echo "... Happy working with MIDAS! " @echo "..." ########################################################################### $(DIRS): @echo "Making directory $@ ..." @mkdir -p $@ ## Libraries $(LIBMIDAS_A): $(OBJS4LIB_A) $(MXML_OBJS) @rm -f $@ @echo "Creating $@ ..." @ar -crv $@ $^ ifdef NEED_RANLIB @ranlib $@ endif $(LIBMIDAS_SO): $(OBJS4LIB_SO) $(MXML_OBJS) @rm -f $@ @echo "Creating $@ ..." @$(CC) $(LDFLAGS) -o $@ $^ ## MXML-check check-mxml: ifdef NEED_STRLCPY @if test ! -e $(MXML_DIR)/strlcpy.h ; then \ echo "Please download mxml from: " ; \ echo "http://midas.psi.ch/htmldoc/quickstart.html" ;\ exit 1; \ fi endif @if test ! -e $(MXML_DIR)/mxml.h ; then \ echo "Please download mxml from: " ; \ echo "http://midas.psi.ch/htmldoc/quickstart.html" ;\ exit 1; \ fi ## Cleaning clean: @echo "Cleanup ..." @rm -f $(LIB_DIR)/*.o $(LIBMIDAS_A) $(LIBMIDAS_SO) *~ \#* mrproper: clean @rm -rf $(OS_DIR) @rm -rf vxworks/68kobj vxworks/ppcobj ## Installs ... install-utils: $(UTILS:%=$(BIN_DIR)/%) @echo "... " @echo "... Installing utilities to $(INSTDIR_BIN)" @echo "... " @for file in $(notdir $^) ; do \ $(INSTALL) $(INS_OPTS) $(BIN_DIR)/$$file $(INSTDIR_BIN)/$$file ; \ done @for file in $(UTILS_SUID) ; do \ if test -f $(INSTDIR_BIN)/$$file ; then chmod +s $(INSTDIR_BIN)/$$file ; fi ; \ done @chmod +x $(INSTDIR_BIN)/stripchart.tcl @ln -fs $(INSTDIR_BIN)/stripchart.tcl $(INSTDIR_BIN)/stripchart install-includes: $(wildcard $(INC_DIR)/*.h) @echo "... " @echo "... Installing includes to $(INSTDIR_INC)" @echo "... " @for file in $(ntodir $^) ; do \ $(INSTALL) $(INS_OPTS) $(INC_DIR)/$$file $(INSTDIR_INC)/$$file ; \ done install-libs: $(LIBMIDAS_A) $(LIBMIDAS_SO) $(OBJS_INS) $(ANALYZER) @echo "... " @echo "... Installing libraries and objects to $(INSTDIR_LIB)" @echo "... " @for file in $(ntodir $^) ; do \ $(INSTALL) $(INS_OPTS) $(LIB_DIR)/$$file $(INSTDIR_LIB)/$$file ; \ done install-drivers: @echo "... " @echo "... Installing drivers to $(PREFIX)" @echo "... " @for file in `find $(DRV_DIR) -type f | grep -v .svn` ; do \ $(INSTALL) $(INS_OPTS) $$file $(PREFIX)/$$file ; \ done install-examples: @echo "... " @echo "... Installing examples to $(PREFIX)" @echo "... " @for file in `find $(EXM_DIR) -type f | grep -v .svn` ; do \ $(INSTALL) $(INS_OPTS) $$file $(PREFIX)/$$file ; \ done @for file in $(EXAMPLES) ; do \ $(INSTALL) $(INS_OPTS) $(BIN_DIR)/$$file $(INSTDIR_BIN)/$$file ; \ done install-src: @echo "... " @echo "... Installing sources to $(PREFIX)" @echo "... " @for file in `find $(SRC_DIR) -type f | grep -v .svn` ; do \ $(INSTALL) $(INS_OPTS) $$file $(PREFIX)/$$file ; \ done ########################################################################### ## Objects VPATH = $(SRC_DIR):$(MXML_DIR):$(UTL_DIR):$(INC_DIR):$(DRV_DIR)/camac $(LIB_DIR)/%.o: %.c $(CC) $(CFLAGS) -c -o $@ $< $(LIB_DIR)/%.o: %.cxx $(CXX) $(CXXFLAGS) -c -o $@ $< $(LIB_DIR)/%.o: %.cpp $(CXX) $(CXXFLAGS) -c -o $@ $< $(LIB_DIR)/midas.o: msystem.h midas.h midasinc.h mrpc.h $(LIB_DIR)/system.o: msystem.h midas.h midasinc.h mrpc.h $(LIB_DIR)/mrpc.o: msystem.h midas.h mrpc.h $(LIB_DIR)/odb.o: msystem.h midas.h midasinc.h mrpc.h $(LIB_DIR)/ybos.o: msystem.h midas.h midasinc.h mrpc.h $(LIB_DIR)/ftplib.o: msystem.h midas.h midasinc.h $(LIB_DIR)/mxml.o: msystem.h midas.h midasinc.h mxml.h ## Frontend and backend framework $(LIB_DIR)/fal.o: $(SRC_DIR)/fal.c msystem.h midas.h midasinc.h mrpc.h $(CXX) -Dextname -DMANA_LITE -c -o $@ $< $(CFLAGS) $(LIB_DIR)/mana.o: msystem.h midas.h midasinc.h mrpc.h $(LIB_DIR)/hmana.o: $(SRC_DIR)/mana.c msystem.h midas.h midasinc.h mrpc.h $(CC) -Dextname -DHAVE_HBOOK $(CFLAGS) -c -o $@ $< $(LIB_DIR)/rmana.o: $(SRC_DIR)/mana.c msystem.h midas.h midasinc.h mrpc.h $(CXX) -DUSE_ROOT $(CXXFLAGS) -c -o $@ $< ## Executables $(BIN_DIR)/%: $(LIB_DIR)/%.o $(LIBMIDAS_A) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) # If you want to link executables dynamically, uncomment the following and # repeat it respectly to other targets ... # But from my experiences, the execs never work while using shared lib. :-( # --- by Exaos Lee #$(BIN_DIR)/%: $(LIB_DIR)/%.o # $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LDFLAGS_SH) ## Utilities $(BIN_DIR)/mlogger: $(LIB_DIR)/mlogger.o $(LIBMIDAS_A) $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(ROOTLIBS) $(BIN_DIR)/mhdump: $(LIB_DIR)/mhdump.o $(LIBMIDAS_A) $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(ROOTLIBS) $(BIN_DIR)/mhttpd: $(LIB_DIR)/mhttpd.o $(LIB_DIR)/mgd.o $(LIBMIDAS_A) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BIN_DIR)/odbedit: $(LIB_DIR)/odbedit.o $(LIB_DIR)/cmdedit.o $(LIBMIDAS_A) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BIN_DIR)/mcnaf: $(LIB_DIR)/mcnaf.o $(LIB_DIR)/camacrpc.o $(LIBMIDAS_A) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(BIN_DIR)/stripchart.tcl: $(UTL_DIR)/stripchart.tcl @cp -f $< $@ ## Examples VPATH += $(EXM_DIR)/lowlevel:$(EXM_DIR)/basic