1/* 2 * NAME 3 * program - construct a program 4 * 5 * DESCRIPTION 6 * This cookbook defines how to construct a program. 7 * 8 * If you program uses any libraries, you will have to append 9 * them to cc_link_flags in your Howto.cook file. 10 * 11 * VARIABLES 12 * all targets of the all recipe 13 * install targets of the install recipe 14 * me the name of the program to be constructed. 15 * Defaults to the last component of the pathname 16 * of the current directory. 17 * install targets of the install command. 18 * ld The name of the linker program 19 * ld_flags Command line arguments for the linker 20 * ld_libraries Library command line arguments for the linker 21 * 22 * RECIPES 23 * all: construct the targets defined in [all]. 24 * clean: remove the files named in [dot_clean]. 25 * clobber: remove the files name in [dot_clean] and [all]. 26 * 27 * If the [lib] variable is defined 28 * install: construct the files named in [install]. 29 * uninstall: remove the files named in [install]. 30 * Copyright (C) 1997-2007 Peter Miller 31 */ 32 33#pragma once 34 35if [not [defined me]] then 36 me = [entryname [dir [pathname x]]]; 37 38all = [me]; 39if [find_command lint] then 40if [defined dot_lint_obj] then 41 all = [all] [me].lint; 42dot_clean = [dot_clean] [me]~; 43 44if [not [defined ld]] then 45{ 46 if [defined c++] then 47 ld = [c++]; 48 else if [defined cc] then 49 ld = [cc]; 50 else if [defined f77] then 51 ld = [f77]; 52 else 53 ld = ld; 54} 55 56all: [all] 57 set default; 58 59run: all 60{ 61 [me] 62 set errok silent; 63} 64 65clean: 66{ 67 rm -f [dot_clean] 68 set clearstat; 69} 70 71clobber: clean 72{ 73 rm -f [all] 74 set clearstat; 75} 76 77if [defined bin] then 78{ 79 install = [bin]/[me]; 80 81 install: [install]; 82 83 uninstall: 84 { 85 rm -f [install] 86 set clearstat; 87 } 88 89 [bin]/%: % 90 { 91 cp % [bin]/%; 92 chmod og-w [bin]/%; 93 } 94 95 [lib]/%: % 96 { 97 cp % [lib]/%; 98 chmod og-w [lib]/%; 99 } 100} 101 102find_libs = [find_command find_libs]; 103 104function ld_flags_careful = 105{ 106 local result = ; 107 if [defined ld_flags] then 108 result += [ld_flags]; 109 if [defined cc_link_flags] then 110 result += [cc_link_flags]; 111 if [defined c++_link_flags] then 112 result += [c++_link_flags]; 113 if [defined f77_link_flags] then 114 result += [f77_link_flags]; 115 return [result]; 116} 117 118/* 119 * The cc_link_flags are an historical accident. They can't be removed 120 * without breaking existing installed sites. Sigh. 121 */ 122 123if [find_libs] then 124{ 125 if [not [defined ld_libraries]] then 126 ld_libraries = ; 127 [me]: [dot_obj] [collect [find_libs] [match_mask -L%0% 128 [ld_flags_careful] [ld_libraries]]] 129 { 130 if [not [defined ld_flags]] then 131 ld_flags = ; 132 if [exists [me]~] then 133 rm -f [me]~ 134 set clearstat; 135 if [exists [me]] then 136 mv [me] [me]~ 137 set clearstat; 138 [ld] [ld_flags_careful] [dot_obj] [ld_libraries] 139 -o [me]; 140 } 141} 142else 143{ 144 [me]: [dot_obj] 145 { 146 if [not [defined ld_flags]] then 147 ld_flags = ; 148 if [exists [me]~] then 149 rm -f [me]~ 150 set clearstat; 151 if [exists [me]] then 152 mv [me] [me]~ 153 set clearstat; 154 [ld] [ld_flags_careful] [dot_obj] [ld_libraries] 155 -o [me]; 156 } 157} 158 159if [find_command lint] then 160if [defined dot_lint_obj] then 161{ 162 [me].lint: [dot_lint_obj] 163 { 164 [lint] [dot_lint_obj] [ld_libraries] [cc_link_flags]; 165 } 166} 167