#  Makefile stub for nodend components of MeTiS 5.1 (including those for GKlib)

#  Nick Gould, for GALAHAD productions
#  This version: 2025-03-07

#  include standard GALAHAD makefile definitions

include $(GALAHAD)/src/makedefs/definitions

.SUFFIXES:
.SUFFIXES: .c _51.o .h _51_64.o

.PHONY: metis51 metis51_silent test test_64
.PHONY: build build_64

# Gklib and metis procedures used

SRC =  memory.c random.c error.c timers.c mcore.c fs.c io.c string.c \
       timing.c fortran.c wspace.c debug.c options.c contig.c graph.c \
       checkgraph.c compress.c bucketsort.c initpart.c mincover.c \
       separator.c refine.c srefine.c balance.c fm.c sfm.c kwayrefine.c \
       kwayfm.c mcutil.c coarsen.c minconn.c util.c mmd.c gklib.c \
       auxapi.c ometis.c

TEST = test_nodend.c
TEST2 = test_nodend2.c

OBJFILE = $(SRC:.c=_51.o)
OBJFILE64 = $(SRC:.c=_51_64.o)
TESTOBJ = $(TEST:.c=_51.o)
TESTOBJ64 = $(TEST:.c=_51_64.o)
TEST2OBJ = $(TEST2:.c=_51.o)
TEST2OBJ64 = $(TEST2:.c=_51_64.o)

CFLAGSM = $(CFLAGS) -DNDEBUG

all: build$(HSL_64)
	@printf ' %-21s\n' "MeTiS 5.1 procedures ($(IPRECIS)$(ISUCC)"
metis51_silent: build$(HSL_64)
build: $(LM5)($(OBJFILE))
build_64: $(LM564)($(OBJFILE64))

$(LM5)($(OBJFILE)): $(SRC)
	@printf ' %-9s %-15s\t\t' "Compiling" $*"_51"
	@$(CC) $(CFLAGSM) $*.c -o $*_51.o
	@$(AR) $(ARREPFLAGS) $@ $*_51.o
	@$(RM) $*_51.o
	@printf '[ OK ]\n'

$(LM564)($(OBJFILE64)): $(SRC)
	@printf ' %-9s %-15s\t\t' "Compiling" $(*:_64=)"_51"
	$(CC) $(CFLAGSM) $*.c -o $*_51_64.o
	$(AR) $(ARREPFLAGS) $@ $*_51_64.o
	$(RM) $*_51_64.o
	@printf '[ OK ]\n'

testall: test$(HSL_64)

test: $(LM5)($(OBJFILE))
	@echo [Run test]
	$(CC) -c $(CFLAGSM) -o $(TESTOBJ) $(TEST)
	$(CC) -o ./test_nodend $(TESTOBJ) -L. -L$(OBJ) -lmetis5_nodend -lm
	./test_nodend
	$(RM) ./test_nodend $(TESTOBJ)

test_64: $(LM564)($(OBJFILE64))
	@echo [Run test 64]
	$(CC) -c $(CFLAGSM) -o $(TESTOBJ64) $(TEST)
	$(CC) -o ./test_nodend $(TESTOBJ64) -L. -L $(OBJ) -lmetis564_nodend -lm
	./test_nodend
#	$(RM) $(TESTOBJ64)
	$(RM) ./test_nodend $(TESTOBJ64)

test2: $(LM5)($(OBJFILE))
	@echo [Run test]
	$(CC) -c $(CFLAGSM) -o $(TEST2OBJ) $(TEST2)
	$(CC) -o ./test_nodend $(TEST2OBJ) -L. -L$(OBJ) -lmetis5_nodend -lm
	./test_nodend
	$(RM) ./test_nodend $(TEST2OBJ)

test2_64: $(LM564)($(OBJFILE64))
	@echo [Run test 64]
	$(CC) -c $(CFLAGSM) -o $(TEST2OBJ64) $(TEST2)
	$(CC) -o ./test_nodend $(TEST2OBJ64) -L. -L $(OBJ) -lmetis564_nodend -lm
	./test_nodend
	$(RM) ./test_nodend $(TEST2OBJ64)

test_gprof: $(LM5)($(OBJFILE))
	@echo [Run test]
	$(CC) -c -pg $(CFLAGSM) -o $(TESTOBJ) $(TEST)
	$(CC) -o ./test_nodend -pg $(TESTOBJ) -L.  -L$(OBJ) -lmetis5_nodend -lm
#	ldd ./test_nodend
#	nm ./test_nodend
	./test_nodend
	gprof ./test_nodend gmon.out > analysis.txt
	$(RM) ./test_nodend  $(TESTOBJ)

cleanall:
	@$(RM) $(OBJFILE) $(LM5) $(OBJFILE64) $(LM564)

clean:
	@$(RM) $(OBJFILE) $(OBJFILE64)
