## Process this file with automake to produce Makefile.in

AUTOMAKE_OPTIONS = foreign no-dependencies

# Additional files to distribute
EXTRA_DIST = COPYRIGHT README README.ISOLatin2 README.notes

SUBDIRS = @SUBDIRS@

# Menudep program generates menudep.h needed by some of the
# source files for Xcircuit
noinst_PROGRAMS = menudep$(EXEEXT)

menudep$(EXEEXT): menudep.o
	$(CC) -o $@ $@.o

menudep.h: menudep$(EXEEXT)
	./menudep$(EXEEXT)

xcwrap.o: xcwrap.c menudep.h
	$(CC) ${CFLAGS} ${DEFS} $(PATHNAMES) xcwrap.c -c -o xcwrap.o

lib/tcl/xcircuit${SHDLIB_EXT}: xcwrap.o ${xcircuit_OBJECTS}
	$(RM) lib/xcircuit${SHDLIB_EXT}
	$(CC) ${CFLAGS} -o $@ ${LDDL_FLAGS} xcwrap.o ${xcircuit_OBJECTS} \
		${X_LIBS} ${X_EXTRA_LIBS} ${EXTRA_LIBS} -lc ${LIBS}

tcl:	lib/tcl/xcircuit${SHDLIB_EXT}
	$(MAKE) lib/tcl/xcircuit${SHDLIB_EXT}

# Automake files
ac_aux_dir = dist

# Requirements for Xcircuit
bin_PROGRAMS = xcircuit

# Temporary directory (if not overridden by environment variable TMPDIR)
tmpdir = /tmp

# Directory for app-defaults file
appdefaultsdir = $(datadir)/$(PACKAGE)-$(VERSION)/app-defaults

PATHNAMES = -DPROG_VERSION=$(VERSION) \
	-DCAD_DIR=\"$(prefix)\" \
	-DTEMP_DIR=\"$(tmpdir)\" \
	-DRESOURCES_DIR=\"$(appdefaultsdir)\" \
	-DBUILTINS_DIR=\"$(librarydir)\" \
	-DBUILTINS_FILE=\"$(BUILTINS_FILE)\" \
	-DUSER_RC_FILE=\"$(USER_RC_FILE)\" \
	-DPROLOGUE_DIR=\"$(librarydir)\" \
	-DPROLOGUE_FILE=\"$(PROLOGUE_FILE)\" \
	-DSTARTUP_FILE=\"$(STARTUP_FILE)\" \
	-DLGF_LIB=\"$(LGF_LIB)\"

xcircuit_SOURCES = elements.c events.c filelist.c files.c \
	fontfile.c formats.c functions.c help.c keybindings.c \
	libraries.c menucalls.c netlist.c parameter.c python.c \
	rcfile.c render.c schema.c selection.c text.c tclxcircuit.c \
	tkSimple.c tkPixmap.c xcircuit.c

xcircuit_LDADD = @SUBLIB@

help.c: menudep.h
menucalls.c: menudep.h
rcfile.c: menudep.h
schema.c: menudep.h
xcircuit.c: menudep.h

# Man page
M4_DEFS = @M4_DEFS@ @DEFS@
man_MANS = xcircuit.1

# Main compiler arguments
DEFS = @DEFS@ $(PATHNAMES)
INCLUDES = -IXw ${INC_SPECS}
SHDLIB_EXT = @SHDLIB_EXT@
LDDL_FLAGS = @LDDL_FLAGS@

# Library directory and files
librarydir = $(datadir)/$(PACKAGE)-$(VERSION)
USER_RC_FILE = .xcircuitrc
PROLOGUE_FILE = xcircps2.pro
BUILTINS_DEP1 = generic.lps
BUILTINS_DEP2 = analog.lps
BUILTINS_DEP3 = avlsi.lps
BUILTINS_DEP4 = digital.lps
BUILTINS_DEP5 = analoglib2.lps
BUILTINS_DEP6 = ic_templates.lps
BUILTINS_DEP7 = quadparts.lps
LGF_LIB = lgf.lps
SIGNAL_LIB = signal.lps
MUSIC_LIB = musiclib.lps
STARTUP_FILE = @STARTUP_FILE@
INTERP_PATH = @INTERP_PATH@

FONTS_LPS = courier courieriso2 courieriso5 helvetica helveticaiso2 \
	helveticaiso5 myfont symbol times_roman times_romaniso2 \
	times_romaniso5
FONTS_XFE = courier courieriso courieriso2 courieriso5 helvetica \
	helveticaiso helveticaiso2 helveticaiso5 myfont symbol \
	times_roman times_romaniso times_romaniso2 times_romaniso5
SCRIPTS_PY = spice gettext pagebbox

WRAPPER_INIT = xcircuit.tcl
WRAPPER_OBJ = xcircuit${SHDLIB_EXT}
WRAPPER_SH = xcircuit.sh
CONSOLE = tkcon.tcl
CONSOLE_SCRIPT = console.tcl

lib/$(INTERP_PATH)/$(WRAPPER_SH): lib/$(INTERP_PATH)/$(WRAPPER_SH).m4
	$(M4) $(M4_DEFS) $(PATHNAMES) -DLIBDIR=\"$(librarydir)\" \
	-DWRAPPER_INIT=\"$(WRAPPER_INIT)\" -DCONSOLE=\"$(CONSOLE)\" \
	-DCONSOLE_SCRIPT=\"$(CONSOLE_SCRIPT)\" \
	lib/$(INTERP_PATH)/$(WRAPPER_SH).m4 > $@
	chmod 0755 $@

lib/$(INTERP_PATH)/$(WRAPPER_INIT): lib/$(INTERP_PATH)/$(WRAPPER_INIT).m4
	$(M4) $(M4_DEFS) $(PATHNAMES) -DLIBDIR=\"$(librarydir)\" \
	lib/$(INTERP_PATH)/$(WRAPPER_INIT).m4 > $@
	chmod 0755 $@

xcircuit.1: xcircuit.1.m4
	$(M4) $(M4_DEFS) $(PATHNAMES) -DLIBDIR=\"$(libdir)\" xcircuit.1.m4 > $@

install-data-local:
	@echo "Installing app-defaults file"
	$(mkinstalldirs) $(DESTDIR)$(appdefaultsdir)
	$(INSTALL_DATA) XCircuit.ad $(DESTDIR)$(appdefaultsdir)/XCircuit
	@echo "Installing library files"
	$(mkinstalldirs) $(DESTDIR)$(librarydir)
	for lib in $(PROLOGUE_FILE) $(BUILTINS_DEP1) $(BUILTINS_DEP2) \
		$(BUILTINS_DEP3) $(BUILTINS_DEP4) $(BUILTINS_DEP5) \
		$(BUILTINS_DEP6) $(BUILTINS_DEP7) \
		$(LGF_LIB) $(SIGNAL_LIB) $(MUSIC_LIB) \
		$(INTERP_PATH)/$(STARTUP_FILE); do \
		$(INSTALL_DATA) lib/$$lib $(DESTDIR)$(librarydir); \
	done
	@echo "Installing .lps font files"
	$(mkinstalldirs) $(DESTDIR)$(librarydir)/fonts
	for i in $(FONTS_LPS); do \
		$(INSTALL_DATA) lib/fonts/$$i.lps $(DESTDIR)$(librarydir)/fonts; \
	done
	@echo "Installing .xfe font files"
	for i in $(FONTS_XFE); do \
		$(INSTALL_DATA) lib/fonts/$$i.xfe $(DESTDIR)$(librarydir)/fonts; \
	done
	@echo "Installing scripts (if option enabled)"
	if test "$(PYTHON)" != ""; then \
		$(mkinstalldirs) $(DESTDIR)$(librarydir)/python; \
		for i in $(SCRIPTS_PY); do \
			$(INSTALL_DATA) lib/python/$$i.py \
				$(DESTDIR)$(librarydir)/python; \
		done; \
	fi

install-tcl: lib/$(INTERP_PATH)/$(WRAPPER_OBJ) lib/$(INTERP_PATH)/$(WRAPPER_SH) lib/$(INTERP_PATH)/$(WRAPPER_INIT)
	@echo "Installing standard XCircuit library files"
	$(MAKE) $(AM_MAKEFLAGS) install-data-local
	@echo "Installing Tcl files"
	$(mkinstalldirs) $(DESTDIR)$(librarydir)
	for lib in \
		$(WRAPPER_OBJ) $(WRAPPER_INIT) $(CONSOLE) \
		$(CONSOLE_SCRIPT) $(WRAPPER_SCRIPT) $(STARTUP_FILE); do \
		$(INSTALL_DATA) lib/$(INTERP_PATH)/$$lib $(DESTDIR)$(librarydir); \
	done
	chmod 0755 $(DESTDIR)$(librarydir)/$(CONSOLE)
	chmod 0755 $(DESTDIR)$(librarydir)/$(CONSOLE_SCRIPT)
	chmod 0755 $(DESTDIR)$(librarydir)/$(WRAPPER_OBJ)
	@echo "Making link .wishrc to $(WRAPPER_INIT)"
	( cd $(DESTDIR)$(librarydir); \
	  $(RM) .wishrc; \
	  ln -s $(WRAPPER_INIT) .wishrc )
	@echo "Installing pixmap images"
	$(mkinstalldirs) $(DESTDIR)$(librarydir)/pixmaps
	for file in `ls lib/pixmaps`; do \
		$(INSTALL_DATA) lib/pixmaps/$$file $(DESTDIR)$(librarydir)/pixmaps; \
	done
	@echo "Installing shell script as xcircuit executable"
	$(mkinstalldirs) $(DESTDIR)$(bindir)
	$(INSTALL_DATA) lib/$(INTERP_PATH)/$(WRAPPER_SH) $(DESTDIR)$(bindir)/xcircuit
	chmod 0755 $(DESTDIR)$(bindir)/xcircuit

veryclean:
	$(RM) lib/$(INTERP_PATH)/$(WRAPPER_OBJ) lib/$(INTERP_PATH)/$(WRAPPER_SH)
	$(RM) xcircuit *.o *.bak Makefile xcircuit.1 core
	$(RM) menudep$(EXEEXT) menudep.h
	$(RM) config.cache config.log config.status
	(cd ./Xw; $(RM) *.o *.a *.bak Makefile core)

extremelyclean:
	$(RM) xcircuit *.o *.bak core
	$(RM) lib/$(INTERP_PATH)/$(WRAPPER_OBJ) lib/$(INTERP_PATH)/$(WRAPPER_SH)
	$(RM) menudep$(EXEEXT) menudep.h xcircuit.1
	$(RM) install-sh missing mkinstalldirs Makefile.in Makefile
	$(RM) config.* aclocal.m4
	(cd ./Xw; $(RM) *.o *.a *.bak Makefile.in Makefile core)
