#!/usr/bin/make -f
#
# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
# SPDX-License-Identifier: BSD-2-Clause

PROG=		triv
SRCS=		trivial.c
OBJS=		trivial.o

CC?=		cc

CPPFLAGS_STD?=	-D_POSIX_SOURCE=200809L -D_XOPEN_SOURCE=700

CPPFLAGS+=	${CPPFLAGS_STD}

CFLAGS_STD?=	-std=c99 -pedantic
CFLAGS_OPT?=	-g -O -pipe
CFLAGS_WARN?=	-Wall -W -Wextra

CFLAGS?=	${CFLAGS_OPT}
CFLAGS+=	${CFLAGS_STD}

LDFLAGS?=

LIBS?=

RM?=		rm -f --

all:		${PROG}

${PROG}:	${OBJS}
		printf -- 'triv-make: About to build %s in %s\n' '${PROG}' "$$(pwd)"
		${CC} ${LDFLAGS} -o ${PROG} ${OBJS} ${LIBS}
		printf -- 'triv-make: Making sure %s was built in %s\n' '${PROG}' "$$(pwd)"
		test -f '${PROG}'
		test -x '${PROG}'
		printf -- 'triv-make: Found %s in %s\n' '${PROG}' "$$(pwd)"

.c.o:
		${CC} -c ${CPPFLAGS} ${CFLAGS} -o $@ $<

clean:
		${RM} ${PROG} ${OBJS}

test:		all
		printf -- 'triv-make: About to run %s in %s\n' '${PROG}' "$$(pwd)"
		./${PROG}
		printf -- 'triv-make: Ran %s in %s\n' '${PROG}' "$$(pwd)"

.PHONY:		all test clean
