1/* 2 * NAME 3 * c++ - the C++ compiler cookbook 4 * 5 * DESCRIPTION 6 * This cookbook describes how to work with C++ files. 7 * Include file dependencies are automatically determined. 8 * 9 * RECIPES 10 * %.o: %.cpp make object files form C++ source files 11 * %.o: %.cc make object files form C++ source files 12 * %.o: %.c++ make object files form C++ source files 13 * 14 * VARIABLES 15 * c_incl The C++ include dependency sniffer command. 16 * Not altered if already defined. 17 * c++ The C++ compiler command 18 * Not altered if already defined. 19 * c++_flags options to pass to the C++ compiler command 20 * Not altered if already defined. 21 * The default is "-O". 22 * c++_include_flags Options passed to the C++ compiler and c_incl 23 * controlling include file searching. 24 * Not altered if already defined. 25 * The default is empty. 26 * c++_src C++ source files in the current directory. 27 * dot_src Source files constructable in the current directory 28 * (unioned with existing setting, if necessary). 29 * dot_obj Object files constructable in the current directory 30 * (unioned with existing setting, if necessary). 31 * dot_clean Files which may be removed from the current directory 32 * in a clean target. 33 * 34 * SEE ALSO 35 * program The program cookbook: 36 * ld The linker program 37 * ld_flags The linker flags, NOT libraries 38 * ld_libraries The linker flags (-L, -l) for libraries 39 * Copyright (C) 2002, 2007 Peter Miller 40 */ 41 42#pragma once 43 44if [not [defined c_incl]] then 45 c_incl = [find_command c_incl]; 46if [not [defined c++]] then 47 c++ = g++; 48if [not [defined c++_flags]] then 49 c++_flags = -O; 50if [not [defined c++_include_flags]] then 51 c++_include_flags = ; 52if [not [defined c++_link_flags]] then 53 c++_link_flags = ; 54c++_src = [glob "*.cpp" "*.cc" "*.c++" ]; 55if [not [defined dot_src]] then 56 dot_src = ; 57dot_src = 58 [stringset 59 [dot_src] [c++_src] 60 - 61 [fromto %.cpp %.s 62 [fromto %.c++ %.s 63 [fromto %.cc %.s 64 [c++_src] 65 ]]] 66 ]; 67if [not [defined dot_obj]] then 68 dot_obj = ; 69dot_obj = 70 [stringset 71 [dot_obj] 72 73 [fromto %.cpp %.o 74 [fromto %.c++ %.o 75 [fromto %.cc %.o 76 [c++_src] 77 ]]] 78 ]; 79if [not [defined dot_clean]] then 80 dot_clean = ; 81dot_clean = 82 [stringset 83 [dot_clean] 84 [fromto %.cpp %.o 85 [fromto %.cc %.o 86 [fromto %.c++ %.o 87 [c++_src] 88 ]]] 89 [fromto %.cpp %.s 90 [fromto %.cc %.s 91 [fromto %.c++ %.s 92 [c++_src] 93 ]]] 94 ]; 95 96%.o: %.cpp 97{ 98 [c++] [c++_include_flags] [c++_flags] 99 [addprefix "-I" [search_list]] 100 -o [target] 101 -c [resolve %.cpp]; 102} 103 104%.o: %.cc 105{ 106 [c++] [c++_include_flags] [c++_flags] 107 [addprefix "-I" [search_list]] 108 -o [target] 109 -c [resolve %.cc]; 110} 111 112%.o: %.c++ 113{ 114 [c++] [c++_include_flags] [c++_flags] 115 [addprefix "-I" [search_list]] 116 -o [target] 117 -c [resolve %.c++]; 118} 119 120/* 121 * if the c_incl command is available, then check dependencies 122 */ 123#if [c_incl] 124 %.cpp.d: %.cpp 125 { 126 [c_incl] -nc -ns -nrec 127 [c++_include_flags] 128 [resolve %.cpp] 129 [addprefix "-I" [search_list]] 130 -prefix "'cascade %.cpp ='" 131 -suffix "';'" 132 [addprefix "-rlp=" [split ":" [search_list]]] 133 -o [target]; 134 } 135 %.cc.d: %.cc 136 { 137 [c_incl] -nc -ns -nrec 138 [c++_include_flags] 139 [resolve %.cc] 140 [addprefix "-I" [search_list]] 141 -prefix "'cascade %.cc ='" 142 -suffix "';'" 143 [addprefix "-rlp=" [split ":" [search_list]]] 144 -o [target]; 145 } 146 %.c++.d: %.c++ 147 { 148 [c_incl] -nc -ns -nrec 149 [c++_include_flags] 150 [resolve %.c++] 151 [addprefix "-I" [search_list]] 152 -prefix "'cascade %.c++ ='" 153 -suffix "';'" 154 [addprefix "-rlp=" [split ":" [search_list]]] 155 -o [target]; 156 } 157 %.h.d: %.h 158 { 159 [c_incl] -nc -ns -nrec 160 [c++_include_flags] 161 [resolve %.h] 162 [addprefix "-I" [search_list]] 163 -prefix "'cascade %.h ='" 164 -suffix "';'" 165 [addprefix "-rlp=" [split ":" [search_list]]] 166 -o [target]; 167 } 168 169 c++_dep_files = [addsuffix ".d" [c++_src] [glob "*.h"]]; 170 dot_clean = 171 [stringset 172 [dot_clean] 173 [c++_dep_files] 174 ]; 175 176 #include-cooked-nowarn [c++_dep_files] 177#endif 178