#
# This file is part of the Alliance CAD System
# Copyright (C) Laboratoire LIP6 - Dpartement ASIM
# Universite Pierre et Marie Curie
# 
# Home page          : http://www-asim.lip6.fr/alliance/
# E-mail support     : mailto:alliance-support@asim.lip6.fr
# 
# This progam 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.
# 
# Alliance VLSI  CAD System  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 the GNU C Library; see the  file COPYING. If not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

#Makefile for Grog, from Frederic Petrot

include $(TOP)/etc/$(MACHINE).mk
include $(TOP)/etc/libraries.mk

ALC_INC          = -I$(ALLIANCE_INCLUDE) \
                   -DMGN_H='"$(MGN_H)"'\
                   -DMLU_H='"$(MLU_H)"'\
                   -DMPU_H='"$(MPU_H)"'\
                   -DMLO_H='"$(MLO_H)"'\
                   -DMPH_H='"$(MPH_H)"'\
                   -DICU_H='"$(ICU_H)"'\
                   -DICN_H='"$(ICN_H)"'\
                   -DIAC_H='"$(IAC_H)"'\
                   -DMUT_H='"$(MUT_H)"'
ALC_LIB          = -L$(ALLIANCE_LIB) \
                   $(MGN_L) \
                   $(MLU_L) \
                   $(MPU_L) \
                   $(MCP_L) \
                   $(MAP_L) \
                   $(MMG_L) \
                   $(MCL_L) \
                   $(MGL_L) \
                   $(MAL_L) \
                   $(MVL_L) \
                   $(MEL_L) \
                   $(MSL_L) \
                   $(MHL_L) \
                   $(RCN_L) \
                   $(MLO_L) \
                   $(MPH_L) \
                   $(ICU_L) \
                   $(ICC_L) \
                   $(ICA_L) \
                   $(ICN_L) \
                   $(MUT_L) -lm

VERSION          = '"1.6"'

RCSSOURCES = Makefile main.c vtisim.c grog.c grog.h grog_code.yac grog_data.c grog_genview.c grog_layout.c grog_netlist.c grog_outline.c grog_vhdl.c
SOURCE = vtisim.c grog.c grog_layout.c grog_netlist.c grog_vhdl.c grog_code.yac grog_data.c grog_outline.c

OBJ = vtisim.o grog.o grog_layout.o grog_netlist.o grog_vhdl.o grog_code.o grog_data.o grog_outline.o grog_icon.o

#CHECK = -DVTICHECK -DPARSEOUT

LOCAL_CFLAGS     = $(CHECK) $(ALC_INC) -O4   \
                   -DALC=$(ALLIANCE_VERSION) \
                   -DGROG=$(VERSION)

GGR_LIB          = libGgr001.a
GGR_H            = ggr001.h

all : $(TARGET_LIB)/$(GGR_LIB) $(TARGET_INCLUDE)/$(GGR_H) $(TARGET_BIN)/grog

$(TARGET_BIN)/grog : $(TARGET_LIB)/$(GGR_LIB) main.o
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -o $@ main.o $(TARGET_LIB)/$(GGR_LIB) $(ALC_LIB)
	$(STRIP) $(TARGET_BIN)/grog

$(TARGET_LIB)/$(GGR_LIB) $(TARGET_INCLUDE)/$(GGR_H) : $(OBJ)
	$(AR) $(ARFLAGS) $(TARGET_LIB)/$(GGR_LIB) $(OBJ)
	$(RANLIB) $(TARGET_LIB)/$(GGR_LIB)
	-@$(CP) $(GGR_H) $(TARGET_INCLUDE)/$(GGR_H)

main.o : main.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c main.c

grog.o : grog.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c grog.c

grog_layout.o : grog_layout.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c grog_layout.c

grog_netlist.o : grog_netlist.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c grog_netlist.c

grog_data.o : grog_data.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c grog_data.c

grog_outline.o : grog_outline.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c grog_outline.c

grog_vhdl.o : grog_vhdl.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c grog_vhdl.c

grog_code.o : grog_code.yac
	$(YACC) $(YACCFLAGS) grog_code.yac
	$(SED) -e "s/yy/grog/g" -e "s/YY/GROG/g" y.tab.c > grog_code.c
	$(RM) y.tab.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c grog_code.c

grog_icon.o : grog_icon.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c grog_icon.c

vtisim.o : vtisim.c
	$(CC) $(CFLAGS) $(LOCAL_CFLAGS) -c vtisim.c

checkin : 
	echo "y" > 1
	for i in $(RCSSOURCES); do \
		ci -l$(VERSION) -f -m"rcs version number consistency" $$i < 1 ; \
	done
	$(RM) 1

clean :
	-@$(RM) main.o $(OBJ) grog_code.y.c > /dev/null 2>&1

realclean: clean
	-@$(RM) $(TARGET_BIN)/grog $(TARGET_LIB)/$(MMG_LIB) > /dev/null 2>&1
