#
#	Makefile for dcmdata/libsrc
#

@SET_MAKE@

SHELL = /bin/sh
VPATH = @srcdir@:@top_srcdir@/include:@top_srcdir@/@configdir@/include
srcdir = @srcdir@
top_srcdir = @top_srcdir@
configdir = @top_srcdir@/@configdir@

include $(configdir)/@common_makefile@

ofstddir = $(top_srcdir)/../ofstd
oflogdir = $(top_srcdir)/../oflog

LOCALINCLUDES = -I$(ofstddir)/include -I$(oflogdir)/include
LIBDIRS = -L$(ofstddir)/libsrc -L$(oflogdir)/libsrc
LOCALLIBS = -loflog -lofstd
LOCALDEFS =

# clear environment variable in the scope of this makefile
DCMDICTPATH =

# Special defines for the Library, define them in LOCALDEFS
#   DICOMDIR_WITHOUT_BACKUP
#       no Backup for DICOMDIR files. default: not defined
#   PRINT_REPLACED_DICTIONARY_ENTRIES
#       dump duplicate entries in the data dictionary to stderr

dicomdic = $(top_srcdir)/data/dicom.dic
privatedic = $(top_srcdir)/data/private.dic

dictobjs = dctagkey.o dcdicent.o dcdict.o dcdictbi.o dcvr.o dchashdi.o
objs = dcpixseq.o dcpxitem.o dcuid.o dcerror.o \
	dcstack.o dclist.o dcswap.o dctag.o dcxfer.o \
	dcobject.o dcelem.o dcitem.o dcmetinf.o dcdatset.o \
	dcsequen.o dcfilefo.o dcbytstr.o dcpixel.o dcvrae.o dcvras.o dcvrcs.o \
	dccodec.o dcvrda.o dcvrds.o dcvrdt.o dcvris.o dcvrtm.o dcvrui.o \
	dcchrstr.o dcvrlo.o dcvrlt.o dcvrpn.o dcvrsh.o dcvrst.o dcvrobow.o \
	dcvrat.o dcvrss.o dcvrus.o dcvrsl.o dcvrul.o dcvrulup.o dcvrfl.o \
	dcvrfd.o dcvrpobw.o dcvrof.o dcdirrec.o dcdicdir.o dcvm.o \
	dcrleccd.o dcrlecce.o dcrlecp.o dcrlerp.o dcrledrg.o dcrleerg.o \
	$(dictobjs) cmdlnarg.o dcvrut.o dctypes.o dcpcache.o dcddirif.o \
	dcistrma.o dcistrmb.o dcistrmf.o dcistrmz.o \
	dcostrma.o dcostrmb.o dcostrmf.o dcostrmz.o dcwcache.o dcpath.o \
	vrscan.o vrscanl.o
support_objs = mkdeftag.o mkdictbi.o dcdictzz.o
support_progs = mkdeftag mkdictbi

# Extra objects needed by support_progs
support_progs_objs = cmdlnarg.o dctypes.o

library = libdcmdata.$(LIBEXT)


all: $(library)

install: install-lib install-support

install-lib: $(library)
	$(configdir)/mkinstalldirs $(DESTDIR)$(libdir)
	$(INSTALL_DATA) $(library) $(DESTDIR)$(libdir)/$(library)
	$(RANLIB) $(DESTDIR)$(libdir)/$(library)


$(library): $(objs)
ifeq ($(AR),ar)
	$(AR) $(ARFLAGS) $@ $(objs)
else
	$(AR) $(ARFLAGS) $@ $(objs) $(LIBDIRS) $(LOCALLIBS) $(ZLIBLIBS)
endif
	$(RANLIB) $@

mkdeftag: mkdeftag.o $(dictobjs) $(support_progs_objs)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LIBDIRS) -o $@ $@.o $(dictobjs) $(support_progs_objs) $(LOCALLIBS) $(LIBS)

mkdictbi: mkdictbi.o $(dictobjs) $(support_progs_objs)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(LIBDIRS) -o $@ $@.o $(dictobjs) $(support_progs_objs) $(LOCALLIBS) $(LIBS)

mkvrscan:
	flex -8 --header-file=vrscanl.h --outfile=vrscanl.c vrscanl.l


# Generate a new include file of defined tags

gendeftag: mkdeftag $(dicomdic) $(privatedic)
	`pwd`/mkdeftag $(dicomdic) $(privatedic) > $(top_srcdir)/include/dcmtk/dcmdata/dcdeftag.h

# Generate a file which can be used as a builtin dictionary

dcdictzz.cc: mkdictbi $(dicomdic) $(privatedic)
	`pwd`/mkdictbi $(dicomdic) $(privatedic) > dcdictzz.cc

# Generate a builtin data dictionary from $(dicomdic) and $(privatedic)

builtindict: nobuiltindict mkdictbi $(dicomdic) $(privatedic)
	`pwd`/mkdictbi $(dicomdic) $(privatedic) > dcdictbi.cc

# Generate an empty builtin data dictionary

nobuiltindict:
	cp dcdictbi.nul dcdictbi.cc


# Clean-up

clean:
	rm -f $(support_progs) $(support_objs) $(objs) $(library) $(TRASH)

distclean: nobuiltindict clean
	rm -f $(DISTTRASH)


# Dependencies

dependencies:
	$(CXX) -MM $(defines) $(includes) $(CPPFLAGS) $(CXXFLAGS) *.cc  > $(DEP)

include $(DEP)
