#
# Makefile for SIR format C programs/library
# written by D. Long at BYU 03 Mar 2017
# revised by D. Long at BYU 12 Oct 2022
#
# Note: be sure to manually edit include/sir3.h to reflect machine/compiler
# type prior to running 
#
# optionally creates dynamic library on linux

# static library name
EXES = libcsir.a

# shared library name
SHRLIB = libcsir.so.2.0.1

# compile flags
CC = gcc -m64 -O2 -lm
# location of sirlib include and library
CFLAGS = -Iinclude
# location of sirlib library
LDFLAGS = -L. -lcsir

.PHONY: all clean

# optional creation of dynamic library -- uncomment $(SHRLIB) on next line to create
all : $(EXES) # $(SHRLIB)
	$(MAKE) -C tools $@;

# create static c routines library
libcsir.a : lib/sir_io.c lib/sir_ez.c lib/sir_geom.c lib/dsir_geom.c lib/dsir_ez.c
	rm -f *.o
	rm -f libcsir.a
	$(CC) $(CFLAGS) -c lib/sir_io.c
	$(CC) $(CFLAGS) -c lib/sir_ez.c
	$(CC) $(CFLAGS) -c lib/sir_geom.c
	$(CC) $(CFLAGS) -c lib/dsir_ez.c
	$(CC) $(CFLAGS) -c lib/dsir_geom.c
	ar cr libcsir.a *.o
	rm -f *.o

# create dynamic c routines library
$(SHRLIB) : lib/sir_io.c lib/sir_ez.c lib/sir_geom.c lib/dsir_geom.c lib/dsir_ez.c
	rm -f *.o
	$(CC) $(CFLAGS) -fPIC -c lib/sir_io.c
	$(CC) $(CFLAGS) -fPIC -c lib/sir_ez.c
	$(CC) $(CFLAGS) -fPIC -c lib/sir_geom.c
	$(CC) $(CFLAGS) -fPIC -c lib/dsir_ez.c
	$(CC) $(CFLAGS) -fPIC -c lib/dsir_geom.c
	$(CC) -shared -Wl,-soname,$(SHRLIB) -o $(SHRLIB) *.o -lc
	rm -f *.o

clean :
	rm -f $(EXES) *.o $(SHRLIB)
	$(MAKE) -C tools $@;
