Makefile.gnumake

#
# Dependencies:
# 	OpenMPI must be installed
# 	pthreads must be available
#
# Make variables:
# 	MT: Specify the number of workers to use. Defaults to 1 if unspecified
# 	FAST: If defined, use optimization and vector unrolling optimizations
# 	      If not defined, disable optimizations and include debugging symbols
#
# Examples:
# 	`make -f Makefile.gnumake MT=4 FAST=1`

PREFIX = /usr/local
BINDIR = $(PREFIX)/bin

# Source files
SRCS = order-up.c math.c wq.c

# Target executable
PROG = order-up

# Compiler flags
CFLAGS = -W -Wall -Wextra

# Conditional flags based on FAST
ifeq ($(FAST),)
	CFLAGS += -g -O0
else
	CFLAGS += -O3 -flax-vector-conversions
endif

# Linker flags
LDFLAGS = -lm -pthread

# Conditional linker flags and compiler flags based on MT
ifeq ($(MT),)
	CFLAGS += -DNUM_WORKERS=1
else
	CFLAGS += -DNUM_WORKERS=$(MT)
endif

# Compiler
CC = mpicc

# Rules
$(PROG): $(SRCS)
	$(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LDFLAGS)

# Install rule
install: $(PROG)
	mkdir -p $(BINDIR)
	cp $(PROG) $(BINDIR)/

# Clean rule
clean:
	rm -f $(PROG)

.PHONY: clean install