CC = gcc
# Use ANSI89 and pedantic flags for strict compliance
CFLAGS = -O3 -ansi -pedantic -Wall -fPIC
TCL_INC = /usr/include/tcl8.6
TCL_LIB = -ltcl8.6

# Multi-threading support (pthreads)
# Set USE_THREADS=1 to enable, USE_THREADS=0 to disable
USE_THREADS ?= 1

ifeq ($(USE_THREADS),1)
    CFLAGS += -DUSE_PTHREADS
    LIBS += -lpthread
endif

ifeq ($(SYS_TYPE),IRIX)
    # SGI IRIX specific configuration
    CC = cc
    CFLAGS = -O
    TCL_INC = /usr/freeware/include
    TCL_LIB = /usr/freeware/lib32/libtcl.so
    # IRIX might need -lpthread as well if using pthreads
    ifeq ($(USE_THREADS),1)
        LIBS += -lpthread
    endif
endif

all: fem_solver.so

fem_solver.so: fem_c_solver.c
	$(CC) $(CFLAGS) -I$(TCL_INC) -shared -o $@ fem_c_solver.c $(TCL_LIB) $(LIBS)

clean:
	rm -f fem_solver.so U*.pdf T*.pdf P*.pdf *.log *.aux *.toc *.out *.dvi core
