# Makefile.PC
#
# This is the Makefile for Midnight Commander under OS/2 and Windows NT
#
# 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
# 980329 changed by Pavel Roskin to make it common for OS/2 and NT
#
# Supported Compilers:
#
#    For Windows NT:
#	Makefile.VC4:	Microsoft Visual C++ 4.0 and above
#	Makefile.BC5:	Borland C++ 5.x
#	Makefile.MIN:	MinGW
#	Makefile.RSX:	RSX
#    For OS/2:
#	Makefile.EMX:	EMX/GCC
#	Makefile.BC2:	Borland C++ 2.x
#	Makefile.IBM:	IBM CSet or Visual Age C++
#	...

# ---- Directories
MC_PC_DIR=.
MC_SRC_DIR=../src
VFS_DIR=../vfs
MCEDIT_SRC_DIR=../edit
MCEDIT_OBJS_DIR=$(OBJS_DIR)/edit
SLANG_SRC_DIR=../slang
SLANG_OBJS_DIR=$(OBJS_DIR)/slang
MC_EXE=$(OBJS_DIR)/mc.exe

# --- Midnight Defines
COMMON_DEFINES=-DMC_$(TARGET_OS) $(SPECIFIC_DEFINES)
MC_DEFINES=$(COMMON_DEFINES) -DHAVE_CONFIG_H
MC_INCLUDES=-I$(MC_PC_DIR) -I$(SLANG_SRC_DIR)
SLANG_DEFINES=$(COMMON_DEFINES)
SLANG_INCLUDES=-I$(MC_PC_DIR) -I$(SLANG_SRC_DIR)
MCEDIT_DEFINES=$(COMMON_DEFINES) -DHAVE_CONFIG_H
MCEDIT_INCLUDES=-I$(MC_PC_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


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_PC_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)$@ $<

MC_SRCS= \
	terms.c \
	user.c \
	file.c \
	listmode.c \
	cmd.c \
	command.c \
	help.c \
	menu.c \
	view.c \
	dir.c \
	info.c \
	widget.c \
	option.c \
	dlg.c \
	panelize.c \
	profile.c \
	util.c \
	dialog.c \
	ext.c \
	color.c \
	layout.c \
	setup.c \
	regex.c \
	hotlist.c \
	tree.c \
	win.c \
	complete.c \
	find.c \
	wtools.c \
	boxes.c \
	background.c \
	main.c \
	popt.c \
	text.c \
	screen.c

PC_SRCS= \
	slint_pc.c \
	chmod.c \
	drive.c

NT_SRCS= \
	cons_nt.c \
	dirent_nt.c \
	key_nt.c \
	util_win32.c \
	util_winnt.c \
	util_nt.c

OS2_SRCS= \
	cons_os2.c \
	dirent_os2.c \
	key_os2.c \
	util_os2.c

SLANG_NT=slw32tty.c
SLANG_OS2=slos2tty.c

SLANG_SRCS= \
	slerr.c \
	slgetkey.c \
	slsmg.c \
	slvideo.c \
	$(SLANG_$(TARGET_OS))

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

SRCS=$(MC_SRCS) $(PC_SRCS) $($(TARGET_OS)_SRCS) $(EXTRA_MC_SRCS)

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)))

ifdef RSC

ifndef RES_SUFFIX
RES_SUFFIX=res
endif # RES_SUFFIX

MC_RES=$(OBJS_DIR)/mc.$(RES_SUFFIX)

$(MC_RES): $(MC_PC_DIR)/mc.rc $(MC_PC_DIR)/mc_nt.ico $(MC_PC_DIR)/config.h ../VERSION
	$(RSC) $(RES_PLACE)$(MC_RES) $(RC_DEFINES) $(MC_PC_DIR)/mc.rc

else
MC_RES=
endif # !RSC
