# --- Copyright University of Sussex 1996. All rights reserved. ----------
# File:				C.windows/pop/makefile
# Purpose:			Makefile for building executables and images in POPSYS
# Author:			Robert John Duncan, Jul  4 1994 (see revisions)

!INCLUDE <win32.mak>
!INCLUDE poplog.mak

POPSRC = ..\src
POPOBJLIB = ..\obj
POPEXTERNLIB = ..\extern\lib
POPEXTERNSRC = ..\extern\src

LIB = $(POPEXTERNLIB);$(LIB)

link = $(link) $(linkdebug) -nologo -machine:$(CPU) -ignore:LNK4001

!IFDEF POPNUTC
# Compilation in the NuTCRACKER environment
LIBC = nutc.lib
guilflags = $(lflags) -subsystem:windows,$(APPVER) -entry:mainCRTStartup
!ENDIF

# Standard saved images

images : startup prolog clisp pml

prolog clisp pml :
	$(POP11) +startup %%nort mkimage $@ $@
	-del $@.psv-*

startup :
	$(POP11) %%nort mkimage $@ winved
	-del $@.psv-*

# Syscomp saved images

syscomp : popc poplink poplibr

popc poplink poplibr :
	$(COREPOP11) %%nort <<mk$@.p
		lvars savedir = current_directory;
		'%popsrc%\\syscomp' -> current_directory;
		false -> pop_debugging;
		pop11_compile("make_$@");
		savedir -> current_directory;
		false -> popfilename;
		make_saved_image("$@");
		sysexit();
<<

# Dynamic executables

pop11 :
	$(link) $(conlflags) -out:$@.exe popmain.lib poplog.lib $(LIBC) \
		$(conlibsdll)

winpop11 :
	$(link) $(guilflags) -out:$@.exe popmain.lib poplog.lib $(LIBC) \
		$(guilibsdll)

poplog :
	$(POPLINK) $(POPLINK_FLAGS) $(POPLINK_POPLOG_FLAGS) -ident 0 -o $@.dll \
		-lf ( $(dlllflags) -base:0x800000 -def:$(POPEXTERNSRC)\poplog.def ) \
		-lo ( poplog.res $(LIBC) ) \
		$(POPOBJLIB)\winsrc.wlb -ex ( )	\
		$(POPOBJLIB)\vedsrc.wlb -ex ( ) \
		$(POPOBJLIB)\src.wlb -ex ( )

poplog.res : poplog.ico
	$(RC) -Fo$@ <<
PoplogIcon ICON "poplog.ico"
<<

# Static executables

corepop11 : newpop11.exe rsvpop11.exe
	copy newpop11.* corepop11.*
	copy rsvpop11.* corepop.*
	-del newpop11.* rsvpop11.*

rsvpop11 rsvpop11.exe : newpop11.exe
	newpop11 ":printf(sysdaytime(),'"'"%%S"'"\n')" > <<poplink_dat.txt
<<
	$(POPLINK) -q -date @poplink_dat.txt -ident 0 -o newpop11.exe
	$(POPLINK) -q -date @poplink_dat.txt -ident 1 -o rsvpop11.exe

newpop11 newpop11.exe :
	$(POPLINK) $(POPLINK_FLAGS) $(POPLINK_POPLOG_FLAGS) -ident 0 -o newpop11.exe \
		-noshare -lf ( $(conlflags) ) -lo ( $(LIBC) ) \
		$(POPOBJLIB)\src.wlb -ex ( )

# Clean up

clean :
	-del *-

# The lot

all : corepop11 syscomp poplog pop11 winpop11 images clean


# --- Revision History ---------------------------------------------------
# --- Robert Duncan, May 29 1996
#		Added case for compilation in the NuTCRACKER environment
#		(indicated by $POPNUTC set). Removed some unused rules.
# --- Robert Duncan, Mar 21 1996
#		Added support for Poplog icon and changed base image name to startup
# --- Robert John Duncan, Feb 12 1996
#		Added $(dlllflags) for linking poplog dll.
#		Import library poplog.lib now in this directory (generated as
#		side-effect of linking poplog.dll).
#		Warning message when linking pop11/winpop11 ("no object files
#		specified") changed to LNK4001.
#		POPLINK fixed to use w-libraries rather than w-files.
#		Added rules for "port" and "objlib".
# --- Robert John Duncan, Feb  7 1996
#		Changed link command for poplog DLL to use poplog.def directly
# --- Robert John Duncan, Jan  8 1996
#		Added externlib target and changed link commands to include -ident
# --- Robert John Duncan, Sep 13 1995
#		Changed POPLINK commands not to specify popmain.lib: now included
#		by default in poplink_cmnd
