#
#  Copyright (C) 2026 Hiroyasu Kamo
# 
#  Permission to use, copy, modify, and distribute this software for any
#  purpose with or without fee is hereby granted, provided that the above
#  copyright notice and this permission notice appear in all copies.
# 
#  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
#  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
#  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
#  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
#  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
#  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

all: add sub subr

main_add.o: main.c peanut.h
	cc -c -DCALCULATE=add main.c -o main_add.o
main_sub.o: main.c peanut.h
	cc -c -DCALCULATE=subtract main.c -o main_sub.o
main_subr.o: main.c peanut.h
	cc -c -DCALCULATE=subtract_in_reverse main.c -o main_subr.o
add.o: add.c peanut.h
	cc -c add.c
sub.o: sub.c peanut.h
	cc -c sub.c
subr.o: subr.c peanut.h
	cc -c subr.c

add: add.o main_add.o
	cc add.o main_add.o -o add
sub: sub.o main_sub.o
	cc sub.o main_sub.o -o sub
subr: subr.o main_subr.o
	cc subr.o main_subr.o -o subr

clean:
	rm -f *.o
distclean: clean
	rm add sub subr
