PETSC_DIR=/usr/local/petsc/petsc-3.15.0/
PETSC_ARCH=arch-linux-c-with-debug

include $(PETSC_DIR)/lib/petsc/conf/variables
include $(PETSC_DIR)/lib/petsc/conf/rules
include ${PETSC_DIR}/${PETSC_ARCH}/lib/petsc/conf/petscvariables

# CC
CC := mpicc -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas -fvisibility=hidden -g3

# Shared Compiler Flags
CFLAGS := #-c
INC := -I /usr/local/include -I $(PETSC_DIR)/include -I $(PETSC_DIR)/$(PETSC_ARCH)/include
LIB := -L /usr/local/lib $(PETSC_SYS_LIB) $(PETSC_VEC_LIB) -lm

SRC_FILES = coefficient_type_functions.cpp \
			fe_problems2d.cpp \
			fe_problems2dneohooke.cpp \
			mesh2d.cpp \
			mesh2drectangle.cpp \
			meshtools.cpp \
			test_tao_neohooke.cpp
OBJ_FILES = $(SRC_FILES:%.cpp=%.o)

# Make macros:
# $< = first input
# $^ = inputs
# $@ = outputs

.DEFAULT_GOAL := test_tao_neohooke

# Define a make target for non-Petsc source files: any .cc file is compiled into a .o file
%.o: %.cpp %.h
	@echo "Compile..."
	${CC} -c -Wall $< -o $@ ${INC}

objects: $(OBJ_FILES)

test_tao_neohooke: objects
	-${CLINKER} ${OBJ_FILES} -o test_tao_neohooke ${LIB} ${INC}

.PHONY: clean
clean::
	rm test_tao_neohooke
