# Makefile
# Written by Dan Nicolaescu 
# 970423 hacked by Juan f. Grigera 
# 970525 hacked again by jfg to add internal editor
# 971127 hacked by Pavel Roskin to make it work with mc-4.1.11
# 980206 hacked by Pavel Roskin to make it work with GNU make
#
# This is the Makefile for Midnight Commander under Win32.
#
# Supported Compilers:
#
#	makefile.vc4:	Microsoft Visual C++ 4.x
#	...

# ---- Directories
MC_NT_DIR=../nt
MC_SRC_DIR=../src
MC_INCLUDE_DIR=.
VFS_DIR=../vfs
MCEDIT_SRC_DIR=../edit
MCEDIT_OBJS_DIR=$(OBJS_DIR)/edit
SLANG_SRC_DIR=../slang
SLANG_OBJS_DIR=$(OBJS_DIR)/slang

# --- Midnight Defines
MC_DEFINES=$(SPECIFIC_DEFINES) -D_CONSOLE -DHAVE_CONFIG_H -DUSE_INTERNAL_EDIT
MC_INCLUDES=-I$(MC_SRC_DIR) -I$(MC_NT_DIR) -I$(SLANG_SRC_DIR)
SLANG_DEFINES=$(SPECIFIC_DEFINES)
SLANG_INCLUDES=-I$(MC_NT_DIR) -I$(SLANG_SRC_DIR)
MCEDIT_DEFINES=$(SPECIFIC_DEFINES) -D_CONSOLE -DHAVE_CONFIG_H
MCEDIT_INCLUDES=-I$(MC_NT_DIR) -I$(MC_SRC_DIR)/.. -I$(SLANG_SRC_DIR)

CFLAGS=$(SPECIFIC_MC_CFLAGS) $(MC_INCLUDES) $(MC_DEFINES) -c
SLANG_CFLAGS=$(SPECIFIC_SLANG_CFLAGS) $(SLANG_INCLUDES) $(SLANG_DEFINES) -c
MCEDIT_CFLAGS=$(SPECIFIC_MCEDIT_CFLAGS) $(MCEDIT_INCLUDES) $(MCEDIT_DEFINES) -c
RSC_FLAGS=$(RES_PLACE)$(OBJS_DIR)/mc.res $(RC_DEFINES)

# --- Dependencies
.PHONY: all object-dirs mc clean
all: object-dirs mc 
object-dirs: $(OBJS_DIR) $(SLANG_OBJS_DIR) $(MCEDIT_OBJS_DIR)

mc: $(MC_EXE)

clean: 
	deltree -y "$(SLANG_OBJS_DIR)"
	deltree -y "$(MCEDIT_OBJS_DIR)"
	deltree -y "$(OBJS_DIR)"

$(OBJS_DIR):
	mkdir "$@"

$(SLANG_OBJS_DIR):
	mkdir "$@"

$(MCEDIT_OBJS_DIR):
	mkdir "$@"

$(OBJS_DIR)/%.$(OBJ_SUFFIX): $(MC_NT_DIR)/%.c
	$(CC) $(CFLAGS) $(OBJ_PLACE)$@ $<

$(OBJS_DIR)/%.$(OBJ_SUFFIX): $(MC_SRC_DIR)/%.c
	$(CC) $(CFLAGS) $(OBJ_PLACE)$@ $<

$(SLANG_OBJS_DIR)/%.$(OBJ_SUFFIX): $(SLANG_SRC_DIR)/%.c
	$(CC) $(SLANG_CFLAGS) $(OBJ_PLACE)$@ $<

$(MCEDIT_OBJS_DIR)/%.$(OBJ_SUFFIX): $(MCEDIT_SRC_DIR)/%.c
	$(CC) $(MCEDIT_CFLAGS) $(OBJ_PLACE)$@ $<

SRCS= 	$(EXTRA_MC_SRCS) \
	util.Win32.c \
	util.WinNT.c \
	terms.c \
	user.c \
	utilnt.c \
	subshell.c \
	file.c \
	listmode.c \
	cmd.c \
	dirent.c \
	command.c \
	help.c \
	menu.c \
	view.c \
	dir.c \
	info.c \
	widget.c \
	cons.handler.nt.c \
	option.c \
	dlg.c \
	panelize.c \
	profile.c \
	util.c \
	dialog.c \
	ext.c \
	color.c \
	drive.nt.c \
	key.nt.c \
	layout.c \
	setup.c \
	regex.c \
	hotlist.c \
	slint.nt.c \
	tree.c \
	win.c \
	chmod.nt.c \
	complete.c \
	find.c \
	wtools.c \
	boxes.c \
	background.c \
	dirhist.c \
	main.c \
	popt.c \
	text.c \
	screen.c

SLANG_SRCS= \
	slw32tty.c \
	slerr.c \
	slgetkey.c \
	slsmg.c \
	slvideo.c

MCEDIT_SRCS= \
	edit.c \
	editcmd.c \
	editdraw.c \
	editmenu.c \
	editoptions.c \
	editwidget.c \
	wordproc.c

OBJS=$(addprefix $(OBJS_DIR)/, \
	$(patsubst %.c,%.$(OBJ_SUFFIX),$(SRCS)))

SLANG_OBJS=$(addprefix $(SLANG_OBJS_DIR)/, \
	$(patsubst %.c,%.$(OBJ_SUFFIX),$(SLANG_SRCS)))

MCEDIT_OBJS=$(addprefix $(MCEDIT_OBJS_DIR)/, \
	$(patsubst %.c,%.$(OBJ_SUFFIX),$(MCEDIT_SRCS)))

# --- Resources
ifdef RSC
MC_RES=$(OBJS_DIR)/mc.res
else
MC_RES=
endif

$(OBJS_DIR)/mc.res: $(MC_NT_DIR)/mc.rc $(MC_NT_DIR)/mc.ico $(MC_NT_DIR)/config.h ../VERSION
	$(RSC) $(RSC_FLAGS) $(MC_NT_DIR)/mc.rc
