##
# MegaZeux Editor Makefile fragment
##

.PHONY: editor_clean editor_target_clean

editor_src = src/editor
editor_obj = src/editor/.build

editor_flags := ${core_flags}

editor_ldflags += ${ZLIB_LDFLAGS} 

ifeq (${PLATFORM},mingw)
editor_spec := -DEDITOR_LIBSPEC="__declspec(dllexport)"
endif

ifeq (${PLATFORM},darwin)
editor_ldflags += -framework Cocoa
endif

ifneq (${X11DIR},)
editor_flags   += -I${X11DIR}/../include
editor_ldflags += -L${X11DIR}/../${RAWLIBDIR} -lX11 ${SDL_LDFLAGS}
endif

${editor_obj}/%.o: ${editor_src}/%.c
	$(if ${V},,@echo "  CC      " $<)
	${CC} -MD ${core_cflags} ${editor_flags} ${editor_spec} -c $< -o $@

# FIXME get zip.o out of here, that's filthy.

editor_objs := \
  ${editor_obj}/board.o ${editor_obj}/block.o ${editor_obj}/clipboard.o    \
  ${editor_obj}/configure.o ${editor_obj}/char_ed.o ${editor_obj}/debug.o  \
  ${editor_obj}/edit.o ${editor_obj}/edit_di.o ${editor_obj}/fill.o        \
  ${editor_obj}/graphics.o ${editor_obj}/macro.o ${editor_obj}/pal_ed.o    \
  ${editor_obj}/param.o ${editor_obj}/robo_debug.o ${editor_obj}/robo_ed.o \
  ${editor_obj}/robot.o ${editor_obj}/select.o ${editor_obj}/sfx_edit.o    \
  ${editor_obj}/undo.o ${editor_obj}/window.o ${editor_obj}/world.o

-include ${editor_objs:.o=.d}

${editor_objs}: $(filter-out $(wildcard ${editor_obj}), ${editor_obj})

ifeq (${BUILD_MODULAR},1)

editor_objs += ${core_obj}/zip.o

editor_target := ${DSOPRE}editor${DSOPOST}

${editor_target}: ${editor_objs} ${core_target}
	$(if ${V},,@echo "  LINK    " $@)
	${CC} ${DSOLDFLAGS} -o $@ ${editor_objs} ${editor_ldflags} \
	  ${LDFLAGS} ${DSOSONAME}$@ ${DSORPATH} -L. -lcore

editor_target_clean:
	$(if ${V},,@echo "  RM      " ${editor_target} ${editor_target}.debug)
	${RM} ${editor_target} ${editor_target}.debug

else

editor_target := ${editor_objs}

editor_target_clean:

endif

editor_clean: editor_target_clean
	$(if ${V},,@echo "  RM      " ${editor_obj})
	${RM} -r ${editor_obj}
