/*
 *                            COPYRIGHT
 *
 *  PCB, interactive printed circuit board design
 *  Copyright (C) 1994 Thomas Nau
 *
 *  This program 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 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Contact addresses for paper mail and Email:
 *  Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
 *  Thomas.Nau@medizin.uni-ulm.de
 *
 *  RCS: $Header: Imakefile,v 1.11 94/07/19 14:11:13 nau Exp $
 */

/* ------------------- start of user configuration ---------------------------
 *
 *   INFODIR:    where to install the GNU-info files
 *   PCBLIBDIR:  where to install fonts...
 * it is set, for example, to /usr/lib/X11/pcb (LIBDIR is defined by imake)
 *
 */
INFODIR = /usr/local/info
PCBLIBDIR = $(LIBDIR)/pcb

/* ----------------------------------------------------------------------
 * You will probably need an additional serachpath for include files
 * if you use OpenWindows
 */
/* EXTRA_INCLUDES  = -I/usr/openwin/include */

/* ----------------------------------------------------------------------
 * Check the following section of architecture dependend settings.
 * If there's a #ifdef - #endif pair for your machine fine; if
 * not you may create a new one (and mail it to the author too if
 * it works) or try the default. Here's some more information:
 *
 * if your system supports atexit() define EXITCALL as -DHAS_ATEXIT
 * if your system has on_exit() but no atexit() like suns with BSD
 * define it as -DHAS_ON_EXIT
 *
 * if you want to take advantage of the dbmalloc package
 *   - define DBMALLOC_INCLUDE as the header file to be included
 *   - add the required library to SYS_LIBRARIES
 *
 * setup the system libraries needed for lex (flex), also add -lm
 *
 */

SYS_LIBRARIES = -ll -lm            /* these are the default libraries */ 

#ifdef SYSV                        /* System V has atexit() */
      EXITCALL = -DHAS_ATEXIT
#endif

#ifdef AnsiDefines                 /* some ANSI CC need additional defines */
     EXTRA_DEFINES  = AnsiDefines
#endif

#ifdef LinuxArchitecture           /* LINUX */
      SYS_LIBRARIES = -lfl -lm
      EXITCALL = -DHAS_ATEXIT
#endif

#ifdef SGIArchitecture             /* Silicon Graphics */
      CCOPTIONS = -D__STDC__
      PROTO_DEFINES = 
      EXITCALL = -DHAS_ATEXIT
#endif

#ifdef HPArchitecture              /* HP */
      EXITCALL = -DHAS_ATEXIT
#endif

#ifdef SunArchitecture             /* Sun */
#if OSMajorVersion < 5             /* BSD */
      EXITCALL = -DHAS_ON_EXIT
#else                              /* Solaris */
      EXITCALL = -DHAS_ATEXIT
#endif
#endif

/* ------------------- end of user configuration ------------------------- */

RELEASE = 1.1.1

COMPRESS = gzip

DEFINES = -DRELEASE=\"$(RELEASE)\" $(EXITCALL) -DPCBLIBDIR=\"$(PCBLIBDIR)\"

PROGRAMS = pcb

SRCS = parse_y.c parse_l.c \
 action.c command.c control.c create.c cursor.c data.c dialog.c \
 draw.c error.c file.c find.c main.c memory.c menu.c misc.c pinout.c \
 print.c remove.c search.c transform.c

OBJS = parse_y.o parse_l.o \
 action.o command.o control.o create.o cursor.o data.o dialog.o \
 draw.o error.o file.o find.o main.o memory.o menu.o misc.o pinout.o \
 print.o remove.o search.o transform.o

FONTS = default_font small_font big_font

DEPLIBS =         $(DEPXAWLIB) $(DEPXTOOLLIB) $(DEPEXTENSIONLIB) $(DEPXLIB) 
LOCAL_LIBRARIES = $(XAWLIB) $(XMULIB) $(XTOOLLIB) $(XLIB) 

ComplexProgramTarget(pcb)
InstallManPage(pcb,$(MANDIR))
InstallAppDefaults(Pcb)
InstallMultipleFlags($(FONTS),$(PCBLIBDIR),$(INSTLIBFLAGS))
InstallMultipleDestFlags(install.info,pcb.info,$(INFODIR),$(INSTLIBFLAGS))

sed.script: Imakefile create_sed_script.sh global.h
	@echo "creating sed-script from defines"
	@./create_sed_script.sh $(DEFINES) Imakefile > $@

pcb.man: pcb.man.raw sed.script
	@echo "creating manual from raw file"
	@sed -f sed.script  < pcb.man.raw > $@

Pcb.ad: Pcb.ad.raw sed.script
	@echo "creating application default resource from raw file"
	@sed -f sed.script  < Pcb.ad.raw > $@

pcb.texi: pcb.texi.raw sed.script
	@echo "creating pcb.texi from raw file"
	@sed -f sed.script  < pcb.texi.raw > $@

pcb.info: pcb.texi
	@echo "creating pcb.info file"
	@makeinfo --no-split pcb.texi

pcb.dvi: pcb.texi
	@echo "creating pcb.dvi file"
	@tex pcb.texi; texindex pcb.fn pcb.vr pcb.cp; tex pcb.texi; tex pcb.texi

parse_y.h parse_y.c: parse_y.y global.h
	$(YACC) -d parse_y.y
	$(MV) y.tab.c parse_y.c
	$(MV) y.tab.h parse_y.h

parse_l.c: parse_l.l parse_y.h global.h
	$(LEX) parse_l.l
	$(MV) lex.yy.c parse_l.c

new::
	make clean
	make

clean::
	$(RM) parse_y.h parse_y.c parse_l.c sed.script

veryclean::
	make clean
	$(RM) pcb.man Pcb.ad pcb.info pcb.dvi

dist::
	@dir=/tmp/pcb-$(RELEASE); \
		echo "creating shipping version `basename $$dir`, please be patient"; \
		if [ -d $$dir ] ; \
			then echo "can't create distribution, $$dir exists" >&2; exit 1; fi; \
		mkdir $$dir; \
		for i in `ls RCS` ; \
			do f=`basename $$i ,v`; \
			if [ ! -f $$f ]; then co $$f; fi; \
			cp $$f $$dir; \
		done; \
		cp -r README_FILES $$dir; \
		cd /tmp; \
		prog=`basename $(COMPRESS)`; \
		if [ "`echo $$prog | cut -c 1`" = "g" ]; \
		then target=$$dir.tar.gz; \
		else target=$$dir.tar.Z; fi; \
		tar cf - `basename $$dir` | $(COMPRESS) > $$target; \
		rm -rf $$dir; \
		echo "$$target is ready to be shipped"
