-- $Source$
-- $State$
--
-- $Id$
--
-- This is the build file used to compile LLgen. It should be run through
-- Prime Mover (copy supplied). See the READ_ME file for more information.

include "c.pm"

-- Where is LLgen going to be installed eventually? (Needs trailing slash.)

PREFIX = PREFIX or "/usr/local/"

-- Where's LLgen's staging area? (Don't change. Needs trailing slash.)

INSTALLPATH = "bin/"

LLgen = cprogram {
	CEXTRAFLAGS = '-DLIBDIR=\\"'..PREFIX..'share/LLgen\\" -DNON_CORRECTING',
	
	-- This line is needed to work around an OSX bug --- Apple's hacked gcc's
	-- preprocessor doesn't find LLgen.c's include files properly. Don't know
	-- why.
	
	CINCLUDES = {PARENT, "-Isrc"},

	cfile "src/main.c",
	cfile "src/gencode.c",
	cfile "src/compute.c",
	cfile "src/check.c",
	cfile "src/reach.c",
	cfile "src/global.c",
	cfile "src/name.c",
	cfile "src/sets.c",
	cfile "src/alloc.c",
	cfile "src/machdep.c",
	cfile "src/cclass.c",
	cfile "src/savegram.c",

	-- These use pre-LLgen'd version of the files. If LLgen.g gets updated,
	-- they need rebuilding. Use the bootstrap script to do this.
	
	cfile "src/LLgen.c",
	cfile "src/Lpars.c",
	cfile "src/tokens.c",

	outputs = {"%U%/LLgen"},
	install = pm.install(              INSTALLPATH.."bin/LLgen")
}

library = group {
	install = {
		pm.install("lib/rec",          INSTALLPATH.."share/LLgen/rec"),
		pm.install("lib/incl",         INSTALLPATH.."share/LLgen/incl"),
		pm.install("lib/nc_incl",      INSTALLPATH.."share/LLgen/nc_incl"),
		pm.install("lib/nc_rec",       INSTALLPATH.."share/LLgen/nc_rec"),
	}
}

manpage = group {
	install = {
		pm.install("doc/LLgen.1", INSTALLPATH.."man/man1/LLgen.1"),
	}
}

documentation = group {
	simple {
		outputs = {"%U%-%I%.ps.gz"},
		command = "refer -sA+T -p %in[1]% %in[2]% | groff -Tps -e -t -ms "..
			"| gzip -c9 > %out[1]%",
		
		file "doc/LLgen.refs",
		file "doc/LLgen.n",
		
		install = {
			pm.install(INSTALLPATH.."share/doc/LLgen/LLgen.ps.gz")
		}
	},
	
	simple {
		outputs = {"%U%-%I%.ps.gz"},
		command = "groff -Tps -e -t -p -ms %in% | gzip -c9 > %out[1]%",
		
		file "doc/LLgen_NCER.n",
		
		install = {
			pm.install(INSTALLPATH.."share/doc/LLgen/NCER.ps.gz")
		}
	},
}

-- Default rule: builds everything into the staging area, but does nothing
-- else.

default = group {
	LLgen,         -- build LLgen itself
	library,       -- copy over the library
	manpage,       -- copy over the man page
	documentation, -- build the two white papers
}

-- This rule will build everything, and then install it to its final location.

install = group {
	default,
	
	install = {
		"mkdir -p %PREFIX%",
		"(cd bin && tar chvf - $(find . ! -type d)) | (cd %PREFIX% && tar xUf -)"
	}
}

-- Revision history
-- $Log$
-- Revision 1.5  2006-07-25 23:29:12  dtrg
-- Modified to not try to unlink directories when installing.
--
-- Revision 1.4  2006/07/25 23:22:58  dtrg
-- Updated to the latest version of pm which installs files with symlinks.
--
-- Revision 1.3  2006/07/23 20:33:26  dtrg
-- Added a workaround for an OSX compiler bug.
--
-- Revision 1.2  2006/07/21 11:15:14  dtrg
-- Updated to the latest version of pm.
--
