# Abhaengigkeiten

TARGET=fl_i18n
VERSION=0.0.2
COMPILE_OPTIONS=-DUSE_THREADS -DUSE_GETTEXT

BINTARGET = $(TARGET)_example

.ifdef BUILD64
CC =  cc-64
CXX = c++-64
.else
CC = cc
CXX = c++
.endif
COLLECT = ar cru
RANLIB = ranlib
MAKEDEPEND	= $(CXX) -MM
LINK = ln -s
RM = rm -vf
COPY = cp -vdp
INSTALL = install -v

#DEBUG = -DDEBUG
#DL = --ldflags # --ldstaticflags

I18N_CXXFILES = $(TARGET).cxx
I18N_HEADERS = $(TARGET).H
I18N_LIB = $(ICONV) $(INTL) $(LIBNAME)
MSGFMT = msgfmt -c --statistics

#shell=/bin/sh
FLTK_H    !=  fltk-config --cxxflags
FLTK_LIBS !=  fltk-config --use-images --use-gl --ldflags

LIBNAME = lib$(TARGET).a

LIB_LIBS = -L$(libdir) -L./ $(FLTK_LIBS) -L/lib $(DBG_LIBS)
INCL = -I/usr/local/include -I.  -I/usr/include/g++ -I/usr/include

OPTS=-Wall -g $(DEBUG) -L. -Wunused -fno-exceptions $(COMPILE_OPTIONS)
LIBLINK_FLAGS = -shared $(DL) -L. -lc -lm
18N_LIB = $(ICONV) $(INTL) $(LIBNAME)
MSGMERGE = msgmerge
XGETTEXT_OPTIONS = \
	--keyword=gettext \
	--keyword=_ \
	--keyword=N_

TOOLKIT_FILES = $(FLTK_CPPFILES)

ALL_INCL = $(INCL) $(FLTK_H)

CXXFLAGS=$(OPTS) $(ALL_INCL)
CFLAGS = $(OPTS) $(ALL_INCL)

LDLIBS = -L$(libdir) -L./ $(I18N_LIB) $(FLTK_LIBS) \
	-L/lib \
	$(DBG_LIBS)

CPP_HEADERS = \
	threads.h

COMMON_CXXFILES = \
	$(TARGET)_example.cxx

POS_DIR != ls po/*.po 2> /dev/null
LINGUAS != ls po/*.po 2> /dev/null | sed 's/\.po//g' | sed 's%po\/%%g'
LING    := $(POS_DIR) 

COMMON_CFILES = 
CFILES = \
	$(COMMON_CFILES)
CPPFILES = \
	$(COMMON_CPPFILES) \
	$(TOOLKIT_FILES)
CXXFILES = \
	$(COMMON_CXXFILES)
TEST_CPP =
TEST_H = \
	$(TARGET)_example.h

ALL_SOURCEFILES = \
	$(COMMON_CFILES) \
	$(COMMON_CPPFILES) \
	$(FLTK_CPPFILES) \
	$(I18N_CXXFILES) \
	$(CXXFILES) \
	$(TEST_CPP)

ALL_HEADERFILES = \
	$(CPP_HEADERS) \
	$(I18N_HEADERS) \
	$(TEST_H)

DOKU = \
	TODO \
	README \
	ChangeLog \
	COPYING \
	BUGS \
	AUTHORS \
	INSTALL

SOURCES = $(ALL_SOURCEFILES) $(ALL_HEADERFILES)
OBJECTS = $(CPPFILES:.cpp=.o) $(CXXFILES:.cxx=.o)
I18N_OBJECTS =  $(I18N_CXXFILES:.cxx=.o)
LINGUAS_SRC  :=  $(LING:.po=.gmo)

POT_FILE = po/$(TARGET).pot


ALL_FILES =	$(SOURCES) \
	makefile \
	Makefile.bsd \
	$(DOKU)

# get time stamp
C := $(shell date +%C)
MTIME   := `date +%Y%m%e.%H%M%S | sed s/$C//`


all:	dynamic
	
BASE =
	

dynamic:	$(BINTARGET)

$(BINTARGET):	$(BASE) $(OBJECTS) $(LINGUAS_SRC) $(I18N_OBJECTS) $(LIBNAME)
	echo Linking $@ ... $(OBJECTS)
	$(CXX) $(OPTS) -o $(BINTARGET) \
	$(OBJECTS) \
	$(LDLIBS) $(LINK_LIB_PATH) $(LINK_SRC_PATH)
	$(REZ)


$(LIBNAME):	$(I18N_OBJECTS)
	echo Linking $@ ...
	$(COLLECT) $(LIBNAME) $(I18N_OBJECTS)
	$(RANLIB) $(LIBNAME)

strip: $(BINTARGET)
	echo strip $(BINTARGET)
	strip $(BINTARGET)

static_static:	$(OBJECTS)
	$(CXX) $(OPTS) -o $(BINTARGET) \
	$(OBJECTS) \
	$(LDLIBS) -static -ljpeg -lpng -lX11 -lpthread -lz $(DL) \
	-lfreetype -lfontconfig -lXrender -lGLU -lXext -lexpat \
	-L/opt/local/lib
	$(REZ)

$(LINGUAS_SRC):	$(POT_FILE)
	echo Linguas ... $(LINGUAS)
	echo Linguas ... $(LINGUAS_SRC)
	for ling in $(LINGUAS); do \
	  ling_base=po/$${ling}; \
	  echo "update $${ling}.gmo ..."; \
	  test -f $${ling_base}.po \
        && ($(MSGFMT) -o $${ling_base}.gmo $${ling_base}.po; \
            if [ ! -d $${ling_base} ]; then \
              mkdir $${ling_base}; \
            fi; \
            if [ ! -d ./$${ling_base}/LC_MESSAGES ]; then \
              mkdir -v $${ling_base}/LC_MESSAGES; \
            fi; \
            test -L $${ling_base}/LC_MESSAGES/$(TARGET).mo \
              && $(RM) $${ling_base}/LC_MESSAGES/$(TARGET).mo \
              || echo $${ling_base}/LC_MESSAGES/$(TARGET).mo nicht gefunden; \
            ln -s ../../$${ling}.gmo $$ling_base/LC_MESSAGES/$(TARGET).mo;) \
        || (echo $${ling}.po is not yet ready ... skipping) \
	done;

$(POT_FILE):	$(ALL_SOURCEFILES)
	test `which xgettext` && xgettext --force-po $(XGETTEXT_OPTIONS) \
	-d $(TARGET) \
	-o $(POT_FILE) \
	$(SOURCES) || echo -e "\c"
	for ling in $(LINGUAS); do \
            test `which $(MSGMERGE)` && \
                 $(MSGMERGE) $(MSGMERG_OPTS) po/$${ling}.po \
                 $(POT_FILE) || \
	        echo -e "\c"; \
	done;
	echo $(POT_FILE) fertig


clean:
	echo mache sauber $@ ...
	-$(RM) $(OBJECTS) $(I18N_OBJECTS) $(BINTARGET) \
	$(LIBNAME)
	-for ling in $(LINGUAS); do \
	  test -f po/$${ling}.gmo \
        && $(RM) po/$${ling}.gmo; \
	done;
	echo ... $@ fertig


# The extension to use for executables...
EXEEXT		= 

# Build commands and filename extensions...
.SUFFIXES:	.0 .1 .3 .c .cxx .h .fl .man .o .z $(EXEEXT)

.c.o:
	echo Compiling $< ...
	$(CC) $(CFLAGS) -c $<

.cxx.o:
	echo Compiling $< ...
	$(CXX) $(CXXFLAGS) -c $<

.cpp.o:
	echo Compiling $< ...
	$(CXX) $(CXXFLAGS) -c $<

.po:
	echo Generating $@ ...
	msgfmt $<

tgz:
	make DESTDIR=Entwickeln copy_files
	tar cf - Entwickeln/ \
	| gzip > $(TARGET)_$(MTIME).tgz
	test -d Entwickeln && \
	test `pwd` != `(cd Entwickeln; pwd)` && \
	$(RM) -R Entwickeln
	test -d ../../Archiv && mv -v $(TARGET)_*.tgz ../../Archiv

targz:
	make DESTDIR=$(TARGET)_$(VERSION) copy_files
	tar cf - $(TARGET)_$(VERSION)/ \
	| gzip > $(TARGET)_$(MTIME).tgz
	test -d $(TARGET)_$(VERSION) && \
	test `pwd` != `(cd $(TARGET)_$(VERSION); pwd)` && \
	$(RM) -R $(TARGET)_$(VERSION) 
	test -d ../../Archiv && mv -v $(TARGET)_*.tgz ../../Archiv || echo no copy

copy_files:
	echo Copy all fl_i18n files ...
	mkdir $(DESTDIR)
	$(COPY) -R \
	$(ALL_FILES) \
	$(DESTDIR)
	mkdir $(DESTDIR)/po
	$(COPY) $(POT_FILE) $(DESTDIR)/po
	for ling in $(LINGUAS); do \
	  test -f po/$${ling}.po \
        && $(COPY) po/$${ling}.po $(DESTDIR)/po/; \
	done;


dist: $(BASE) targz
	test -f && $(COPY) ../../Archiv/$(TARGET)_$(MTIME).tgz $(TARGET)_$(VERSION).tar.gz || $(COPY) $(TARGET)_$(MTIME).tgz $(TARGET)_$(VERSION).tar.gz


.PHONY: install uninstall
#.SILENT:

