#
# --- GSMP-COPYRIGHT-NOTE-BEGIN ---
# 
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the GSMP-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
# 
# GSMP: dam/Makefile
# General Sound Manipulation Program is Copyright (C) 2000 - 2003
#   Valentin Ziegler and Ren Rebe
# 
# This program 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; version 2. A copy of the GNU General
# Public License can be found at LICENSE.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT-
# ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
# 
# --- GSMP-COPYRIGHT-NOTE-END ---

# The Rules containing all the tricky ruls - some details
# are inspired from the Linux 2.6 kbuild Makefiles ...

# Do not print "Entering directory ..."
MAKEFLAGS += --no-print-directory

# Set the TOPDIR
ifeq ($(origin TOPDIR), undefined)
        TOPDIR = .
endif

# Set CCD (current compile dir) to an initial .
ifeq ($(origin CCD), undefined)
        CCD = .
endif

# Beautify output
silent = 1
Q = @

HOSTCC		= gcc
HOSTCXX		= g++
HOSTCFLAGS	= -Wall -Os -s
HOSTCXXFLAGS	= -Wall -Os -s

# set CROSS_COMPILE to the arch you want to compile for ...

CC		= $(CROSS_COMPILE)gcc
CXX		= $(CROSS_COMPILE)g++
CFLAGS		= -Wall -Os -s
CXXFLAGS	= -Wall -Os -s

GENERATOR_ARGS := -d

# Test and include the configure generate configuration - and scream
# when it is not found!
x=$(shell ls ${TOPDIR}/config.make 2> /dev/null)
ifeq ($(x),$(TOPDIR)/config.make)
        include $(TOPDIR)/config.make
else
        $(error $(TOPDIR)/config.make does not exist. Plese run ./configure!.)
endif

# some default rules

.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)

define LINK
	@echo '  LINK      $@'
        $(Q)$(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) $(LDFLAGS) -o $@ $^
endef

$(SUBDIRS):
	@echo '  ENTERING  $(CCD)/$@ ...'
	$(Q)$(MAKE) -C $@ CCD="$(CCD)/$@" $(MAKECMDGOALS)
	@echo '  LEAVING   $(CCD)/$@ ...'

%: %.o
	@echo '  LINK EXEC $@'
	$(Q)$(CXX) $(CXXFLAGS) $(INCLUDES) $(LIBS) -o $@ $^

%.o: %.cc %.d
	@echo '  CXX       $@'
	$(Q)$(CXX) $(CXXFLAGS) $(INCLUDES) -c -o $@ $<

%.d: %.cc
	@echo '  DEP       $@'
	$(Q)$(CXX) -MM $(CXXFLAGS) $(INCLUDES) $< > $@

%.so: $(OBJS)
	@echo '  LINK SO   $@'
	$(Q)$(CXX) -shared $(CXXFLAGS) $(LDFLAGS) $(LIBS) -o $@ $^

