#######################################################################
LOCATION = xic/src/scrkit
#######################################################################

# This will identify the operating system by calling Xic.  If this
# fails, set this to one of the identifiers in thea ifeq tests below.
VSTR = $(shell xic --v)
OSNAME = $(word 2, $(VSTR))
ARCH = $(word 3, $(VSTR))

# Note that this Makefile can be used for building objects on any of
# the supported operating systems.  Other than for above, you only
# need Xic installed under Windows.

# For Windows, the full path to the directory containing xic.dll,
# change to real location if necessary.
DLL_LOC = c:/usr/local/xictools/bin

# This Makefile originated from this distribution:
#GFX_VERSION = 4.3.12
#OSNAME = LinuxUbuntu22
#CXX = g++
#CC = gcc
#CFLAGS = -O3 -Wall -W -Wshadow -Wwrite-strings -pthread 
#LSHFLAG = -shared
#DEPEND_PROG = $(CC) -MM -O3 -Wall -W -Wshadow -Wwrite-strings -pthread
#FILTER = 
#PIC_OPT = -fPIC
#SOEXT = so

DATE = Sun Aug 28 12:38:08 PDT 2022

# Edit the blocks below if necessary.

ifeq ($(OSNAME),Win32)

# Windows, compiler and libraries from win-builds.org.
CXX = /usr/local/win-builds/bin/g++
CC = /usr/local/win-builds/bin/gcc
CFLAGS = -O -Wall -W -Wshadow -Wwrite-strings -pthread 
LSHFLAG = -shared -Wl,--enable-auto-import,--export-all-symbols
DEPEND_PROG = $(CC) -MM -O3 -Wall -W -Wshadow -Wwrite-strings -pthread
FILTER = |sed -e s/C:// -e s/
//
PIC_OPT = 
SOEXT = dll
WINLIBS = $(DLL_LOC) -lxic

else ifeq ($(OSNAME:Darwin%=Darwin),Darwin)

# Apple OS X
CXX = g++
CC = gcc
CFLAGS = -O -Wall -W -Wshadow -Wwrite-strings -pthread -mmacosx-version-min=10.10 -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
LSHFLAG = -dynamiclib -undefined dynamic_lookup
DEPEND_PROG = $(CC) -MM
FILTER = 
PIC_OPT = 
SOEXT = dylib

else ifeq ($(OSNAME:Linux%=Linux),Linux)
ifeq ($(ARCH),x86_64)

# Generic Linux, covers all 64-bit builds.
CXX = g++
CC = gcc
LINKCC = $(CXX)
CFLAGS = -O -Wall -W -Wshadow -Wwrite-strings -pthread 
LSHFLAG = -shared
DEPEND_PROG = $(CC) -MM
FILTER = 
PIC_OPT = -fPIC
SOEXT = so

else

# Generic Linux, covers all 32-bit builds.
CXX = g++ -m32 -march=$(ARCH)
CC = gcc -m32 -march=$(ARCH)
LINKCC = $(CXX)
CFLAGS = -O -Wall -W -Wshadow -Wwrite-strings -pthread
LSHFLAG = -shared
DEPEND_PROG = $(CC) -MM
FILTER =
PIC_OPT = -fPIC
SOEXT = so

endif
endif

# Add additional libraries here if needed.
LIBS = $(WINLIBS)

HFILES = \
  miscmath.h \
  scrkit.h \
  si_args.h \
  si_if_variable.h \
  si_scrfunc.h
CCFILES = \
  template.cc
CCOBJS = $(CCFILES:.cc=.o)
INCLUDE = -I.

template.$(SOEXT): template.o
	@echo template.$(SOEXT): linking
	@$(CXX) $(LSHFLAG) -o template.$(SOEXT) template.o $(LIBS)

template.o: template.cc $(HFILES)
	$(CXX) $(CFLAGS) $(PIC_OPT) $(INCLUDE) -c $*.cc

.cc.o:
	$(CXX) $(CFLAGS) $(PIC_OPT) $(INCLUDE) -c $*.cc

ifeq (0,1)
miscmath.h:  $(BASE)/include/miscutil/miscmath.h
	cp -f $(BASE)/include//miscutil/miscmath.h .
si_args.h: ../include/si_args.h
	cp -f ../include/si_args.h .
si_if_variable.h: ../include/si_if_variable.h
	cp -f ../include/si_if_variable.h .
si_scrfunc.h: ../include/si_scrfunc.h
	cp -f ../include/si_scrfunc.h .
endif

clean:

distclean:
	-@rm -rf miscmath.h si_args.h si_if_variable.h si_scrfuncs.h Makefile

