# -*- mode: makefile; coding: latin-9-unix -*-
#% Time-stamp: <2006-12-20 19:54:50 alain> %
#% $Id: Makefile,v 1.1.1.1 2006/12/17 10:36:20 cvsalain Exp $ %
#*******************************************************************************
# Makefile for Tcl/Tk projects
#
# Copyright 2006 by Alain Jaffre <jack.r [at] free.fr>
# Provided under the terms of
# GNU General Public License <http://www.gnu.org/licenses/gpl.html>
#
# It was build for my personal use, but could interest some other people.
# It try to be as generic as possible
#*******************************************************************************

#*******************************************************************************
# Project base name that we want to build
PRJ = mon_projet

#*******************************************************************************
# Directory where are stored all used images
IMGDIR =img

#*******************************************************************************
# Directory where are stored all messages files
MSGDIR =msg

#*******************************************************************************
# Directory where we want resulting files
FINALDIR = final



#*******************************************************************************
# NO CHANGE NEEDED BELOW THAT LINE
#*******************************************************************************




#*******************************************************************************
# Tools
TCLKITDIR = /home/toto/prog/tcl/tclkit/
SDX = sdx
TCLKIT = tclkit
TCLKIT_WIN = tclkit-win32.exe 
TCLKIT_LINUX = tclkit-linux

#*******************************************************************************
# Libraries
LIBDIR = /usr/lib
BWIDGETLIB = bwidget1.7.0

#*******************************************************************************
# Build path
ROOTPATH = $(PRJ).vfs
LIBPATH = $(ROOTPATH)/lib
SRCPATH = $(LIBPATH)/app-$(PRJ)

#*******************************************************************************
# Check what we have to do
ifdef IMGDIR
IMAGES = $(shell ls -l -d $(IMGDIR) | grep d)
endif
ifdef MSGDIR
MESSAGES = $(shell ls -l -d $(MSGDIR) | grep d)
endif
BWIDGET = $(shell cat $(PRJ).tcl | grep BWidget)


.PHONY: help usage kit win32 linux clean proper all

help: usage

usage:
	@echo ""
	@echo "Makefile for tcl/tk projects"
	@echo "USAGE: "
	@echo ""
	@echo "help     - That usage information"
	@echo "usage    - That usage information"
	@echo "kit      - Build the starkit file"
	@echo "win32    - Build the starpack for Windows 32 bits"
	@echo "linux    - Build the starpack for linux x86 32 bits"
	@echo "clean    - Remove all intermediate files"
	@echo "proper   - Remove all files except source ones"
	@echo "all      - Build all files (kit, starpack for win 32, starpack for linux)"
	@echo ""

buildtree: $(PRJ).tcl
	make clean
# source files
	mkdir -p $(SRCPATH)
	cp *.tcl $(SRCPATH)
# images
ifdef IMGDIR
ifeq ($(findstring d,$(IMAGES)),d)
# We really have an images directory so copy it
	mkdir -p $(SRCPATH)/$(IMGDIR)
	cp -f $(IMGDIR)/*.gif $(SRCPATH)/$(IMGDIR)
endif
endif
# messages
ifdef MSGDIR
ifeq ($(findstring d,$(MESSAGES)),d)
# We really have a messages directory so copy it
	mkdir -p $(SRCPATH)/$(MSGDIR)
	cp -f $(MSGDIR)/*.msg $(SRCPATH)/$(MSGDIR)
endif
endif
# libraries
ifeq ($(findstring BWidget,$(BWIDGET)),BWidget)
# we need bwidget library
	cp -r $(LIBDIR)/$(BWIDGETLIB) $(LIBPATH)
endif
# main.tcl
	@echo "package require starkit" > $(ROOTPATH)/main.tcl
	@echo "starkit::startup" >> $(ROOTPATH)/main.tcl
	@echo "package require app-"$(PRJ) >> $(ROOTPATH)/main.tcl

clean:
	rm -rf $(ROOTPATH)

proper:
	make clean
	rm -f $(PRJ).kit
	rm -f $(PRJ).exe
	rm -f $(PRJ)

kit: $(PRJ).tcl
	make buildtree
	$(TCLKITDIR)$(TCLKIT) $(TCLKITDIR)$(SDX) wrap $(PRJ).kit
	make clean

win32: $(PRJ).tcl
	make buildtree
	$(TCLKITDIR)$(TCLKIT) $(TCLKITDIR)$(SDX) wrap $(PRJ).exe -runtime $(TCLKITDIR)$(TCLKIT_WIN)
	make clean

linux: $(PRJ).tcl
	make buildtree
	$(TCLKITDIR)$(TCLKIT) $(TCLKITDIR)$(SDX) wrap $(PRJ) -runtime $(TCLKITDIR)$(TCLKIT_LINUX)
	make clean

all: $(PRJ).tcl
	make buildtree
# kit
	$(TCLKITDIR)$(TCLKIT) $(TCLKITDIR)$(SDX) wrap $(PRJ).kit
# win32
	$(TCLKITDIR)$(TCLKIT) $(TCLKITDIR)$(SDX) wrap $(PRJ).exe -runtime $(TCLKITDIR)$(TCLKIT_WIN)
# linux
	$(TCLKITDIR)$(TCLKIT) $(TCLKITDIR)$(SDX) wrap $(PRJ) -runtime $(TCLKITDIR)$(TCLKIT_LINUX)
	make clean




