#******************************************************************************
#                   Makefile for the GNU Spice GUI C++ Files                  *
#                                                                             *
#  Started     : 18/08/2003                                                   *
#  Last update : 22/02/2008                                                   *
#  Copyright   : (C) 2003 by MSWaters                                         *
#  Email       : M.Waters@bom.gov.au                                          *
#******************************************************************************

#******************************************************************************
#                                                                             *
#     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.                                     *
#                                                                             *
#******************************************************************************

#******************************************************************************
# Any or all of the following values may be set below or on the command line
# when envoking make eg. :
#
#   make GSPICEUI_DBG=1 GSPICEUI_WXLIB=2.6
#
# Note : Values specified on the command line over-ride those specified below.

# Create bin file containing debug info. (ie. for gdb)
GSPICEUI_DBG = 0

# Specify the version of the wxWidgets library to compile against
GSPICEUI_WXLIB = 2.8

#******************************************************************************
# Specify string values
#******************************************************************************

# Which compiler
CC = g++

# Application name
PROG = gspiceui

# wxWidgets configuration utility
# (Arguments can be passed to wx-config to specify the version of wxWidgets to
# use, whether unicode is required, etc.)
WXCFG = wx-config --unicode --version=$(GSPICEUI_WXLIB)

# Dependency file
DEPS = Makefile.deps

# Directories
#ROOT     := $(shell cd .. ; pwd)
ROOT       = ..
SRCDIR     = $(ROOT)/src
OBJDIR     = obj
BINDIR     = $(ROOT)/bin
INSTALLDIR = /usr/local/bin

# Compiler options
ifeq ($(GSPICEUI_DBG),0)
  # Options for release (Not using -Wall since it's GCC specific)
  CXXFLAGS = -O -pipe $(shell $(WXCFG) --cxxflags)
else
  # Options for development
  CXXFLAGS = -Wall -g -pipe $(shell $(WXCFG) --cxxflags)
endif

# Includes
INCLUDES = -I/usr/include -I/usr/X11R6/include -I.

# Libraries
# (The pkg-config stuff was requested by a user, somehow pangox was missing)
LIBS := $(shell $(WXCFG) --libs) $(shell pkg-config --libs pangox)

# Objects
OBJS := $(wildcard *.cpp) $(wildcard */*.cpp) $(wildcard */*/*.cpp)
OBJS := $(notdir $(OBJS))
OBJS := $(patsubst %.cpp, obj/%.o, $(OBJS))

# Search path
vpath  %.cpp  base
vpath  %.cpp  gnucap:gnucap/commands:gnucap/dialogs:gnucap/panels
vpath  %.cpp  main
vpath  %.cpp  netlist
vpath  %.cpp  ngspice:ngspice/commands:ngspice/dialogs:ngspice/panels
vpath  %.cpp  process
vpath  %.cpp  utility

#******************************************************************************
# Make these targets
#******************************************************************************

all : $(OBJS) $(BINDIR)/$(PROG)

# Compiler Rules :
#   $<  is the name of the first dependency
#   $@  is the file name of the target
#   -c  compile only, don't link, produces object file ie. <name>.o files
#   -o  place output file in $@

obj/%.o : %.cpp
	$(CC) -c $(CXXFLAGS) $(INCLUDES) $< -o $@

# Linker Rules :
#   -pipe  use pipes rather temporary files for interprocess communications
#   -o     specify the output file name

$(BINDIR)/$(PROG) : $(OBJS)
	$(CC) -pipe -o $(BINDIR)/$(PROG) obj/*.o $(LIBS)
ifeq ($(ROOT)/GSpiceUI.app,$(wildcard $(ROOT)/GSpiceUI.app))
	cp $(BINDIR)/$(PROG) $(ROOT)/GSpiceUI.app/Contents/MacOS/gspiceui
endif

#******************************************************************************
# Dependencies
#******************************************************************************

ifeq ($(DEPS),$(wildcard $(DEPS)))
  include $(DEPS)
endif

#******************************************************************************
# Create the file containing dependency information
#******************************************************************************

deps :
	$(CC) -MM -D wxCHECK_VERSION="" -I. *.cpp */*.cpp */*/*.cpp | \
	gawk 'BEGIN {} { printf "%s%s\n", (index($$0," ")!=1 ? "$(OBJDIR)/" : ""), $$0 }' \
	> $(DEPS)

#******************************************************************************
# Test utilities
#******************************************************************************

../bin/testcmdngspiceopt : CmdNgSpiceOPT.cpp CmdBase.cpp ConvertType.cpp
	$(CC) $(CXXFLAGS) -Wall -g -D TEST_UTIL $(INCLUDES) $^ -o $@ $(LIBS)
../bin/testcmdngspicepr  : CmdNgSpicePR.cpp CmdBase.cpp
	$(CC) $(CXXFLAGS) -Wall -g -D TEST_UTIL $(INCLUDES) $^ -o $@ $(LIBS)
../bin/testcmdngspicedc  : CmdNgSpiceDC.cpp CmdBase.cpp ConvertType.cpp
	$(CC) $(CXXFLAGS) -Wall -g -D TEST_UTIL $(INCLUDES) $^ -o $@ $(LIBS)
../bin/testcmdngspiceac  : CmdNgSpiceAC.cpp CmdBase.cpp ConvertType.cpp
	$(CC) $(CXXFLAGS) -Wall -g -D TEST_UTIL $(INCLUDES) $^ -o $@ $(LIBS)
../bin/testcmdngspicetr  : CmdNgSpiceTR.cpp CmdBase.cpp ConvertType.cpp
	$(CC) $(CXXFLAGS) -Wall -g -D TEST_UTIL $(INCLUDES) $^ -o $@ $(LIBS)

../bin/testcmdgnucapopt  : CmdGnuCapOPT.cpp CmdBase.cpp ConvertType.cpp
	$(CC) $(CXXFLAGS) -Wall -g -D TEST_UTIL $(INCLUDES) $^ -o $@ $(LIBS)
../bin/testcmdgnucapdc   : CmdGnuCapDC.cpp CmdBase.cpp ConvertType.cpp
	$(CC) $(CXXFLAGS) -Wall -g -D TEST_UTIL $(INCLUDES) $^ -o $@ $(LIBS)
../bin/testcmdgnucapac   : CmdGnuCapAC.cpp CmdBase.cpp ConvertType.cpp
	$(CC) $(CXXFLAGS) -Wall -g -D TEST_UTIL $(INCLUDES) $^ -o $@ $(LIBS)

#******************************************************************************
# Install the application
#******************************************************************************

install :
	cp ../bin/$(PROG) $(INSTALLDIR)/bin

#******************************************************************************
# Uninstall the application
#******************************************************************************

uninstall :
	rm -f $(INSTALLDIR)/bin/$(PROG)

#******************************************************************************
# Remove old versions of files
#******************************************************************************

clean :
	rm -f $(BINDIR)/$(PROG) $(OBJDIR)/*.o

#******************************************************************************
# Specify phony targets
#******************************************************************************

.PHONY : deps install uninstall clean

#******************************************************************************
