# --- Copyright University of Sussex 1996. All rights reserved. ----------
# File:				C.windows/obj/wlb.mak
# Purpose:			Makefile rules for w-libraries
# Author:			Robert Duncan, Mar 21 1996

# Check that target w-library and sources are specified
!IF !DEFINED(TARGET) || !DEFINED(SRCDIR)
!ERROR Target w-library not specified
!ENDIF

# If w-library directory not given, assume current directory
!IFNDEF WLBDIR
WLBDIR=$(MAKEDIR)
!ENDIF

# If configuration not given, assume update
!IFNDEF CFG
CFG=update
!ENDIF

# Include standard Poplog rules
!INCLUDE $(WLBDIR)\..\pop\poplog.mak

# Command for recursive MAKE
REMAKE=@$(MAKE) /$(MAKEFLAGS) /c /f $(WLBDIR)\wlb.mak WLBDIR=$(WLBDIR) CFG=$(CFG)

# Library to make
WLB=$(WLBDIR)\$(TARGET).wlb

# Temporary file
TMPFILE=$(WLBDIR)\$(TARGET).txt

# To make the TARGET, make all the w-files and then rebuild the library.
# Must be done in two separate MAKE commands because we can't determine
# dependencies for the w-library until all w-files have been made
$(TARGET) :
	cd $(SRCDIR)
	$(REMAKE) wfiles
	$(REMAKE) $(WLB)
	cd $(MAKEDIR)

# Make the w-files
!IF EXIST("$(WLB)") && "$(CFG)" == "update"

# Use POPLIBR to determine which w-files need remaking
wfiles :
	$(POPLIBR) $(POPLIBR_FLAGS) -lcs $(WLB) > <<$(TMPFILE)
<<
	$(POPC) $(POPC_FLAGS) @$(TMPFILE)

!ELSE

# Remake any w-files which are out of date wrt. their sources
wfiles :: *.p
	@$(REMAKE) @<<
$(**:.p=.w)
<<

!IFDEF SFILES
# Extra w-files to be generated from s-files
wfiles :: $(SFILES)
	@$(REMAKE) @<<
$(**:.s=.w)
<<
!ENDIF

!ENDIF

# Rebuild the w-library using POPLIBR
!IF EXIST("$(WLB)")

# Update (-r)
$(WLB) : *.w
	$(POPLIBR) $(POPLIBR_FLAGS) -r $@ @<<
$?
<<

!ELSE

# Create (-c)
$(WLB) : *.w
	$(POPLIBR) $(POPLIBR_FLAGS) -c $@ *.w

!ENDIF
