CC = gcc
LD = gcc

CFLAGS = -pipe -pedantic -fpack-struct -Wall -D__OS2__ -O6 -g
# -fno-for-scope 
LFLAGS = -s
LIBS = -lbsd

#.SUFFIXES .c, .o, .obj, .a, .ar, .exe

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

.cpp.o:
	$(CC) $(CFLAGS) -c $<

.c.obj:
	$(CC) $(CFLAGS) -c -Zomf $<

.cpp.obj:
	$(CC) $(CFLAGS) -c -Zomf $<

ob = bink.o brake.o busy.o complete.o getopt.o history.o initdata.o \
     jam.o jamcrc32.o jamfetch.o jamfield.o jamhinfo.o jamlock.o jamlread.o \
     jammbini.o jamscan.o jamstore.o jamsub.o jamsys.o merge.o message.o \
     msg.o mtask.o mtasklow.o origin.o regexp.o regsub.o stat.o t-mail.o \
     emx.o

obj = bink.obj brake.obj busy.obj complete.obj getopt.obj history.obj \
      initdata.obj jam.obj jamcrc32.obj jamfetch.obj jamfield.obj jamhinfo.obj \
      jamlock.obj jamlread.obj jammbini.obj jamscan.obj jamstore.obj \
      jamsub.obj jamsys.obj merge.obj message.obj msg.obj mtask.obj \
      mtasklow.obj origin.obj regexp.obj regsub.obj stat.obj t-mail.obj \
      emx.obj

all: vagaemx.exe vagabnd2.exe

vagaemx.exe:	$(ob)
	$(LD) $(LFLAGS) -o vagaemx.exe $(ob) $(LIBS) -Zcrtdll

vagabnd2.exe:	$(obj)
	$(LD) $(LFLAGS) -o vagabnd2.exe $(obj) $(LIBS) -Zsys -Zomf -Zlinker "/pmtype:vio"

#-----------------------------------

bink.o:		bink.cpp busy.h emx.h
brake.o:	brake.cpp busy.h emx.h
busy.o:		busy.cpp busy.h emx.h
complete.o:	complete.cpp busy.h emx.h
getopt.o:	getopt.c busy.h emx.h
history.o:	history.cpp busy.h emx.h
jam.o:		jam.cpp busy.h emx.h
jamcrc32.o:	jamcrc32.c
jamfetch.o:	jamfetch.c
jamfield.o:	jamfield.c
jamhinfo.o:	jamhinfo.c
jamlock.o:	jamlock.c
jamlread.o:	jamlread.c
jammbini.o:	jammbini.c
jamscan.o:	jamscan.c
jamstore.o:	jamstore.c
jamsub.o:	jamsub.c
jamsys.o:	jamsys.c
merge.o:	merge.cpp busy.h emx.h
message.o:	message.cpp busy.h emx.h
msg.o:		msg.cpp busy.h emx.h
mtask.o:	mtask.cpp busy.h emx.h
mtasklow.o:	mtasklow.c busy.h emx.h
origin.o:	origin.cpp busy.h emx.h
regexp.o:	regexp.c
regsub.o:	regsub.c
stat.o:		stat.cpp busy.h emx.h
t-mail.o:	t-mail.cpp busy.h emx.h

emx.o:		emx.c emx.h

#-----------------------------------

bink.obj:	bink.cpp busy.h emx.h
brake.obj:	brake.cpp busy.h emx.h
busy.obj:	busy.cpp busy.h emx.h
complete.obj:	complete.cpp busy.h emx.h
getopt.obj:	getopt.c busy.h emx.h
history.obj:	history.cpp busy.h emx.h
jam.obj:	jam.cpp busy.h emx.h
jamcrc32.obj:	jamcrc32.c
jamfetch.obj:	jamfetch.c
jamfield.obj:	jamfield.c
jamhinfo.obj:	jamhinfo.c
jamlock.obj:	jamlock.c
jamlread.obj:	jamlread.c
jammbini.obj:	jammbini.c
jamscan.obj:	jamscan.c
jamstore.obj:	jamstore.c
jamsub.obj:	jamsub.c
jamsys.obj:	jamsys.c
merge.obj:	merge.cpp busy.h emx.h
message.obj:	message.cpp busy.h emx.h
msg.obj:	msg.cpp busy.h emx.h
mtask.obj:	mtask.cpp busy.h emx.h
mtasklow.obj:	mtasklow.c busy.h emx.h
origin.obj:	origin.cpp busy.h emx.h
regexp.obj:	regexp.c
regsub.obj:	regsub.c
stat.obj:	stat.cpp busy.h emx.h
t-mail.obj:	t-mail.cpp busy.h emx.h

emx.obj:	emx.c emx.h

#-----------------------------------

initdata.o:	initdata.cpp busy.h emx.h
	$(CC) $(CFLAGS) -c -DOS_MODE=\"EMX\" initdata.cpp

initdata.obj:	initdata.cpp busy.h emx.h
	$(CC) $(CFLAGS) -c -DOS_MODE=\"OS/2\" -Zomf initdata.cpp

#-----------------------------------

clean:	release
	-del /f *.exe >nul 2>&1

release:
	-del /f *.o *.obj *.sym *.dsk >nul 2>&1
