
# Makefile for creating distribution of test package
# Type 'make dist' for create tar-gziped archiv. 

#
# Author: Lubomir Host 'rajo' <rajo AT host.sk>
#

# $Platon: doc/diplomova-praca-rajo/scripts/Makefile,v 1.3 2005/01/16 14:34:56 rajo Exp $ 

PACKAGE = hotGas
VERSION = 1.0

unexport SUBDIRS
unexport SUBDIR_OBJECTS
unexport MAKEFILES
unexport CONFIGURE_SCRIPTS
export PACKAGE
export VERSION

# Directories {{{

srcdir       = .
top_srcdir   = .
distdir      = $(PACKAGE)-$(VERSION)
top_distdir  = $(distdir)
top_builddir = .

# }}} Directories

# Targets

# if you have subdirectories with Makefiles,
# add names of directories here
SUBDIRS   =

# ak subor v $(SOURCES) neexistuje, spravi sa symlinka na tento zdrojak
BASE_SOURCE = hotGas.c
 
# here add names of your source codes
SOURCE_SYMLINKS	= hotGas-drift.c \
				  hotGas-distrib.c

SOURCES			= v-drift-analytic.c
				  #casy-zrazok.c


# name of objects and header files is created
# _automaticaly_ from $(SOURCES) -- you don't need
# change this
OBJECTS          = $(sort $(patsubst %.c,%.o,$(SOURCES) $(SOURCE_SYMLINKS)))
# include_HEADERS = $(sort $(patsubst %.c,%.h,$(SOURCES)))
DEP_FILES        = $(sort $(patsubst %.c,.deps/%.P,$(SOURCES) $(SOURCE_SYMLINKS)))
PROGRAMS         = $(sort $(patsubst %.c,%,$(SOURCES) $(SOURCE_SYMLINKS)))

BASENAME_REGEXP_ = $(sort $(basename $(notdir $(BASE_SOURCE))))
BASENAME_REGEXP  = $(shell echo '$(BASENAME_REGEXP_)' | sed 's/-/_/g; s/ \+/_|/g;' )


DISTFILES = Makefile \
			$(BASE_SOURCE) $(SOURCES) $(include_HEADERS)

# }}} Targets

# Programs {{{

TAR          = tar
ZIP          = zip
ZIP_ENV      = -r9
GZIP_ENV     = --best
             
CC           = gcc
CPP          =
CXX          =
#DEBUG_FLAGS  = -g -ggdb -DDEBUG
CFLAGS       = -Wall -Wshadow $(DEBUG_FLAGS)
CPPFLAGS     =
LDFLAGS      = -L./lib
DEFS         =
INCLUDES     = -I$(srcdir) -I$(top_builddir) -I./include
#LIBS         = -lm -lcfg+ -lDiplomovka
LIBS         = -lm -lcfg+


COMPILE  = $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
CCLD     = $(CC)
LINK     = $(CCLD) $(CFLAGS) $(LDFLAGS) -o $@

echo_COMPILE = $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS)
COMPILE := $(COMPILE) -DCOMPILE_STRING="\"$(COMPILE) $$EXTRA_DEFINES\""

# }}} Programs

all: include/platon/cfg.h $(SOURCES) $(OBJECTS) $(PROGRAMS)

include/platon/cfg.h: libcfg+-0.6.2.tar.gz
	tar xvzf libcfg+-0.6.2.tar.gz
	here=`pwd`; cd libcfg+-0.6.2/ && ./configure --prefix=$$here && $(MAKE) install

libcfg+-0.6.2.tar.gz:
	@echo; echo "Library libcfg+ is needed for succesfull building"
	@echo "Attempting to download from http://platon.sk website ..."
	wget -nH -nd 'http://platon.sk/projects/download.php?id=57&force=1'


print-param:
	@echo "COMPILE = $(COMPILE)"
	@echo "LINK    = $(LINK)"
	@echo "BASENAME_REGEXP = $(BASENAME_REGEXP)"
	@echo

debug:
	$(MAKE) DEBUG_FLAGS="-g -ggdb -DDEBUG"

#$(PROGRAM): $(OBJECTS)
%: %.o
	$(LINK) $@.o $(LIBS)

DEPS_MAGIC := $(shell mkdir .deps > /dev/null 2>&1 || :)
-include $(DEP_FILES)

%.o: %.c
	@EXTRA_DEFINES="`echo '$@' | \
		awk '{	gsub(/-/, \"_\"); \
				sub(/^($(BASENAME_REGEXP)_)/, \" -D\"); \
				if (! /^[ \t]+-D/) \
					sub(/^/, \"-D\"); \
				sub(/\.o$$/, \"\"); \
				print toupper($$0); }'`"; \
	echo "$(echo_COMPILE) $$EXTRA_DEFINES -o $@ -c $<"; \
	$(COMPILE) $$EXTRA_DEFINES -Wp,-MD,.deps/$(*F).pp -o $@ -c $<
	@-cp .deps/$(*F).pp .deps/$(*F).P; \
	tr ' ' '\012' < .deps/$(*F).pp \
	  | sed -e 's/^\\$$//' -e '/^$$/ d' -e '/:$$/ d' -e 's/$$/ :/' \
	    >> .deps/$(*F).P; \
	rm .deps/$(*F).pp

$(BASE_SOURCE):
	ln -s -f ../hotGas.c $@

$(SOURCE_SYMLINKS): $(BASE_SOURCE)
	ln -s -f $< $@;

clean:
	-rm -rf *.o core* .deps/
	-rm -f $(SOURCE_SYMLINKS) $(BASE_SOURCE)
	-rm -rf libcfg+-0.6.2/ include/ lib/ man/ share/

dist:
	make -C ../ dist

# vim600: fdm=marker fdc=3



