#!/usr/bin/make 
# vim:noet:ai:ts=8:sw=8:filetype=make:nocindent:textwidth=0:
#
# Copyright (C) 2005 Dell Inc.
#  by Michael Brown <Michael_E_Brown@dell.com>
# Licensed under the Open Software License version 2.1 
# 
# Alternatively, 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, 
# or (at your option) any later version.
#
# This program 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.
#
# Note that all 'module.mk' files are "include"-ed in this file and
# fall under the same license.
# 
# This is a standard non-recursive make system.
#

  include version.mk
  RELEASE_VERSION := $(RELEASE_MAJOR).$(RELEASE_MINOR).$(RELEASE_SUBLEVEL)$(RELEASE_EXTRALEVEL)
  RELEASE_STRING := $(RELEASE_NAME)-$(RELEASE_VERSION)
  RPM_RELEASE := 1

  BUILD_DATE := $(shell date "+%Y-%m-%d %H:%M:%S")

#Standard Compiler Flags  
	# To pass in extra args to CFLAGS, CXXFLAGS, or LDFLAGS, use the EXTRA_* 
	# versions from make's command line (see below)
  CXXFLAGS += -DBUILD_DATE="$(BUILD_DATE)" -g -Wall -W -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE  -D_GNU_SOURCE 
  CFLAGS += -DBUILD_DATE="$(BUILD_DATE)" -g -Wall -W -Wbad-function-cast -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE  -D_GNU_SOURCE
  LDFLAGS += -Llib/ $(EXTRA_LDFLAGS)

WARNINGS=-Wpointer-arith -Wfloat-equal -Wcast-qual -Wcast-align -Wwrite-strings -Wredundant-decls -Winline 
WARNINGS_CXX=-Wabi -Wctor-dtor-privacy -Wnon-virtual-dtor  -Wreorder -Woverloaded-virtual -Wsign-promo  -Wsynth -Wold-style-cast
# Would like to enable, but too many stupid warnings. (comma at end of enumerator list, anonymous structs
# -pedantic
# would like to enable, but cannot (too many warnings in system headers.).
#-Weffc++ 
NO_WARN=-Wno-long-long -Wno-inline

#Standard include locations
  CXXFLAGS += -Ilibraries/common/ -Iinclude/ -Llib/ $(EXTRA_CXXFLAGS) $(WARNINGS) $(WARNINGS_CXX) $(NO_WARN) -O2
  CFLAGS += -Ilibraries/common/ -Iinclude/ -Llib/ $(EXTRA_CFLAGS) $(WARNINGS) $(NO_WARN) -O2

#Release history:
# 0.1.0 == 22 Dec 2001 initial import into CVS.

#--------------------------------------------
# Generic Makefile stuff is below. You
#  should not have to modify any of the stuff
#  below.
#--------------------------------------------

  default: noxml
  nothing:

#Included makefiles will add their deps for each stage in these vars:
  RPMS := 

  INSTALL_LIST :=
  INSTALL_DEPS :=

  CLEAN_LIST := 
  CLEAN_DEPS :=

  DISTCLEAN_LIST :=
  DISTCLEAN_DEPS :=

  ALL_DEPS :=
  BASE_BINS :=
  BASE_BINS_STATIC :=
  BASE_LIBS :=
  BASE_STATIC_LIBS :=
  BASE_STATIC_DEBUG_LIBS :=
  EXT_BINS :=
  EXT_BINS_STATIC :=
  EXT_LIBS :=
	

#Define the top-level build directory
  BUILDDIR := $(shell pwd)

  include build/Rules.make-linux
  include build/Rules.make-common

  dir:=libraries
  include libraries/module.mk

  dir:=cppunit
  include cppunit/module.mk

  dir:=doc
  include doc/module.mk

  dir:=bins
  include bins/module.mk

  dir:=supported-bins
  include supported-bins/module.mk

  include common.mk

#Include the docs in the build
#  doc_FILES += COPYING INSTALL README

  all:  $(ALL_DEPS) 
  minimal: $(BASE_BINS) 
  static: $(BASE_BINS_STATIC) $(EXT_BINS_STATIC)

  clean: clean_list $(CLEAN_DEPS) 
  clean_list:
	rm -rf $(CLEAN_LIST)

  distclean: clean distclean_list $(DISTCLEAN_DEPS) 
  distclean_list:
	rm -rf $(DISTCLEAN_LIST)

  install_list: $(INSTALL_LIST)
  install: all $(INSTALL_DEPS) install_list

  .PHONY: tarball rpm
  tarball: $(RELEASE_STRING).tar.bz2
  zip: $(RELEASE_STRING).zip
  rpm: $(RPMS)

  .PHONY: version
  version:
  	@echo "Libsmbios Version: $(RELEASE_VERSION)"

  $(RELEASE_STRING).zip $(RELEASE_STRING).tar.bz2: $(shell find . -name \*.cpp -o -name \*.h -o -name \*.mk -o -name \*.hpp -o -name \*.in ) Makefile 
	$(SIL)[ ! -e $(RELEASE_STRING) ] || rm -rf $(RELEASE_STRING)
	$(SIL)[ ! -e $(RELEASE_STRING).tar.bz2 ] || rm -rf $(RELEASE_STRING).tar.bz2
	$(SIL)[ ! -e $(RELEASE_STRING).zip ] || rm -rf $(RELEASE_STRING).zip
	find . -depth | grep -v ^./$(RELEASE_STRING) | grep -v ^rpm/ | cpio -pdm $(RELEASE_STRING) 
	rm -f $(RELEASE_STRING)/include/smbios/version.h
	$(SIL)make -s -C $(RELEASE_STRING) include/smbios/version.h
	$(SIL)make -s -C $(RELEASE_STRING) libsmbios.spec
	$(SIL)make -s -C $(RELEASE_STRING) libraries/common/StdSmbiosXml.h
	$(SIL)mv $(RELEASE_STRING)/libraries/common/StdSmbiosXml.h $(RELEASE_STRING)/libraries/common/StdSmbiosXml.h-save
	$(SIL)make -s -C $(RELEASE_STRING) distclean
	$(SIL)mv $(RELEASE_STRING)/libraries/common/StdSmbiosXml.h-save $(RELEASE_STRING)/libraries/common/StdSmbiosXml.h
	$(SIL)find $(RELEASE_STRING) -name \*.d -exec rm {} \;
	tar cjf $(RELEASE_STRING).tar.bz2 $(RELEASE_STRING)
	zip -r $(RELEASE_STRING).zip $(RELEASE_STRING)
	$(SIL)rm -rf $(RELEASE_STRING)/

  rpm: tarball
	BLD_DIR=$$(mktemp -d /tmp/rpmbuild-$$$$-XXXXXX); \
	mkdir -p $$BLD_DIR/SOURCES $$BLD_DIR/BUILD $$BLD_DIR/RPMS $$BLD_DIR/RPMS/i386 $$BLD_DIR/RPMS/noarch $$BLD_DIR/SRPMS $$BLD_DIR/SPECS ;\
	rpmbuild --define "_topdir $$BLD_DIR" -ta $(RELEASE_STRING).tar.bz2  ;\
	cp $$BLD_DIR/RPMS/*/*rpm .	;\
	cp $$BLD_DIR/SRPMS/*rpm .	;\
	rm -rf $$BLD_DIR

  srpm: tarball
	BLD_DIR=$$(mktemp -d /tmp/rpmbuild-$$$$-XXXXXX); \
	mkdir -p $$BLD_DIR/SOURCES $$BLD_DIR/BUILD $$BLD_DIR/RPMS $$BLD_DIR/RPMS/i386 $$BLD_DIR/RPMS/noarch $$BLD_DIR/SRPMS $$BLD_DIR/SPECS ;\
	rpmbuild --define "_topdir $$BLD_DIR" -ts --nodeps $(RELEASE_STRING).tar.bz2  ;\
	cp $$BLD_DIR/SRPMS/*rpm .	;\
	rm -rf $$BLD_DIR

  CLEAN_LIST += $(RELEASE_NAME)*.rpm
  CLEAN_LIST += $(RELEASE_STRING).tar.bz2
  CLEAN_LIST += $(RELEASE_STRING).zip
  CLEAN_LIST += $(shell find . -name .\#\* )
  CLEAN_LIST += $(shell find . -name core )
  CLEAN_LIST += $(shell find . -name .\*.swp )
  CLEAN_LIST += $(shell find . -name \*.pyc )
  CLEAN_LIST += testResults.xml
  CLEAN_LIST += tmp/
  CLEAN_LIST += rpm/
  CLEAN_LIST += build/VC*/*/Debug build/VC*/*/Release build/VC*/*/*.plg build/VC*/*.ncb build/VC*/*.opt

  .PHONY: all clean clean_list distclean distclean_list \
  		install install_list 

# Here is a list of variables that are assumed Local to each Makefile. You can
#   safely stomp on these values without affecting the build.
# 	MODULES
#	FILES
#	TARGETS
#	SOURCES
