#
# $Id: Makefile,v 1.6 2004/07/12 19:49:23 bakerj Exp $
#
# ************************** Property of the MITRE Corporation ***************************//
#
# Copyright (c) 2003 - The MITRE Corporation
#
# This file is part of the Query-based Network Assessment project.
#
# The Query-based Network Assessment is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License.
#
# The Query-based Network Assessment is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with the
# Query-based Network Assessment; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ****************************************************************************************//

# output directories
OUTDIR = ./Release
BUILDDIR = ${OUTDIR}/obj

# source directories
SRCDIR = ../../../src/DefinitionInterpreter
REDHATDIR = ${SRCDIR}/redhat
COMMONDIR = ../../../src/common
PROBEDIR = ${COMMONDIR}/probes/redhat
CURRENTDIR = ../../project/redhat/DefinitionInterpreter

INCDIRS = -I/usr/include -I$(COMMONDIR) -I$(REDHATDIR) -I${SRCDIR} -I${PROBEDIR} -I/usr/include/pcre

EXECUTABLE = $(OUTDIR)/ovaldi

# The location of the c++ compiler.
CXX = /usr/bin/g++

# General options that should be used by g++.
CPPFLAGS = -Wall -O

LIBDIR = -L/usr/lib

# What libraries do we need?
LIBS = -lxerces-c -lpcre -lrpm

# Determine what platform the source is being build on
PLATFORM = $(shell uname)

# What object code are we expecting?
OBJS = \
	Main.obj\
	Common.obj \
	DOMCommon.obj \
	DOMOvalDataCollector.obj \
	DOMOvalResultXML.obj \
	DOMOvalXMLAnalyzer.obj \
	DOMProcessor.obj \
	Exception.obj \
	Log.obj \
	MD5.obj \
	REGEX.obj \
	Probe.obj \
	ProbeData.obj \
	DataCollector.obj \
	FileProbe.obj \
	FileAttributeData.obj \
	FilePermissionData.obj \
	InetListeningServersData.obj \
	InetListeningServersProbe.obj \
	ProcessData.obj \
	ProcessProbe.obj \
	RPMInfoData.obj \
	RPMInfoProbe.obj \
	RPMVersionCompareData.obj \
	RPMVersionCompareProbe.obj \
	UnameData.obj \
	UnameProbe.obj \
	Version.obj

REL_OBJS = \
	$(BUILDDIR)/Main.obj\
	$(BUILDDIR)/Common.obj \
	$(BUILDDIR)/DOMCommon.obj \
	$(BUILDDIR)/DOMOvalDataCollector.obj \
	$(BUILDDIR)/DOMOvalResultXML.obj \
	$(BUILDDIR)/DOMOvalXMLAnalyzer.obj \
	$(BUILDDIR)/DOMProcessor.obj \
	$(BUILDDIR)/Exception.obj \
	$(BUILDDIR)/Log.obj \
	$(BUILDDIR)/MD5.obj \
	$(BUILDDIR)/REGEX.obj \
	$(BUILDDIR)/Probe.obj \
	$(BUILDDIR)/ProbeData.obj \
	$(BUILDDIR)/DataCollector.obj \
	$(BUILDDIR)/FileProbe.obj \
	$(BUILDDIR)/FileAttributeData.obj \
	$(BUILDDIR)/FilePermissionData.obj \
	$(BUILDDIR)/InetListeningServersData.obj \
	$(BUILDDIR)/InetListeningServersProbe.obj \
	$(BUILDDIR)/ProcessData.obj \
	$(BUILDDIR)/ProcessProbe.obj \
	$(BUILDDIR)/RPMInfoData.obj \
	$(BUILDDIR)/RPMInfoProbe.obj \
	$(BUILDDIR)/RPMVersionCompareData.obj \
	$(BUILDDIR)/RPMVersionCompareProbe.obj \
	$(BUILDDIR)/UnameData.obj \
	$(BUILDDIR)/UnameProbe.obj \
	$(BUILDDIR)/Version.obj

# Search the output directory for object files
vpath %.obj $(BUILDDIR)
vpath %.cpp $(SRCDIR)
vpath %.cpp $(COMMONDIR)
vpath %.cpp $(REDHATDIR)
vpath %.cpp $(PROBEDIR)


# *******************************************************************
#                      Suffix Translations
# *******************************************************************

.SUFFIXES:
.SUFFIXES: .cpp .obj

.cpp.obj:
	$(CXX) -c $(CPPFLAGS) -D$(PLATFORM) $(INCDIRS) -o $(BUILDDIR)/$@ $^

# *******************************************************************
#                            Rules
# *******************************************************************

all: update set-platform

set-platform:
	@if [ $(PLATFORM) = Linux ]; then \
		make redhat; \
	fi;

	@if [ $(PLATFORM) = SunOS ]; then \
		make sunos; \
	fi;

redhat: PLATFORM = REDHAT
redhat: build


sunos: PLATFORM = SUNOS
sunos: build

update:
	-rm $(BUILDDIR)/Version.obj
	cd ${SRCDIR}; ls; ./updateversion.pl; cd ${CURRENTDIR}

build : $(OBJS)
	$(CXX) $(CPPFLAGS) -D$(PLATFORM) $(REL_OBJS) $(LIBDIR) $(LIBS) -o $(EXECUTABLE)

clean :
	-rm $(REL_OBJS)
	@if [ $(PLATFORM) = Linux ]; then \
		make clean-linux; \
	fi;

	@if [ $(PLATFORM) = SunOS ]; then \
		make clean-sunos; \
	fi;

clean-linux:
	-rm $(OUTDIR)/ovaldi

clean-sunos:
	-rm $(OUTDIR)/ovaldi

debug: CPPFLAGS = -Wall -O -static-libgcc -ggdb
debug: all
