# Makefile created with HOSTTYPEs:
#  linux
 
# Makefile created with HOSTTYPEs:
#  linux
 
# Makefile created with HOSTTYPEs:
#  linux
 
# Makefile created with HOSTTYPEs:
#  c++
#  motif
 
# Makefile created with HOSTTYPEs:
#  xw
 
# Makefile created with HOSTTYPEs:
#  ultrix
#  xw
 
# Makefile for NETGEN, Copyright 1990, Massimo Sivilotti, Caltech
#
VERSION=1.05
#
# This makefile should work for UNIX and MSDOS.
# See the directions below.

# Here is the root directory for the sources, for SYSV and GNU makes
# There are some hacks below to make this work with MSDOS Turbo make as well
VPATH=.

# this is the directory to install {netgen, ntk2adl, netcomp}
BINDIR=/usr/local/bin

# this is the directory where netgen.a will be installed
LIBDIR=/usr/local/lib

# this is the directory to install local manual pages
MANDIR=/usr/local/man/man1

# this is the extension for local manual pages
MANEXT=1
#physcmp# MANEXT=1

# include and library dirs for X things, if they are in non-standard places.
#ifi#      XLIBDIR=-L/local/lib
XLIBDIR=-L/usr/X11R6/lib

# name your favorite ANSI-compatible C compiler
# Useful gcc flags:  -pg (profiler), -Wall (enable warnings), -O (optimizer)
#CC=gcc -Wall -g                # gcc 1.37 on HPUX, SUNS, VAX
CC=gcc
#sunos-4.0#   CC=gcc
#turboc-2.0#  CC=tcc -mh       # Turbo C 2.0 on IBM PC
#CC=CC            # ATT C++ 2.0 on Sun3
#physcmp# CC=g++         # experimental

# OLDCC should be a non-ansi compiler (that doesn't need prototypes)
OLDCC=gcc
#             OLDCC=cc
#turboc-2.0#  OLDCC=tcc -w-pro -mh

# UNIX utilities
INSTALL=install
MV=mv
CP=cp
RM=rm
AR=ar
# change this to 'echo' if you don't have/need/want ranlib
RANLIB=ranlib

# UNIX file name extensions, and directory separator character
OBJ=.o
EXE=
LIB=.a
SEPARATOR=/

# PC utilities
#msdos#  INSTALL=copy
#msdos#  MV=rename
#msdos#  CP=copy
#msdos#  RM=erase

# PC file name extensions, and directory separator character
#msdos#  OBJ=.obj
#msdos#  EXE=.exe
#msdos#  LIB=.lib
# the hash following the backslash below is REQUIRED
#msdos#  SEPARATOR=\#

# Useful CCFLAGS are:
#   
#   -O if you trust your optimizer
#   -g for debugger symbols
#   -pg for the gnu profiler
#
#hpux#              CCFLAGS=-O -g
#vax-bsd4.3#        CCFLAGS=
#sunos-4.0#         CCFLAGS=-O -g
#sunos-4.0#   CCFLAGS= -g
#msdos#             CCFLAGS=
# CCFLAGS= -O
CCFLAGS= -O


# Useful OSFLAGS are (see config.h for a complete list):
#
#   -DVMUNIX  
#   -Dsun     --  for sun systems  (along with VMUNIX)
#   -DHPUX    --  for HPUX systems (along with VMUNIX)
#   -DBSD     --  for BSD systems (strings.h, rindex, etc)
#
#   -DIBMPC   --  for IBM PC's
#
#   -DANSI_LIBRARY     -- if you have ANSI-standard libraries
#   -DNEED_PROTOTYPES  -- to use system function prototypes in proto.h
#       (see config.h for any other system-dependent requirements)
#   -DCPLUSPLUS -- for C++
#
#   -DTEST    --  to make a test version (see test.c)
#   -DFAST_STRINGMATCH -- to bypass libc's strcmp with internal inline version
#          (not thoroughly tested!!!)
#

CCXFIX = -DCPLUSPLUS
#hpux#  OSFLAGS=-DVMUNIX -DHPUX -DHAVE_MALLINFO -DTEST -DANSI_LIBRARY $(CCXFIX)
#hpux#  OSFLAGS=-DVMUNIX -DHPUX -DTEST -DANSI_LIBRARY $(CCXFIX)
#sunos-4.0#  OSFLAGS=-DVMUNIX -DBSD -Dsun -DNEED_PROTOTYPES -DHAVE_SYSV_STRING
#sunos-4.0#  OSFLAGS=-DVMUNIX -DBSD -Dsun -DHAVE_SYSV_STRING
#sunos-4.0#  OSFLAGS=-DVMUNIX -DBSD -Dsun  $(CCXFIX)
#vax-bsd4.3# OSFLAGS=-DVMUNIX -DBSD -DNEED_PROTOTYPES -DNEED_VPRINTF -DMAXINT=31999
#msdos#      OSFLAGS=-DIBMPC
OSFLAGS=-DHAVE_SYSV_STRING -Dlinux

# Useful CLIBS
#   -lmalloc  -- if this is a faster/better malloc than libc's
#
#hpux#  CLIBS=-lmalloc
CLIBS=


# Useful XFLAGS
#   -DHAVE_X11 -- if you want to compile the X11 version
#   -DX11_HP_WIDGETS -- if you want to use the Xw widget library
#   -DX11_MOTIF_WIDGETS -- if you want to use the Xm widget library
#   -DX11_ATHENA_WIDGETS -- if you want to use the Xaw widget library
#

#  build using Xaw Widgets
#xaw#        XFLAGS=-DHAVE_X11 -DX11_ATHENA_WIDGETS $(XINCDIR)
#xaw#        XLIBS= $(XLIBDIR) -lXaw -lXmu -lXt -lXext -lX11
#  build using Xw Widgets
# XFLAGS=-DHAVE_X11 -DX11_HP_WIDGETS $(XINCDIR)
# XLIBS= $(XLIBDIR) -lXw -lXt -lX11
#hpux# XLIBS= $(XLIBDIR) -lXw -lXtR2 -lX11
#  build using Xm Widgets (Motif)

# XFLAGS=-DHAVE_X11 -DX11_MOTIF_WIDGETS $(XINCDIR) -I/usr/X11R6/include
# XLIBS= $(XLIBDIR) -lXm -lXt -lX11
XFLAGS=
XLIBS=

#ifi# XFLAGS=-DHAVE_X11 -DX11_MOTIF_WIDGETS $(XINCDIR)
#ifi# XLIBS= $(XLIBDIR) -lXm -lmotifXt /usr/lib/old/libXx11.a

# Support for regular expressions:  See also config.h
#
# define the libraries to get the regexp stuff
REGLIB=

# define the regular expression library you want
#    HAVE_REGCMP  if you have regcmp(3x) and regex(3x) (typically HPUX)
#    HAVE_RE_COMP if you have re_comp and re_exec   (typically SUNS)
#     leave it empty if you have neither, or want to use the supplied regexp
REGEXPFLAGS=-DHAVE_RE_COMP
#hpux#  #REGEXPFLAGS=-DHAVE_REGCMP

# define the objects (if any) to be included in NETGEN library
#    the following are appropriate for REGEXPFLAGS=
#REGOBJS= regerror$(OBJ) regexp$(OBJ) regsub$(OBJ) 
REGOBJS=
#hpux#  #REGOBJS=

# define whatever is needed to compile the regexp library on this system
# See the Makefile in the regexp subdirectory.
#REGEXPDEFS=-DSTRCSPN -Dstrchr=index  # good for all BSD machines
REGEXPDEFS=
#hpux#   REGEXPDEFS=
# the following works for IBM-PC (TurboC gets regexp.h from the current dir)
#msdos#  REGEXPDEFS=-DIBMPC -DNEED_REGEXP


#debugging flags (define DBUG_OFF to disable dbug), maybe use -pg
DBUGFLAGS=-DDBUG_OFF 

#define the DBUG objects (if any) to be included in NETGEN library
#DBUGOBJS=dbug$(OBJ)
DBUGOBJS=

#define whatever is needed to compile dbug.o
# the following works for BSD; sparcs require -fwritable-strings for gcc
#DBUGDEFS=-DBSD4_3 -fwritable-strings    # good for all BSD machines
DBUGDEFS=
#hpux#  DBUGDEFS=
#msdos# DBUGDEFS=-DIBMPC


#############################################################################
#
#  YOU SHOULD NOT NEED TO CHANGE ANYTHING BELOW THIS POINT
#
#############################################################################
CFLAGS=$(CCFLAGS) $(OSFLAGS) $(REGEXPFLAGS) $(DBUGFLAGS) $(XFLAGS)

targets: netgen$(EXE) ntk2adl$(EXE) netcomp$(EXE) inetcomp$(EXE)

OBJS = hash$(OBJ) netgen$(OBJ) objlist$(OBJ) ntk$(OBJ) query$(OBJ) \
       actellib$(OBJ) flatten$(OBJ) netfile$(OBJ) actel$(OBJ) ntk$(OBJ) \
       ccode$(OBJ) ext$(OBJ) wombat$(OBJ) spice$(OBJ) print$(OBJ) \
       netcmp$(OBJ) place$(OBJ) embed$(OBJ) random$(OBJ) greedy$(OBJ) \
       anneal$(OBJ) bottomup$(OBJ) pdutils$(OBJ) timing$(OBJ) 

LIBS = -lm $(REGLIB) $(CLIBS)


# the following are the TurboC/IBM-PC targets

netgen.exe: test$(OBJ) netgen.lib
	$(CC) $(CFLAGS) -enetgen test$(OBJ) netgen.lib

ntk2adl.exe: ntk2adl$(OBJ) netgen.lib
	$(CC) $(CFLAGS) -entk2adl ntk2adl$(OBJ) netgen.lib 

netcomp.exe: netcomp$(OBJ) netgen.lib
	$(CC) $(CFLAGS) -enetcomp netcomp$(OBJ) netgen.lib 

netgen.lib: $(OBJS) $(DBUGOBJS) $(REGOBJS)
	-$(RM) netgen.lib
	tlib /C netgen +hash +netgen +objlist  +query +flatten +ccode
	tlib /C netgen +netfile +ntk +ext +wombat +actel +actellib +spice
	tlib /C netgen +print  +pdutils +timing +netcmp
	tlib /C netgen +place +embed +random +greedy +anneal +bottomup
	-tlib /C netgen +dbug +regexp +regsub +regerror

# the following are the UNIX targets

netgen: test$(OBJ) netgen.a xnetgen.o
	-$(MV) -f netgen netgen.bak
	-$(RM) netgen.bak
	$(CC) $(CFLAGS) -o netgen $(LIBS) $(XLIBS) test$(OBJ) xnetgen.o netgen.a

ntk2adl: ntk2adl$(OBJ) netgen.a 
	-$(MV) -f ntk2adl ntk2adl.bak
	-$(RM) ntk2adl.bak
	$(CC) $(CFLAGS) -o ntk2adl ntk2adl$(OBJ) netgen.a $(LIBS)

inetcomp: inetcomp$(OBJ) netgen.a
	-$(MV) -f inetcomp inetcomp.bak
	-$(RM) inetcomp.bak
	$(CC) $(CFLAGS) -o inetcomp inetcomp$(OBJ) netgen.a $(LIBS)

netcomp: netcomp$(OBJ) netgen.a
	-$(MV) -f netcomp netcomp.bak
	-$(RM) netcomp.bak
	$(CC) $(CFLAGS) -o netcomp netcomp$(OBJ) netgen.a $(LIBS)

netgen.a: $(OBJS) $(DBUGOBJS) $(REGOBJS)
	-$(RM) netgen.a
	$(AR) r netgen.a $(REGOBJS) $(DBUGOBJS) $(OBJS)
	$(RANLIB) netgen.a


#
# below here, nothing is OS-specific
#

test$(OBJ): test.c netgen.h print.h
ntk2adl$(OBJ): ntk2adl.c netgen.h
netcomp$(OBJ): netcomp.c netgen.h

HFILES = netgen.h config.h proto.h hash.h objlist.h query.h print.h


# netgen module contents
#
place$(OBJ): place.c $(HFILES) netfile.h  embed.h timing.h
embed$(OBJ): embed.c $(HFILES) embed.h 
random$(OBJ): random.c $(HFILES) embed.h timing.h
greedy$(OBJ): greedy.c $(HFILES) embed.h timing.h
anneal$(OBJ): anneal.c $(HFILES) embed.h timing.h 
bottomup$(OBJ): bottomup.c $(HFILES) embed.h timing.h
#
hash$(OBJ): hash.c       $(HFILES)
netgen$(OBJ): netgen.c   netfile.h  $(HFILES) 
objlist$(OBJ): objlist.c regexp.h   $(HFILES)
query$(OBJ): query.c       netfile.h  $(HFILES) timing.h
flatten$(OBJ): flatten.c            $(HFILES)
print$(OBJ): print.c print.h config.h
netcmp$(OBJ): netcmp.c    netcmp.h  $(HFILES)
pdutils$(OBJ): pdutils.c  pdutils.h $(HFILES)
timing$(OBJ): timing.h
#
# output file formats
#
netfile$(OBJ): netfile.c   netfile.h $(HFILES)
ntk$(OBJ): ntk.c           netfile.h $(HFILES)
wombat$(OBJ): wombat.c     netfile.h $(HFILES)
ext$(OBJ): ext.c           netfile.h $(HFILES)
actellib$(OBJ): actellib.c netgen.h
actel$(OBJ): actel.c       netfile.h $(HFILES)
spice$(OBJ): spice.c       netfile.h $(HFILES)
ccode$(OBJ): ccode.c       netfile.h $(HFILES)
#
xnetgen$(OBJ): xnetgen.c xnetgen.h timing.h netcmp.h $(HFILES)
	$(OLDCC) $(CFLAGS) -c $(VPATH)$(SEPARATOR)xnetgen.c

# the following are ugly: they try to emulate VPATH for MAKEs that lack it

DBUGDIR=dbug
dbug$(OBJ): $(DBUGDIR)$(SEPARATOR)dbug.c
# this should not be gcc, since dbug.c is primitive-c
	$(OLDCC) -c $(DBUGDEFS) -I$(VPATH)$(SEPARATOR)$(DBUGDIR) \
		$(VPATH)$(SEPARATOR)$(DBUGDIR)$(SEPARATOR)dbug.c


REGEXPDIR=regexp
regerror$(OBJ): $(REGEXPDIR)$(SEPARATOR)regerror.c
	$(OLDCC) -c $(REGEXPDEFS) -I$(VPATH)$(SEPARATOR)$(REGEXPDIR) \
		$(VPATH)$(SEPARATOR)$(REGEXPDIR)$(SEPARATOR)regerror.c
regexp$(OBJ): $(REGEXPDIR)$(SEPARATOR)regexp.c
	$(OLDCC) -c $(REGEXPDEFS) -I$(VPATH)$(SEPARATOR)$(REGEXPDIR) \
		$(VPATH)$(SEPARATOR)$(REGEXPDIR)$(SEPARATOR)regexp.c
regsub$(OBJ): $(REGEXPDIR)$(SEPARATOR)regsub.c
	$(OLDCC) -c $(REGEXPDEFS) -I$(VPATH)$(SEPARATOR)$(REGEXPDIR) \
		$(VPATH)$(SEPARATOR)$(REGEXPDIR)$(SEPARATOR)regsub.c


install: netgen$(EXE) ntk2adl$(EXE) netcomp$(EXE)
	$(INSTALL) netgen$(EXE) $(BINDIR)
	$(INSTALL) ntk2adl$(EXE) $(BINDIR)
	$(INSTALL) netcomp$(EXE) $(BINDIR)
	$(CP) $(VPATH)$(SEPARATOR)netgen.1 \
		   $(MANDIR)$(SEPARATOR)netgen.$(MANEXT)
	$(CP) $(VPATH)$(SEPARATOR)netcomp.1 \
		   $(MANDIR)$(SEPARATOR)netcomp.$(MANEXT)
	$(CP) $(VPATH)$(SEPARATOR)ntk2adl.1 \
		   $(MANDIR)$(SEPARATOR)ntk2adl.$(MANEXT)

clean:
	-$(RM) *$(OBJ)
	-$(RM) core *.bak gmon.out ERRS
	-$(RM) *~ #*

realclean: clean
	-$(RM) netgen$(EXE) ntk2adl$(EXE) netcomp$(EXE) netgen$(LIB)
	-$(RM) netgen-$(VERSION).tar.Z netgen-$(VERSION).tar
	-$(RM) makefile makefile.old

# these are the files that depend on X11
xclean:
	-$(RM) netgen$(EXE) ntk2adl$(EXE) netcomp$(EXE) netgen$(LIB)
	-$(RM) xnetgen$(OBJ) print$(OBJ) test$(OBJ)


# various distribution generators
netgentar: 
	-$(RM) netgen*.tar netgen*.tar.Z
	tar cvf netgen-$(VERSION).tar `cat manifest`
	@echo Distribution made in netgen-$(VERSION).tar

netgentar.Z: 
	-$(RM) netgen*.tar netgen*.tar.Z
	tar cf - `cat manifest` | compress > netgen-$(VERSION).tar.Z
	@echo Distribution made in netgen-$(VERSION).tar.Z

distrib: dist
dist: netgentar.Z



# this code is awaiting the day we have a working deansi or ansi2knr
#.c$(OBJ):
#	indent -psl -br -st < $< > $*.ans.c
#either:	ansi2knr $*.ans.c $*.knr.c
#or:    	deansi < $*.ans.c > $*.knr.c
#	$(CC) $(CFLAGS) -I$(VPATH) -c -o $*.o  $*.knr.c
#	-$(RM) $*.knr.c $*.ans.c 

# NOTE: the $(OBJ) macro expands to have a . as its leading character.
# This is required for the following implicit rule to work
.c$(OBJ):
	$(CC) $(CFLAGS) -c $<
