# Copyright (c) 2023 Emma Tebibyte
# SPDX-License-Identifier: FSFAP
#
# Copying and distribution of this file, with or without modification, are
# permitted in any medium without royalty provided the copyright notice and this
# notice are preserved.  This file is offered as-is, without any warranty.

.POSIX:

PREFIX=/usr/local
CFLAGS=-O3 -s -Wl,-z,noseparate-code,-z,nosectionheader -flto -Lbuild

build: build_dir cat false tail true

clean: build_dir
	rm -rf build/

cat: src/cat.c build_dir lib
	cc $(CFLAGS) -lyac -o build/cat src/cat.c

false: src/false.c build_dir
	cc $(CFLAGS) -o build/false src/false.c

tail: src/tail.c build_dir lib
	cc $(CFLAGS) -lyac -o build/tail src/tail.c

true: src/true.c build_dir
	cc $(CFLAGS) -o build/true src/true.c

lib: src/yac.c src/yac.h
	cc $(CFLAGS) -c -fPIC -o build/yac.o src/yac.c
	cc -shared -o build/libyac.so build/yac.o

build_dir:
	mkdir -p build

install: build
	rm build/*.o
	mkdir -p $(PREFIX)/lib $(PREFIX)/bin
	cp -f build/*.so $(PREFIX)/lib/
	cp -f build/* $(PREFIX)/bin/