/*
 * NAME
 *	program - construct a program
 *
 * DESCRIPTION
 *	This cookbook defines how to construct a program.
 *
 *	If you program uses any libraries, you will have to append
 *	them to cc_link_flags in your Howto.cook file.
 *
 * VARIABLES
 *	all		targets of the all recipe
 *	install		targets of the install recipe
 *	me		the name of the program to be constructed.
 *			Defaults to the last component of the pathname
 *			of the current directory.
 *	install		targets of the install command.
 *
 * RECIPES
 *	all:		construct the targets defined in [all].
 *	clean:		remove the files named in [dot_clean].
 *	clobber:	remove the files name in [dot_clean] and [all].
 *
 * If the [lib] variable is defined
 *	install:	construct the files named in [install].
 *	uninstall:	remove the files named in [install].
 *
 * MANIFEST: cookbook for constructing programs
 */

#pragma once

if [not [defined me]] then
    me = [entryname [dir [pathname x]]];

all = [me];
if [defined dot_lint_obj] then
    all = [all] [me].lint;
dot_clean = [dot_clean] [me]~;

all: [all];

clean:
    {
	rm -f [dot_clean]
	    set clearstat;
    }

clobber: clean
    {
	rm -f [all]
	    set clearstat;
    }

if [defined bin] then
{
    install = [bin]/[me];

    install: [install];

    uninstall:
        {
            rm -f [install]
		set clearstat;
        }

    [bin]/%: %
        {
            cp % [bin]/%;
            chmod og-w [bin]/%;
        }

    [lib]/%: %
        {
            cp % [lib]/%;
            chmod og-w [lib]/%;
        }
}

find_libs = [find_command find_libs];

if [find_libs] then
{
    [me]: [dot_obj] [collect [find_libs] [cc_link_flags]]
        {
	    if [exists [me]~] then
		rm -f [me]~
		    set clearstat;
	    if [exists [me]] then
		mv [me] [me]~
		    set clearstat;
    	    [cc] [dot_obj] [cc_link_flags] -o [me];
        }
}
else
{
    [me]: [dot_obj]
        {
	    if [exists [me]~] then
		rm -f [me]~
		    set clearstat;
	    if [exists [me]] then
		mv [me] [me]~
		    set clearstat;
    	    [cc] [dot_obj] [cc_link_flags] -o [me];
        }
}

if [defined dot_lint_obj] then
{
    [me].lint: [dot_lint_obj]
        {
	    [lint] [dot_lint_obj] [cc_link_flags];
        }
}
