# Makefile for Unix Frotz
# GNU make is required

SOURCES = sf_fonts.c sf_msg_en.c sf_resource.c sf_util.c \
	sf_deffont.c sf_ftype.c sf_osfdlg.c sf_sig.c sf_video.c \
	sf_font3.c sf_images.c sf_sound.c generic.c

HEADERS = sf_frotz.h

DEFINES = sf_defines.h

OBJECTS = $(SOURCES:.c=.o)

DEPS = $(SOURCES:.c=.d)

TARGET = frotz_sdl.a

ARFLAGS = rc

ifneq ($(NO_PKGCONF), yes)
SDL_CFLAGS += $(shell $(PKGCONF) $(SDL_PKGS) --cflags)
SDL_SOUND_CFLAGS += $(shell $(PKGCONF) $(SDL_SOUND_PKGS) --cflags)
else
SDL_CFLAGS += $(SDL_CFLAGS_DEF)
SD_SOUND_CFLAGS += $(SDL_SOUND_CFLAGS_DEF)
endif


$(TARGET): $(DEFINES) $(OBJECTS) | $(DEFINES)
	$(AR) $(ARFLAGS) $@ $(OBJECTS)
	$(RANLIB) $@
	@echo "** Done with SDL interface."

%.o: %.c
	$(CC) $(CFLAGS) $(SDL_CFLAGS) -fPIC -fpic -o $@ -c $<

$(DEFINES):
	@echo "** Generating $@"
	@echo "/* This file was automatically generated by the build process. */" > $@
	@echo "/* These are defines specific to the SDL interface. */" >> $@
	@echo >> $@
	@echo "#ifndef SDL_DEFINES_H" >> $@
	@echo "#define SDL_DEFINES_H" >> $@
ifeq ($(SOUND_TYPE),none)
	@echo "#define NO_SOUND" >> $@
endif
	@echo "#endif /* SDL_DEFINES_H */" >> $@

clean:
	-rm -f $(TARGET) $(OBJECTS) $(DEPS) $(DEFINES)

.PHONY: clean
.DELETE_ON_ERROR:

