# ms/Makefile
# This file is part of RCS.
#
# RCS is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# RCS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with RCS; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Report problems and direct all questions to:
#
#    rcs-bugs@cs.purdue.edu
#

# This Makefile allows building OS/2 and DOS executables for RCS. It
# supports the Microsoft/IBM NMAKE program, DMAKE and GNU make. The
# compilers supported are emx 0.8h or newer (gcc 2.5.8) to create
# 32-bit OS/2 or 32-bit DOS executables, Microsoft C 6.00A to create
# 16-bit OS/2 or 16-bit DOS executables and Borland C++ 3.0 to create
# 16-bit DOS executables.

# default target
default:
	@echo "Available targets:"
	@echo "	emx emx-debug emxdos"
	@echo "	msc msc-debug mscdos mscdos-debug"

# ----- start of configuration section -----

# emx 0.8h (gcc) -> 32-bit OS/2 executables
emx:
	$(MAKE) all -f ms/Makefile EMX="" \
	CC="gcc -Zomf -Zmtd" \
	CCFLAGS="-O -D__OS2__" \
	LDFLAGS="-Zstack 512 -s ms/rcs.def" \
	DLDFLAGS="-Zdll -s"
emx-debug:
	$(MAKE) all -f ms/Makefile EMX="" O=.o A=.a \
	CC="gcc -g" \
	CCFLAGS="-D__OS2__"

# emx 0.8h (gcc) -> 32-bit DOS executables
emxdos:
	$(MAKE) all -f ms/Makefile EMX="" OS="dos" O=.o A=.a \
	CC="gcc" \
	CCFLAGS="-O -D__MSDOS__" \
	LDFLAGS="-s"

# Microsoft C 6.00A -> 16-bit OS/2 (and DOS, family mode) executables
# remove the -Lp option if the default libraries are the protected mode ones
msc:
	$(MAKE) all -f ms/Makefile MSC="" \
	CC="cl -nologo -AS" \
	CCFLAGS="-Zp -G2s -Ocegit -D__MSC__ -D__OS2__" \
	LDFLAGS="-F 4000 -Lp setargv.obj ms\rcs.def -link /noe"
#	BIND="bind -nologo" \
#	BFLAGS="-n DOSGETPROCADDR DOSLOADMODULE DOSFREEMODULE"
msc-debug:
	$(MAKE) all -f ms/Makefile MSC="" \
	CC="cl -nologo -Zi -AM" \
	CCFLAGS="-Zp -G2 -Od -D__MSC__ -D__OS2__" \
	LDFLAGS="-F 4000 -Lp ms\rcs.def -link /noe"

# Microsoft C 6.00A -> 16-bit DOS executables
# remove the -Lr option if the default libraries are the real mode ones
mscdos:
	$(MAKE) all -f ms/Makefile MSC="" OS="dos" \
	CC="cl -nologo -AS" \
	CCFLAGS="-Zp -G2s -Ocegit -D__MSC__ -D__MSDOS__" \
	LDFLAGS="-F 4000 -Lr setargv.obj -link /noe"
mscdos-debug:
	$(MAKE) all -f ms/Makefile MSC="" OS="dos" \
	CC="cl -nologo -Zi -AM" \
	CCFLAGS="-Zp -G2s -Od -D__MSC__ -D__MSDOS__" \
	LDFLAGS="-F 4000 -Lr -link /noe"

# defaults:

O = .obj
A = .lib
X = .exe

OS = os2
EMX = emx
MSC = msc
BCC = bcc

# other macros:
CFLAGS = $(CCFLAGS) -Ims -Dmain=rcsmain
OTHER_OBJECT = getcwdsl$O spawnvpq$O login$(OS)$O
REMOVE = del
BIND = echo
BFLAGS = done

# ----- end of configuration section -----
# You shouldn't have to change anything past this point.

# all commands
RCSCOMMANDS = ci.exe co.exe ident.exe merge.exe rcs.exe \
	rcsclean.exe rcsdiff.exe rcsmerge.exe rlog.exe

.SUFFIXES: .c $O .exe

.c$O:
	$(CC) $(CFLAGS) -c $<

$O.exe:
	$(CC) $< rcslib$A -o $@ $(LDFLAGS)
	@$(BIND) $@ $(BFLAGS)

all: $(RCSCOMMANDS)

RCSLIB1 = rcslex$O rcssyn$O rcsgen$O rcsedit$O rcskeys$O rcsmap$O
RCSLIB2 = rcsrev$O rcsutil$O rcsfnms$O partime$O maketime$O
RCSLIB3 = rcskeep$O rcsfcmp$O rcstime$O merger$O version$O
RCSLIB = $(RCSLIB1) $(RCSLIB2) $(RCSLIB3) $(OTHER_OBJECT)

# dynamic/shared library variant, emx, OS/2 only
$(EMX)rcslib.lib: dllinit$O ms/rcslib.def rcslib.dll
	emximp -o $@ ms/rcslib.def
	emxomfar r $@ dllinit$O
$(EMX)rcslib.dll: dllmain$O $(RCSLIB) ms/rcslib.def
	$(CC) dllmain$O $(RCSLIB) -o $@ ms/rcslib.def $(DLDFLAGS)

# For the library targets to work under DOS too, we need to get around
# the stupid DOS command line length limit by using multiple commands.

# static library variant, emx
$(EMX)rcslib.a: libinit$O $(RCSLIB)
	-$(REMOVE) $@
	ar cr $@ $(RCSLIB1)
	ar cr $@ $(RCSLIB2)
	ar cr $@ $(RCSLIB3)
	ar cr $@ libinit$O $(OTHER_OBJECT)
	ar s $@

# static library variant, MS C
$(MSC)rcslib$A: libinit$O $(RCSLIB)
	-$(REMOVE) $@
	lib /nologo /noi $@ $(RCSLIB1);
	lib /nologo /noi $@ $(RCSLIB2);
	lib /nologo /noi $@ $(RCSLIB3);
	lib /nologo /noi $@ libinit$O $(OTHER_OBJECT);

# static library variant, Borland C++
$(BCC)rcslib$A: libinit$O $(RCSLIB)
	-$(REMOVE) $@
	tlib $@ $(RCSLIB1)
	tlib $@ $(RCSLIB2)
	tlib $@ $(RCSLIB3)
	tlib $@ libinit$O $(OTHER_OBJECT)

$(RCSCOMMANDS) : rcslib$A

OBJECT=	ci$O co$O ident$O maketime$O merge$O merger$O partime$O \
	rcs$O rcsclean$O rcsdiff$O rcsedit$O rcsfcmp$O rcsfnms$O \
	rcsgen$O rcskeep$O rcskeys$O rcslex$O rcsmap$O rcsmerge$O \
	rcsrev$O rcssyn$O rcsutil$O rlog$O version$O

$(OBJECT) : ms/conf.h rcsbase.h

getcwdsl$O: ms/getcwdsl.c
	$(CC) $(CFLAGS) -c ms/getcwdsl.c
spawnvpq$O: ms/spawnvpq.c
	$(CC) $(CFLAGS) -c ms/spawnvpq.c
login$(OS)$O: ms/login$(OS).c
	$(CC) $(CFLAGS) -c ms/login$(OS).c

libinit$O: ms/libinit.c
	$(CC) $(CFLAGS) -c ms/libinit.c
dllinit$O: ms/libinit.c
	$(CC) $(CFLAGS) -DDLLINIT -c ms/libinit.c -o $@
dllmain$O: ms/dllmain.c
	$(CC) $(CFLAGS) -c ms/dllmain.c

clean:
	-$(REMOVE) *.o *.a *.obj *.lib *.bak conf.err $(RCSCOMMANDS)
