CC = gcc
# Cross strip when there is one; host `strip` cannot read elf32-morphos.
# See Source/makefile for the full note. Found 09.09.2026.
STRIP := $(shell command -v ppc-morphos-strip 2>/dev/null || echo strip)
CHMOD = chmod
RM = rm

CFLAGS = -O2 -Wall -noixemul
LFLAGS = -noixemul
CDEFS = -DNO_PPCINLINE_STDARG

EXE = AnalogDiff
EXE2 = WbTest

# keep_dtors_nonempty.o: without it EVERY exit crashes (knowledge-db 08 X1).
OBJ = analogdiff.o keep_dtors_nonempty.o
OBJ2 = wbtest.o keep_dtors_nonempty.o

all: $(EXE) $(EXE2)

$(EXE): $(OBJ)
	$(CC) $(OBJ) -o $@.debug $(LFLAGS)
	$(STRIP) --strip-all --strip-unneeded --remove-section .comment $@.debug -o $@
	@sh check_dtors.sh $@.debug $@
	$(CHMOD) +x $(EXE)

$(EXE2): $(OBJ2)
	$(CC) $(OBJ2) -o $@.debug $(LFLAGS)
	$(STRIP) --strip-all --strip-unneeded --remove-section .comment $@.debug -o $@
	@sh check_dtors.sh $@.debug $@
	$(CHMOD) +x $(EXE2)

.c.o:
	$(CC) $(CDEFS) $(CFLAGS) -c $< -o $@

clean:
	$(RM) -f $(OBJ) $(EXE) $(EXE).debug $(OBJ2) $(EXE2) $(EXE2).debug
