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

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

# 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

DICTFILE = dicom.dic
PRIVDICTFILE = 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 \
	dcdebug.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
support_objs = mkdeftag.o mkdictbi.o dcdictzz.o
support_progs = mkdeftag mkdictbi
library = libdcmdata.$(LIBEXT)


all: $(library)

install: install-lib install-support

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

install-support: $(DICTFILE) $(PRIVDICTFILE)
	$(configdir)/mkinstalldirs $(libdir)
	if [ "x$(INSTALL_PRIVATE_DICTIONARY)" = "xYES" ] ; then \
		cat $(DICTFILE) $(PRIVDICTFILE) >dicom.tmp ; \
		$(INSTALL_DATA) dicom.tmp $(libdir)/dicom.dic ; \
	else \
		$(INSTALL_DATA) $(DICTFILE) $(libdir)/dicom.dic ; \
	fi


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

distclean: nobuiltindict clean
	rm -f $(DISTTRASH)


$(library): $(objs)
	$(AR) $(ARFLAGS) $@ $(objs)
	$(RANLIB) $@


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

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


# Generate a new include file of defined tags

gendeftag: mkdeftag $(DICTFILE) $(PRIVDICTFILE)
	`pwd`/mkdeftag `pwd`/$(DICTFILE) `pwd`/$(PRIVDICTFILE) > $(top_srcdir)/include/dcdeftag.h

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

dcdictzz.cc: mkdictbi $(DICTFILE) $(PRIVDICTFILE)
	`pwd`/mkdictbi `pwd`/$(DICTFILE) `pwd`/$(PRIVDICTFILE) > dcdictzz.cc

# Generate a builtin data dictionary from $(DICTFILE) and $(PRIVDICTFILE)

builtindict: nobuiltindict mkdictbi $(DICTFILE) $(PRIVDICTFILE)
	`pwd`/mkdictbi `pwd`/$(DICTFILE) `pwd`/$(PRIVDICTFILE) > dcdictbi.cc

# Generate an empty builtin data dictionary

nobuiltindict:
	cp dcdictbi.nul dcdictbi.cc


# Dependencies

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

include $(DEP)
