/*
 *                            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 2.4 94/10/05 09:16:31 nau Exp $
 */

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

/* ----------------------------------------------------------------------
 * 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
 *
 * a symbol PATCHES is used to pass additional information to
 * the compiler. Additional options are:
 *   -DNEED_STRDUP       if your system doesn't have strdup()
 */

/* ----------------------------------------------------------------------
 * some default values which can be changed in the architecture
 * depending section
 */
SYS_LIBRARIES = -ll -lm         /* these are the default libraries */ 
#ifdef SYSV                     /* System V has atexit() */
      EXITCALL = -DHAS_ATEXIT
#endif

/* ----------------------------------------------------------------------
 * the architecture depending section
 */
#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__    /* thanks to Bernd Leibing */
      PROTO_DEFINES =           /* Bernd.Leibing@e-technik.uni-ulm.de */
      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

#ifdef ArmArchitecture          /* Acorn RISCiX, BSD libraries */
      EXITCALL = -DHAS_ATEXIT   /* thanks to Adrian Godwin */
                                /* agodwin@acorn.co.uk */
                                /* the BSD environment does not define M_PI */
      PATCHES = -DNEED_STRDUP
      CC = /usr/ucb/cc
#endif

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

RELEASE = 1.2

COMPRESS = gzip

DEFINES = -DRELEASE=\"$(RELEASE)\" $(EXITCALL) \
          -DCIRCUITDIR=\"$(CIRCUITDIR)\" \
          -DPACKAGEDIR=\"$(PACKAGEDIR)\" \
          -DPCBLIBDIR=\"$(PCBLIBDIR)\" \
          $(PATCHES)

PROGRAMS = pcb

SRCS = parse_y.c parse_l.c \
 action.c change.c command.c control.c copy.c create.c cursor.c \
 data.c dialog.c draw.c error.c file.c fileselect.c find.c log.c \
 main.c memory.c menu.c misc.c move.c \
 pinout.c print.c printdialog.c printpanner.c remove.c rotate.c \
 search.c select.c update.c

OBJS = parse_y.o parse_l.o \
 action.o change.o command.o control.o copy.o create.o cursor.o \
 data.o dialog.o draw.o error.o file.o fileselect.o find.o log.o \
 main.o memory.o menu.o misc.o move.o \
 pinout.o print.o printdialog.o printpanner.o remove.o rotate.o \
 search.o select.o update.o

FONTS = default_font

ADDITIONALDIR =   circuits packages README_FILES

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

all:: pcb

depend:: parse_l.c parse_y.c

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

install.circuits::
	MakeDir($(CIRCUITDIR))
	@case '${MFLAGS}' in *[i]*) set +e;; esac; 	\
	for i in `ls circuits` ; do 				\
		(set -x; $(INSTALL) -c $(INSTDATFLAGS) circuits/$$i $(CIRCUITDIR));	\
	done
	MakeDir($(PACKAGEDIR))
	@case '${MFLAGS}' in *[i]*) set +e;; esac; 	\
	for i in `ls packages` ; do 				\
		(set -x; $(INSTALL) -c $(INSTDATFLAGS) packages/$$i $(PACKAGEDIR));	\
	done

sed.script: Imakefile create_sed_script.sh const.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 pcb.texi

dist::
	@dir=/tmp/pcb-$(RELEASE); \
		echo "creating public release `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 $(ADDITIONALDIR) $$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"
