
################################################################################
##
##  Makefile:  Globals
##
##  Assumptions:    Variable "prefix" already defined
##
##  $Revision: 1.38.2.1 $  $Name: not supported by cvs2svn $
##  $Date: 2005-01-19 02:17:04 $
##
##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
##
###############################################################################

# Determine the operating system and set variable for later conditional use

ifndef OSTYPE
    OSTYPE = $(shell uname -s)
endif

# Set environment variables for the project's directory structure

ifndef mandir
    export mandir = $(prefix)/man
endif

ifndef includedir
    export includedir = $(prefix)/include
endif

ifndef testbindir
    export testbindir = $(prefix)/testbin
endif

ifndef bindir
    export bindir = $(prefix)/bin
endif

ifndef libexecdir
    export libexecdir = $(prefix)/lib
endif

ifndef TIME_CONFIG_FILE
    export TIME_CONFIG_FILE = $(prefix)/config/psTime.config
endif

ifndef TIME_XML_FILE
    export TIME_XML_FILE = $(prefix)/config/psTime.xml
endif

ifndef PS_LIB_VERSION
    export PS_LIB_VERSION = rel4
endif

ifndef sladir
    export sladir = /usr/local/star
endif

ifndef xml2config
    export xml2config = `which xml2-config`
endif

SLA_LINK := $(shell $(sladir)/bin/sla_link)
XML2_LINK := $(shell $(xml2config) --libs)

XML2_CFLAGS := $(shell $(xml2config) --cflags)

# Set initial value for CFLAGS which will include all OS common flags for GCC
GCOVFLAGS :=
CFLAGS := -O0 -g2 -Wall -Werror -std=c99 -D_GNU_SOURCE -pipe $(GCOVFLAGS) $(XML2_CFLAGS)

ifdef NO_TRACE
CFLAGS := $(CFLAGS) -DPS_NO_TRACE=1
endif

# Set initial value for LDFLAGS which will include all OS common flags for GCC and required libraries.

EXTLIBS := -lcfitsio -lgsl -lgslcblas -lfftw3f -L$(sladir)/lib $(SLA_LINK) $(XML2_LINK)
LDFLAGS := -g2 -pipe $(EXTLIBS)

# Define or refine variables for the Linux OS

ifneq "$(findstring inux,$(OSTYPE))" ""
    CFLAGS_RELOC := $(CFLAGS) -fpic
    LDFLAGS_SO := $(LDFLAGS) -fpic -shared -ldl
    LDFLAGS_DLL := $(LDFLAGS) -fpic -shared
    DLL = so
    SO  = so
    DOCS = doxygen Doxyfile
    BUILD_DYNAMIC1 = $(CC) $(LDFLAGS_DLL) -Wl,--whole-archive
    BUILD_DYNAMIC2 = -Wl,--no-whole-archive -lm -o
endif

ifneq "$(findstring arwin,$(OSTYPE))" ""
    CFLAGS += -Wno-long-double -DDARWIN
    CFLAGS_RELOC := $(CFLAGS)
    LDFLAGS := $(LDFLAGS) -lmx
    LDFLAGS_SO := $(LDFLAGS) -bundle -flat_namespace -undefined suppress
    LDFLAGS_DLL := $(LDFLAGS) -dynamiclib
    DLL = dylib
    SO = bundle
    DOCS =
    BUILD_DYNAMIC1 = libtool -dynamic
    BUILD_DYNAMIC2 = -L/usr/local/star/lib -lm -lmx -lgcc $(EXTLIBS) -lg2c -o
endif

# Set default for variable CC

ifndef CC
    export CC=cc
endif

# Set default for variable LD

ifndef LD
    export LD=ld
endif

# Set list of PHONY targets
.PHONY: all install distclean clean docs tags print_header

