# If your make is too ancient to support this syntax,
# either create config.mk and remove the -,
# or remove this line;
-include config.mk

## C Compiler
CC ?= cc

## C Compiler Flags
CFLAGS ?= -g -O0 -ansi -Wall -Wextra -Wno-deprecated-non-prototype -Wno-implicit-int -Wno-return-type

## C Preprocessor Flags
CPPFLAGS ?= -D_GNU_SOURCE -D_BSD_SOURCE -D_XOPEN_SOURCE=700

## Linker Flags
LDFLAGS ?=

## Installation directory
PREFIX ?= /usr/local

BINDIR ?= ${PREFIX}/bin

MANDIR ?= ${PREFIX}/share/man

## Build mk
all: mk

## Remove build artifacts
clean:
	rm -f mk

## Remove even more stuff
distclean: clean
	rm -f Makefile config.log config.h config.h config.mk compile_flags.txt

## Install mk into ${PREFIX}
install: mk mk.1
	mkdir -p ${DESTDIR}${BINDIR} ${DESTDIR}${MANDIR}/man1
	cp -f mk ${DESTDIR}${BINDIR}/
	cp -f mk.1 ${DESTDIR}${MANDIR}/man1/

mk: mk.c compats.c mk.h
	${CC} -o mk.tmp mk.c compats.c ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}
	mv mk.tmp mk
