| 1 | REBOL [ |
|---|
| 2 | Title: "m2 Visual-C++ template" |
|---|
| 3 | ] |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | win32: func [blk] [do blk] |
|---|
| 7 | |
|---|
| 8 | console: does [ m2/ct/cfg_console: true ] |
|---|
| 9 | |
|---|
| 10 | conv_slash: func [ file ] [ replace/all file "/" "\" ] |
|---|
| 11 | |
|---|
| 12 | eol: "^/" |
|---|
| 13 | |
|---|
| 14 | dist_files: function [] [str obj] [ |
|---|
| 15 | str: make string! 64 |
|---|
| 16 | |
|---|
| 17 | obj: [] |
|---|
| 18 | foreach t m2/targets [ append obj t/objdir ] |
|---|
| 19 | obj: intersect obj obj ; Removes duplicates. |
|---|
| 20 | append str obj |
|---|
| 21 | |
|---|
| 22 | foreach t m2/targets [ append str t/dist ] |
|---|
| 23 | str |
|---|
| 24 | ] |
|---|
| 25 | |
|---|
| 26 | generate_makefile: does [ |
|---|
| 27 | ;foreach t m2/targets [ probe t ] ;KR |
|---|
| 28 | |
|---|
| 29 | emit do_tags copy nmake_header |
|---|
| 30 | |
|---|
| 31 | emit "^/#------ Target settings" |
|---|
| 32 | foreach t m2/targets [ emit "^/^/" t/macro_text ] |
|---|
| 33 | |
|---|
| 34 | emit [ {^/ARCHIVE = } m2/project_version {^/DIST_FILES = \^/} ] |
|---|
| 35 | if not empty? m2/distribution_files [ |
|---|
| 36 | emit expand_list_gnu/part m2/distribution_files |
|---|
| 37 | ] |
|---|
| 38 | emit expand_list_gnu m2/header_files_used |
|---|
| 39 | |
|---|
| 40 | emit "^/^/#------ Build rules^/^/all:" |
|---|
| 41 | foreach t m2/targets [ emit [ " " t/output_file ] ] |
|---|
| 42 | emit eol |
|---|
| 43 | |
|---|
| 44 | foreach t m2/targets [ emit " " t/rule_text ] |
|---|
| 45 | |
|---|
| 46 | emit [ "^/^/" do_tags copy nmake_other_rules ] |
|---|
| 47 | |
|---|
| 48 | foreach t m2/targets [ emit t/clean ] |
|---|
| 49 | |
|---|
| 50 | emit "^/^/#------ Compile rules^/^/" |
|---|
| 51 | foreach t m2/targets [ |
|---|
| 52 | emit t/make_obj_rule |
|---|
| 53 | if t/cfg/qt [ emit t/moc_rule ] |
|---|
| 54 | ] |
|---|
| 55 | |
|---|
| 56 | emit "^/#EOF^/" |
|---|
| 57 | ] |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | qt-includes: context [ |
|---|
| 61 | gui: does [ include_from {$(QTDIR)\include\QtGui} ] |
|---|
| 62 | network: does [ include_from {$(QTDIR)\include\QtNetwork} ] |
|---|
| 63 | opengl: does [ include_from {$(QTDIR)\include\QtOpenGL} ] |
|---|
| 64 | xml: does [ include_from {$(QTDIR)\include\QtXml} ] |
|---|
| 65 | svg: does [ include_from {$(QTDIR)\include\QtSvg} ] |
|---|
| 66 | sql: does [ include_from {$(QTDIR)\include\QtSql} ] |
|---|
| 67 | support: does [ include_from {$(QTDIR)\include\Qt3Support} |
|---|
| 68 | cxxflags {-DQT3_SUPPORT} ] |
|---|
| 69 | ] |
|---|
| 70 | |
|---|
| 71 | qt-libraries: context [ |
|---|
| 72 | core: { QtCore4} |
|---|
| 73 | gui: { QtGui4} |
|---|
| 74 | network: { QtNetwork4} |
|---|
| 75 | opengl: { QtOpenGL4} |
|---|
| 76 | xml: { QtXml4} |
|---|
| 77 | svg: { QtSvg4} |
|---|
| 78 | sql: { QtSql4} |
|---|
| 79 | support: { Qt3Support4} |
|---|
| 80 | main: { qtmain} |
|---|
| 81 | ] |
|---|
| 82 | |
|---|
| 83 | qt-debug-libraries: context [ |
|---|
| 84 | core: { QtCored4} |
|---|
| 85 | gui: { QtGuid4} |
|---|
| 86 | network: { QtNetworkd4} |
|---|
| 87 | opengl: { QtOpenGLd4} |
|---|
| 88 | xml: { QtXmld4} |
|---|
| 89 | xml: { QtXmld4} |
|---|
| 90 | svg: { QtSvgd4} |
|---|
| 91 | sql: { QtSqld4} |
|---|
| 92 | support: { Qt3Supportd4} |
|---|
| 93 | main: { qtmaind} |
|---|
| 94 | ] |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | exe_target: make m2/target_env |
|---|
| 98 | [ |
|---|
| 99 | obj_macro: none |
|---|
| 100 | cfg_console: false |
|---|
| 101 | |
|---|
| 102 | config: |
|---|
| 103 | [ |
|---|
| 104 | obj_macro: rejoin [ "$(" uc_name "_OBJECTS)" ] |
|---|
| 105 | |
|---|
| 106 | ; Most of libc gives warnings in VC8. |
|---|
| 107 | cflags {-D_CRT_SECURE_NO_WARNINGS} |
|---|
| 108 | |
|---|
| 109 | cflags {/nologo} |
|---|
| 110 | cxxflags {/EHsc} |
|---|
| 111 | lflags {/nologo /incremental:no} |
|---|
| 112 | |
|---|
| 113 | either cfg_console [ |
|---|
| 114 | lflags {/subsystem:console} |
|---|
| 115 | ][ |
|---|
| 116 | lflags {/subsystem:windows} |
|---|
| 117 | ] |
|---|
| 118 | |
|---|
| 119 | either cfg/warn [ |
|---|
| 120 | cflags {-W3} |
|---|
| 121 | ][ |
|---|
| 122 | cflags {-W0} |
|---|
| 123 | ] |
|---|
| 124 | |
|---|
| 125 | if cfg/debug [ |
|---|
| 126 | cflags {/MDd} |
|---|
| 127 | cflags {-Zi -DDEBUG} |
|---|
| 128 | lflags {/DEBUG} |
|---|
| 129 | ] |
|---|
| 130 | |
|---|
| 131 | if cfg/release [ |
|---|
| 132 | cflags {/MD} |
|---|
| 133 | cflags {-O1 -DNDEBUG} |
|---|
| 134 | ] |
|---|
| 135 | |
|---|
| 136 | if cfg/opengl [ |
|---|
| 137 | libs {opengl32 glu32} |
|---|
| 138 | ] |
|---|
| 139 | |
|---|
| 140 | if cfg/qt [ |
|---|
| 141 | either cfg/qt = 3 [ |
|---|
| 142 | include_from {$(QTDIR)\include} |
|---|
| 143 | ][ |
|---|
| 144 | include_from {$(QTDIR)\include} |
|---|
| 145 | include_from {$(QTDIR)\include\QtCore} |
|---|
| 146 | do bind cfg/qt in qt-includes 'gui |
|---|
| 147 | ] |
|---|
| 148 | if cfg/release [ |
|---|
| 149 | cxxflags {-DQT_NO_DEBUG} |
|---|
| 150 | ] |
|---|
| 151 | ] |
|---|
| 152 | |
|---|
| 153 | if cfg/x11 [ |
|---|
| 154 | include_from {/usr/X11R6/include} |
|---|
| 155 | libs_from %/usr/X11R6/lib {Xext X11 lm} |
|---|
| 156 | ] |
|---|
| 157 | ] |
|---|
| 158 | |
|---|
| 159 | configure: does [ |
|---|
| 160 | output_file: rejoin [ conv_slash output_dir name ".exe" ] |
|---|
| 161 | do config |
|---|
| 162 | ;libs {user32} ; gdi32 |
|---|
| 163 | if cfg/qt [ |
|---|
| 164 | either cfg/qt = 3 [ |
|---|
| 165 | ;libs_from {$(QTDIR)\lib} {qt} |
|---|
| 166 | ;libs_from {$(QTDIR)\lib} {qt-mt331 qtmain} |
|---|
| 167 | libs_from {$(QTDIR)\lib} {qt-mt qtmain} |
|---|
| 168 | |
|---|
| 169 | ; If Qt statically compiled must link with more libs. |
|---|
| 170 | libs {ole32 comdlg32 winspool advapi32 imm32 ws2_32 shell32} |
|---|
| 171 | ][ |
|---|
| 172 | append qt4-libs: copy cfg/qt [core main] |
|---|
| 173 | |
|---|
| 174 | libs_from %"$(QTDIR)/lib" |
|---|
| 175 | rejoin bind qt4-libs either cfg/debug |
|---|
| 176 | [in qt-debug-libraries 'gui] |
|---|
| 177 | [in qt-libraries 'gui] |
|---|
| 178 | |
|---|
| 179 | libs {comdlg32 winspool advapi32 shell32 ole32} |
|---|
| 180 | ] |
|---|
| 181 | ] |
|---|
| 182 | ] |
|---|
| 183 | |
|---|
| 184 | lib_string: func [ |
|---|
| 185 | items [block!] |
|---|
| 186 | /local str |
|---|
| 187 | ][ |
|---|
| 188 | str: make string! 64 |
|---|
| 189 | forall items [ |
|---|
| 190 | append str either (find items/1 " ") [ |
|---|
| 191 | rejoin [ { "} items/1 {.lib"} ] |
|---|
| 192 | ][ |
|---|
| 193 | rejoin [ { } items/1 {.lib} ] |
|---|
| 194 | ] |
|---|
| 195 | ] |
|---|
| 196 | remove str |
|---|
| 197 | ] |
|---|
| 198 | |
|---|
| 199 | macro_text: func [] |
|---|
| 200 | [ |
|---|
| 201 | emit [ |
|---|
| 202 | uc_name "_CFLAGS = " menv_cflags " " gnu_string "/D" defines eol |
|---|
| 203 | uc_name "_CXXFLAGS = $(" uc_name "_CFLAGS) " menv_cxxflags eol |
|---|
| 204 | uc_name "_INCPATH = " gnu_string "/I" include_paths eol |
|---|
| 205 | uc_name "_LFLAGS = " menv_lflags eol |
|---|
| 206 | uc_name "_LIBS = " gnu_string "/libpath:" link_paths " " |
|---|
| 207 | lib_string link_libs eol |
|---|
| 208 | ] |
|---|
| 209 | |
|---|
| 210 | emit [ |
|---|
| 211 | uc_name "_SOURCES = " expand_list_gnu source_files eol |
|---|
| 212 | uc_name "_OBJECTS = " expand_list_gnu object_files eol |
|---|
| 213 | ] |
|---|
| 214 | ] |
|---|
| 215 | |
|---|
| 216 | clean: does [ rejoin [ "^(tab)-@del " output_file " " obj_macro eol ] ] |
|---|
| 217 | |
|---|
| 218 | dist: func [] [ |
|---|
| 219 | rejoin [" $(" uc_name "_SOURCES) $(" uc_name "_HEADERS)" ] |
|---|
| 220 | ] |
|---|
| 221 | |
|---|
| 222 | rule_text: func [] |
|---|
| 223 | [ |
|---|
| 224 | emit [ eol output_file ": " obj_macro m2/local_libs link_libs |
|---|
| 225 | {^/^(tab)$(LINK) /out:$@ $(} uc_name {_LFLAGS) } obj_macro |
|---|
| 226 | { $(} uc_name {_LIBS)} eol |
|---|
| 227 | ] |
|---|
| 228 | ] |
|---|
| 229 | |
|---|
| 230 | rule_makeobj: func [cc flags obj src] [ |
|---|
| 231 | rejoin [ "^(tab)$(" cc ") /c $(" uc_name flags ") /Fo" obj |
|---|
| 232 | " $(" uc_name "_INCPATH) " src ] |
|---|
| 233 | ] |
|---|
| 234 | ] |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | lib_target: make exe_target [ |
|---|
| 238 | configure: does [ |
|---|
| 239 | output_file: rejoin [ conv_slash output_dir name ".lib" ] |
|---|
| 240 | do config |
|---|
| 241 | ] |
|---|
| 242 | |
|---|
| 243 | rule_text: function [] [] |
|---|
| 244 | [ |
|---|
| 245 | emit [ |
|---|
| 246 | eol output_file ": " obj_macro |
|---|
| 247 | "^/^(tab)lib /nologo /out:$@ " obj_macro " $(" uc_name |
|---|
| 248 | "_LIBS) $(" uc_name "_LFLAGS)^/" |
|---|
| 249 | ] |
|---|
| 250 | ] |
|---|
| 251 | ] |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | shlib_target: make exe_target [ |
|---|
| 255 | configure: does [ |
|---|
| 256 | output_file: rejoin [ conv_slash output_dir name ".dll" ] |
|---|
| 257 | do config |
|---|
| 258 | ;cflags {-MT} |
|---|
| 259 | lflags {/DLL} |
|---|
| 260 | ] |
|---|
| 261 | ] |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | nmake_header: |
|---|
| 265 | {#---------------------------------------------------------------------------- |
|---|
| 266 | # Makefile for NMAKE |
|---|
| 267 | # Generated by m2 at <now> |
|---|
| 268 | # Project: <m2/project_name> |
|---|
| 269 | #---------------------------------------------------------------------------- |
|---|
| 270 | |
|---|
| 271 | |
|---|
| 272 | #------ Compiler and tools |
|---|
| 273 | |
|---|
| 274 | CC = cl.exe |
|---|
| 275 | CXX = cl.exe |
|---|
| 276 | LINK = link.exe |
|---|
| 277 | TAR = tar.exe -cf |
|---|
| 278 | ZIP = zip.exe -r -9 |
|---|
| 279 | MOC = $(QTDIR)\bin\moc.exe |
|---|
| 280 | |
|---|
| 281 | } |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | nmake_other_rules: |
|---|
| 285 | {<m2/makefile>: <project_file> |
|---|
| 286 | ^(tab)m2 <project_file> |
|---|
| 287 | |
|---|
| 288 | .PHONY: dist |
|---|
| 289 | dist: |
|---|
| 290 | ^(tab)$(TAR) $(ARCHIVE).tar --exclude CVS --exclude .svn --exclude *.o <project_file> <dist_files> $(DIST_FILES) |
|---|
| 291 | ^(tab)mkdir /tmp/$(ARCHIVE) |
|---|
| 292 | ^(tab)tar -C /tmp/$(ARCHIVE) -xf $(ARCHIVE).tar |
|---|
| 293 | ^(tab)tar -C /tmp -cf $(ARCHIVE).tar $(ARCHIVE) |
|---|
| 294 | ^(tab)rm -rf /tmp/$(ARCHIVE) |
|---|
| 295 | ^(tab)$(ZIP) $(ARCHIVE).tar |
|---|
| 296 | |
|---|
| 297 | .PHONY: clean |
|---|
| 298 | clean: |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | ;EOF |
|---|