# @configure_input@
#
# Common rules for octave's libcruft directories.
#
# FIXME -- assumes that the libcruft directory tree is only
# one level deep.
#
# Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2003, 2005,
#               2006, 2007 John W. Eaton
#
# This file is part of Octave.
# 
# Octave 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; either version 3 of the License, or (at
# your option) any later version.
# 
# Octave 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.
# 
# You should have received a copy of the GNU General Public License
# along with Octave; see the file COPYING.  If not, see
# <http://www.gnu.org/licenses/>.


DLL_CDEFS = @CRUFT_DLL_DEFS@
DLL_CXXDEFS = @CRUFT_DLL_DEFS@

CRUFT_FSRC = $(addprefix $(srcdir)/, $(FSRC))
CRUFT_CSRC = $(addprefix $(srcdir)/, $(CSRC))
CRUFT_CXXSRC = $(addprefix $(srcdir)/, $(CXXSRC))

CRUFT_SRC = $(CRUFT_FSRC) $(CRUFT_CSRC) $(CRUFT_CXXSRC)

CRUFT_FBASE = $(basename $(notdir $(CRUFT_FSRC)))
CRUFT_CBASE = $(basename $(notdir $(CRUFT_CSRC)))
CRUFT_CXXBASE = $(basename $(notdir $(CRUFT_CXXSRC)))

CRUFT_BASE = $(CRUFT_FBASE) $(CRUFT_CBASE) $(CRUFT_CXXBASE)

CRUFT_FOBJ = $(addsuffix .o, $(CRUFT_FBASE) )
CRUFT_COBJ = $(addsuffix .o, $(CRUFT_CBASE) )
CRUFT_CXXOBJ = $(addsuffix .o, $(CRUFT_CXXBASE) )

CRUFT_OBJ = $(CRUFT_FOBJ) $(CRUFT_COBJ) $(CRUFT_CXXOBJ)

CRUFT_FDEFS = $(patsubst %.f, %.def, $(notdir $(CRUFT_FSRC)))
CRUFT_CDEFS = $(patsubst %.c, %.def, $(notdir $(CRUFT_CSRC)))
CRUFT_CXXDEFS = $(patsubst %.cc, %.def, $(notdir $(CRUFT_CXXSRC)))

CRUFT_DEFS = $(CRUFT_FDEFS) $(CRUFT_CDEFS) $(CRUFT_CXXDEFS)

DISTFILES = $(CRUFT_SRC) $(addprefix $(srcdir)/, Makefile.in $(SPECIAL))

ifeq ($(SHARED_LIBS), true)
  ifdef FPICFLAG
    CRUFT_FPICOBJ := $(addprefix pic/, $(CRUFT_FOBJ))
  else
    CRUFT_FPICOBJ := $(CRUFT_FOBJ)
  endif
  ifdef CPICFLAG
    CRUFT_CPICOBJ := $(addprefix pic/, $(CRUFT_COBJ))
  else
    CRUFT_CPICOBJ := $(CRUFT_COBJ)
  endif
  ifdef CXXPICFLAG
    CRUFT_CXXPICOBJ := $(addprefix pic/, $(CRUFT_CXXOBJ))
  else
    CRUFT_CXXPICOBJ := $(CRUFT_CXXOBJ)
  endif
  CRUFT_PICOBJ := $(CRUFT_FPICOBJ) $(CRUFT_CPICOBJ) $(CRUFT_CXXPICOBJ)
endif

CWD = $(shell pwd)
THISDIR = $(notdir $(CWD))

ifeq ($(STATIC_LIBS), true)
  LIBCRUFT_DEPEND := $(CRUFT_OBJ)
.PRECIOUS: $(CRUFT_OBJ)
endif

ifeq ($(SHARED_LIBS), true)
  LIBCRUFT_PICDEPEND := $(CRUFT_PICOBJ)
.PRECIOUS: $(CRUFT_PICOBJ)
endif

all: pic $(CRUFT_DEFS) $(LIBCRUFT_DEPEND) $(LIBCRUFT_PICDEPEND)
	@echo "warning: run make in parent directory to update libraries"
.PHONY: all

stmp-pic: pic
	@if [ -f stmp-pic ]; then \
	  true; \
	else \
	  echo "touch stmp-pic"; \
	  touch stmp-pic; \
	fi

pic:
	@if [ -d pic ]; then \
	  true; \
	else \
	  echo "mkdir pic"; \
	  mkdir pic; \
	fi

$(CRUFT_PICOBJ): stmp-pic

$(CRUFT_DEFS): $(TOPDIR)/libcruft/mkf77def

%.def : %.f
	@echo "making $@ from $<"
	@$(TOPDIR)/libcruft/mkf77def < $< > $@-t
	@$(simple-move-if-change-rule)

install:: all
.PHONY: install

install-strip:: all
.PHONY: install-strip

uninstall::
.PHONY: uninstall

tags: $(SOURCES)
	ctags $(SOURCES)

TAGS: $(SOURCES)
	etags $(SOURCES)

clean mostlyclean distclean maintainer-clean::
	rm -f $(MAKEDEPS) $(CRUFT_OBJ) $(CRUFT_PICOBJ) $(CRUFT_DEFS)
	-rmdir pic
	rm -f stmp-pic
.PHONY: clean mostlyclean

distclean maintainer-clean::
	rm -f Makefile
.PHONY: distclean
	
maintainer-clean::
	rm -f tags TAGS
.PHONY: maintainer-clean

dist:
	ln $(EXTERNAL_DISTFILES) ../../`cat ../../.fname`/libcruft/$(THISDIR)
.PHONY: dist
