#
#  Generic make commands (common part of other Make files)
#  For GNU make; will not work with most other make programs
#
#  Variables:
#    bindir		$(tspdir)/bin/
#    includedir		$(tspdir)/include
#    LIB		$(tspdir)/lib/libtsp.a
#    CFLAGS		-O2
#    FFLAGS		-u -O
#    LDFLAGS		-s
#    LINTFLAGS		-u -x
#    LNSFLAGS		-f
#    COMPILER		cc
#    LOADLIBES		$(LIB) -lm
#    BINDIR		bin

# $Id: Make_kernel 1.6 1998/04/15 libtsp-v3r0 $

# Get the OS name
UNAME := $(shell uname -s)
OS = unix

ifeq ($(UNAME),SunOS)
  rev := $(shell uname -r | cut -c1)
  ifeq ($(rev),4)
    OS = SunOS4
  else
    ifeq ($(rev),5)
      OS = SunOS5
    endif
  endif
endif

ifeq ($(UNAME),CYGWIN32_NT)
  OS = CYGWIN32_NT
endif

ifeq ($(UNAME),ULTRIX)
  OS = Ultrix
endif

SHELL = /bin/sh

# Setup for specific operating systems
# Generic unix setup
ifeq ($(OS),unix)
  BINDIR = bin
  LIBDIR = lib
  exec_prefix = /usr/local
endif

# SunOS 4
ifeq ($(OS),SunOS4)
  BINDIR = bin/sun4
  LIBDIR = lib/sun4
  exec_prefix = /usr/local
  CC = cc
  CFLAGS = -O2
endif

# Sun Solaris
ifeq ($(OS),SunOS5)
  BINDIR = bin
  LIBDIR = lib
  exec_prefix = /opt/local
  CC = cc
  CFLAGS = -xO4 -Xc -v
endif

# DEC Ultrix
ifeq ($(OS),Ultrix)
  BINDIR = bin
  LIBDIR = lib
  exec_prefix = /usr/local
  CC = cc
  CFLAGS = -O2
endif

# Gnu software under Windows NT
ifeq ($(OS),CYGWIN32_NT)
  BINDIR = bin
  LIBDIR = lib
  exec_prefix = //D/tsp
  CC = gcc
  CFLAGS = -O3 -Wall
endif

# Set exec_prefix
ifdef tspdir
  exec_prefix = $(tspdir)
endif

libdir = $(exec_prefix)/$(LIBDIR)
bindir = $(exec_prefix)/$(BINDIR)
includedir = $(exec_prefix)/include
htmldir = $(exec_prefix)/html
mandir = $(exec_prefix)/man

# Determine which language will be used
LANG = C
ifeq (.f,$(findstring .f,$(SOURCES)))
  LANG = FORTRAN
endif
ifeq (.F,$(findstring .F,$(SOURCES)))
  LANG = FORTRAN
endif

# Set the default library name
ifeq ($(LANG),FORTRAN)
  LIBNAME_DEFAULT = libuti
else
  LIBNAME_DEFAULT = libtsp
endif
ifndef LIBNAME
  LIBNAME = $(LIBNAME_DEFAULT)
endif
LIB = $(addsuffix .a,$(addprefix $(libdir)/,$(LIBNAME)))

# Options
FFLAGS = -u -O
LDFLAGS = -s
LINTFLAGS = -u -x

LNS = linksoft
LNSFLAGS = -f

# Choose which compiler to use
ifeq ($(LANG),FORTRAN)
  COMPILER = $(FC)
  LOADLIBES = $(LIB)
else
  COMPILER = $(CC)
  LOADLIBES = $(LIB) -lm
endif
