Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Entry  09 Mar 2008, Exaos Lee, Suggestion, New Makefile for building MIDAS Makefile-by-EL
    Reply  09 Mar 2008, Stefan Ritt, Suggestion, New Makefile for building MIDAS 
    Reply  10 Mar 2008, Stefan Ritt, Suggestion, New Makefile for building MIDAS 
       Reply  10 Mar 2008, Exaos Lee, Suggestion, New Makefile for building MIDAS 
    Reply  10 Mar 2008, Konstantin Olchanski, Suggestion, New Makefile for building MIDAS 
       Reply  10 Mar 2008, Exaos Lee, Suggestion, New Makefile for building MIDAS 
          Reply  12 Mar 2008, Konstantin Olchanski, Suggestion, New Makefile for building MIDAS 
       Reply  10 Mar 2008, Exaos Lee, Suggestion, "Makefile-by-EL" updated Makefile-by-EL
          Reply  10 Mar 2008, Exaos Lee, Suggestion, "Makefile-by-EL" updated 
          Reply  11 Mar 2008, Stefan Ritt, Suggestion, "Makefile-by-EL" updated 
             Reply  11 Mar 2008, Exaos Lee, Suggestion, "Makefile-by-EL" updated 
Message ID: 455     Entry time: 09 Mar 2008     Reply to this: 456   458   459
Author: Exaos Lee 
Topic: Suggestion 
Subject: New Makefile for building MIDAS 
I rewrote the Makefile for MIDAS in order to make it tidy. I tested it on my box
and it works here.
1. The full file is seperated to several parts
  a. initialized setup
  b. environment setup
  c. specify OS-specific flags
  d. processing environment for building flags
  e. targets
2. The file is less than 400 lines now. The original one is more than 500 lines.
3. The modified one is easy for debuging.

I tried to learn "autoconf" and "automake" in order to make building MIDAS more
compatible for various platforms. But I havn't enough time now. Hope somebody
can help it. The attached file is original named "Makefile.in" for using "autoconf".

:-)
Attachment 1: Makefile-by-EL  9 kB  | Hide | Hide all
# initialized flags

#CC =
#FC = 
#LD =
CFLAGS   = -g -O3 -Wall -Wuninitialized -DINCLUDE_FTPLIB

###########################################################################
## Environments setup

## 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     =

# MIDAS max event size
MIDAS_MAX_EVENT_SIZE =

# OS specific programs included
SPECIFIC_OS_PRG      =

# ..? Why it is needed?
MIDAS_PREF_FLAGS     =

## installer

INSTALL  = $(shell which install)
ifndef INSTALL
INSTALL  = ./install.sh
else
INS_OPTS = -v -D
endif

# MXML dir
ifndef MXML_DIR
MXML_DIR = ../mxml
endif

# MySQL
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

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
LIBS       += -lz
endif # ZLIB

ifdef NEED_SHLIB
CFLAGS  += -shared -fPIC
endif # SHLIB

###########################################################################
## 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) -L$(LIB_DIR)

## Directories for install

INSTDIR_BIN = $(PREFIX)/bin
INSTDIR_INC = $(PREFIX)/include
INSTDIR_LIB = $(PREFIX)/lib
INSTDIR_DRV = $(PREFIX)/driver

## Utilities

PROGS = mserver  mhttpd  mlogger  odbedit  mtape   mhist    \
	mstat    mcnaf   mdump    mhdump    mchart  odbhist  \
	melog    webpaw  lazylogger   stripchart.tcl  \
	$(SPECIFIC_OS_PRG)

UTILS = $(shell for i in $(PROGS); do echo $(BIN_DIR)/$$i ; done)

## 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)

OBJS_LIB_NEED = midas.o  system.o  mrpc.o  odb.o  ybos.o  ftplib.o  history.o  alarm.o  elog.o

ifndef NEED_SHLIB
OBJS_LIB_NEED += cnaf_callback.o
endif

OBJS_LIB = $(shell for i in $(OBJS_LIB_NEED) ; do echo $(LIB_DIR)/$$i ; done)

## MXML OBJS

MXML_OBJS_NEED = mxml.o
ifdef NEED_STRLCPY
MXML_OBJS_NEED += strlcpy.o
endif

MXML_OBJS = $(shell for i in $(MXML_OBJS_NEED) ; do echo $(LIB_DIR)/$$i ; done)

## Objects for install

OBJS_INS_NEED = mfe.o fal.o
OBJS_INS = $(shell for i in $(OBJS_INS_NEED) ; do echo $(LIB_DIR)/$$i ; done)

## library

LIBMIDAS_A  = $(LIB_DIR)/libmidas.a
ifdef NEED_SHLIB
LIBMIDAS_SO  = $(LIB_DIR)/libmidas.so
LDFLAGS     += -shared -L$(LIB_DIR) -lmidas
endif

## Examples

EXAMPLES_NEED = consume produce rpc_test msgdump minife minirc odb_test
EXAMPLES = $(shell for i in $(EXAMPLES_NEED); do echo examples/$$i ; done)

## Includes

INCLUDES = $(wildcard $(INC_DIR)/*.h)

###########################################################################

CXXFLAGS  = $(CFLAGS)
ifdef ROOTSYS
CXXFLAGS += -DHAVE_ROOT
endif

all: check-mxml mkdirs $(LIBMIDAS_A) $(LIBMIDAS_SO) $(ANALYZER) $(OBJS_INS) utilities

.PHONY: clean

###########################################################################

## Library objects

$(LIB_DIR)/%.o: $(SRC_DIR)/%.c $(INCLUDES)
	$(CC) $(CFLAGS) -c -o $@ $<

## MXML_OBJS

$(LIB_DIR)/mxml.o: $(MXML_DIR)/mxml.c
	$(CC) $(CFLAGS) -c -o $@ $<

$(LIB_DIR)/strlcpy.o: $(MXML_DIR)/strlcpy.c
	$(CC) $(CFLAGS) -c -o $@ $<

## Frontend and backend framework

$(LIB_DIR)/fal.o: $(SRC_DIR)/fal.c $(INCLUDES)
	$(CXX) -Dextname -DMANA_LITE -c -o $@ $< $(CFLAGS)

$(LIB_DIR)/hmana.o: $(SRC_DIR)/mana.c $(INCLUDES)
	$(CC) -Dextname -DHAVE_HBOOK $(CFLAGS) -c -o $@ $<

$(LIB_DIR)/rmana.o: $(SRC_DIR)/mana.c $(INCLUDES)
	$(CXX) -DUSE_ROOT $(CXXFLAGS) -c -o $@ $<

## Utilities

$(BIN_DIR)/%: $(UTL_DIR)/%.c $(INCLUDES)
	$(CC) $(CFLAGS) -o $@ $< $(LIBMIDAS_A) $(LDFLAGS)

$(BIN_DIR)/mlogger: $(SRC_DIR)/mlogger.c $(LIBMIDAS_A)
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(ROOTLIBS)
$(BIN_DIR)/mserver: $(SRC_DIR)/mserver.c $(INCLUDES)
$(BIN_DIR)/mhttpd:  $(SRC_DIR)/mhttpd.c  $(SRC_DIR)/mgd.c
$(BIN_DIR)/odbedit: $(SRC_DIR)/odbedit.c $(SRC_DIR)/cmdedit.c
$(BIN_DIR)/mcnaf:   $(UTL_DIR)/mcnaf.c   $(DRV_DIR)/camac/camacrpc.c
$(BIN_DIR)/mhdump:  $(UTL_DIR)/mhdump.cxx
	$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(ROOTLIBS)
$(BIN_DIR)/lazylogger: $(SRC_DIR)/lazylogger.c
$(BIN_DIR)/stripchart.tcl: $(UTL_DIR)/stripchart.tcl
	@cp -f $< $(BIN_DIR)/$(shell basename $@)

###########################################################################

mkdirs:
	@for i in $(DIRS) ; do \
		echo "Making directory $$i ..." ; \
		mkdir -p $$i ; \
	done
... 108 more lines ...
ELOG V3.1.4-2e1708b5