| 1 | REBOL [ |
|---|
| 2 | Title: "m2 Mac OS X template" |
|---|
| 3 | ] |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | macx: func [blk] [do blk] |
|---|
| 7 | |
|---|
| 8 | bundle: does [m2/ct/cfg_bundle: true] |
|---|
| 9 | universal: does [m2/ct/cfg_universal: true] |
|---|
| 10 | |
|---|
| 11 | eol: "^/" |
|---|
| 12 | |
|---|
| 13 | dist_files: function [] [str obj] [ |
|---|
| 14 | str: make string! 64 |
|---|
| 15 | |
|---|
| 16 | obj: [] |
|---|
| 17 | foreach t m2/targets [ append obj t/objdir ] |
|---|
| 18 | obj: intersect obj obj ; Removes duplicates. |
|---|
| 19 | append str obj |
|---|
| 20 | |
|---|
| 21 | foreach t m2/targets [ append str t/dist ] |
|---|
| 22 | str |
|---|
| 23 | ] |
|---|
| 24 | |
|---|
| 25 | generate_makefile: does [ |
|---|
| 26 | foreach t m2/targets [ |
|---|
| 27 | ;probe t |
|---|
| 28 | |
|---|
| 29 | ; make_obj_rule must be called before we write DIST_FILES since |
|---|
| 30 | ; it finds the header dependencies. |
|---|
| 31 | t/built_obj_rule: t/make_obj_rule |
|---|
| 32 | |
|---|
| 33 | if t/cfg/qt <> 3 [ |
|---|
| 34 | moc_exe: {moc} ; /usr/bin/moc-4.0 |
|---|
| 35 | ] |
|---|
| 36 | ] |
|---|
| 37 | |
|---|
| 38 | emit do_tags copy gnu_header |
|---|
| 39 | |
|---|
| 40 | emit "^/#------ Target settings" |
|---|
| 41 | foreach t m2/targets [ emit "^/^/" t/macro_text ] |
|---|
| 42 | |
|---|
| 43 | emit [ {^/ARCHIVE = } m2/project_version {^/DIST_FILES = \^/} ] |
|---|
| 44 | if not empty? m2/distribution_files [ |
|---|
| 45 | emit expand_list_gnu/part m2/distribution_files |
|---|
| 46 | ] |
|---|
| 47 | emit expand_list_gnu m2/header_files_used |
|---|
| 48 | |
|---|
| 49 | emit "^/^/#------ Build rules^/^/all:" |
|---|
| 50 | foreach t m2/targets [ emit [ " " t/output_file ] ] |
|---|
| 51 | emit eol |
|---|
| 52 | |
|---|
| 53 | foreach t m2/targets [ emit " " t/rule_text ] |
|---|
| 54 | |
|---|
| 55 | emit [ "^/^/" do_tags copy gnu_other_rules ] |
|---|
| 56 | |
|---|
| 57 | foreach t m2/targets [ emit t/clean ] |
|---|
| 58 | |
|---|
| 59 | emit "^/^/#------ Compile rules^/^/" |
|---|
| 60 | foreach t m2/targets [ |
|---|
| 61 | emit t/built_obj_rule |
|---|
| 62 | if t/cfg/qt [ |
|---|
| 63 | emit t/moc_rule |
|---|
| 64 | ] |
|---|
| 65 | ] |
|---|
| 66 | |
|---|
| 67 | emit "^/#EOF^/" |
|---|
| 68 | ] |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | qt-libs: context [ |
|---|
| 72 | gui: does [include_from {/Library/Frameworks/QtGui.framework/Headers} |
|---|
| 73 | lflags {-framework QtGui}] |
|---|
| 74 | network: does [include_from {/Library/Frameworks/QtNetwork.framework/Headers} |
|---|
| 75 | lflags {-framework QtNetwork}] |
|---|
| 76 | opengl: does [include_from {/Library/Frameworks/QtOpenGL.framework/Headers} |
|---|
| 77 | lflags {-framework QtOpenGL}] |
|---|
| 78 | xml: does [include_from {/Library/Frameworks/QtXml.framework/Headers} |
|---|
| 79 | lflags {-framework QtXml}] |
|---|
| 80 | svg: does [include_from {/Library/Frameworks/QtSvg.framework/Headers} |
|---|
| 81 | lflags {-framework QtSvg}] |
|---|
| 82 | sql: does [include_from {/Library/Frameworks/QtSql.framework/Headers} |
|---|
| 83 | lflags {-framework QtSql}] |
|---|
| 84 | support: does [ |
|---|
| 85 | include_from {/Library/Frameworks/Qt3Support.framework/Headers} |
|---|
| 86 | cxxflags {-DQT3_SUPPORT} |
|---|
| 87 | lflags {-framework Qt3Support } |
|---|
| 88 | ] |
|---|
| 89 | ] |
|---|
| 90 | |
|---|
| 91 | qt-static-libs: context [ |
|---|
| 92 | qlib: func [name] [ |
|---|
| 93 | include_from join {$(QTDIR)/include/} name |
|---|
| 94 | lflags join {-l} name |
|---|
| 95 | ] |
|---|
| 96 | gui: does [qlib {QtGui}] |
|---|
| 97 | network: does [qlib {QtNetwork}] |
|---|
| 98 | opengl: does [qlib {QtOpenGL}] |
|---|
| 99 | xml: does [qlib {QtXml}] |
|---|
| 100 | svg: does [qlib {QtSvg}] |
|---|
| 101 | sql: does [qlib {QtSql}] |
|---|
| 102 | support: does [qlib {Qt3Support} cxxflags {-DQT3_SUPPORT}] |
|---|
| 103 | ] |
|---|
| 104 | |
|---|
| 105 | exe_target: make m2/target_env |
|---|
| 106 | [ |
|---|
| 107 | ; built_obj_rule exists only to hold the output make_obj_rule |
|---|
| 108 | built_obj_rule: none |
|---|
| 109 | |
|---|
| 110 | cfg_bundle: none |
|---|
| 111 | cfg_universal: none |
|---|
| 112 | |
|---|
| 113 | obj_macro: none |
|---|
| 114 | |
|---|
| 115 | config: |
|---|
| 116 | [ |
|---|
| 117 | obj_macro: rejoin [ "$(" uc_name "_OBJECTS)" ] |
|---|
| 118 | |
|---|
| 119 | cflags {-pipe} |
|---|
| 120 | |
|---|
| 121 | if cfg/warn [ |
|---|
| 122 | cflags {-Wall -W} |
|---|
| 123 | ] |
|---|
| 124 | |
|---|
| 125 | if cfg/debug [ |
|---|
| 126 | cflags {-g -DDEBUG} |
|---|
| 127 | ] |
|---|
| 128 | |
|---|
| 129 | if cfg/release [ |
|---|
| 130 | cflags {-O3 -DNDEBUG} |
|---|
| 131 | ] |
|---|
| 132 | |
|---|
| 133 | if cfg_universal [ |
|---|
| 134 | cflags {-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -mmacosx-version-min=10.4} |
|---|
| 135 | lflags {-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -arch i386 -mmacosx-version-min=10.4} |
|---|
| 136 | ] |
|---|
| 137 | |
|---|
| 138 | if cfg/opengl [ |
|---|
| 139 | lflags {-framework OpenGL} |
|---|
| 140 | ;libs {GL GLU} |
|---|
| 141 | ] |
|---|
| 142 | |
|---|
| 143 | if cfg/qt [ |
|---|
| 144 | either cfg/qt = 3 [ |
|---|
| 145 | include_from {$(QTDIR)/include} |
|---|
| 146 | ][ |
|---|
| 147 | either cfg/qt-static [ |
|---|
| 148 | include_from {$(QTDIR)/include} |
|---|
| 149 | include_from {$(QTDIR)/include/QtCore} |
|---|
| 150 | lflags {-L$(QTDIR)/lib -lQtCore} |
|---|
| 151 | lflags {-framework Carbon -lz -liconv} |
|---|
| 152 | do bind cfg/qt in qt-static-libs 'gui |
|---|
| 153 | ][ |
|---|
| 154 | include_from {/Library/Frameworks/QtCore.framework/Headers} |
|---|
| 155 | cflags {-F/Library/Frameworks} |
|---|
| 156 | lflags {-F/Library/Frameworks -framework QtCore} |
|---|
| 157 | lflags {-framework Carbon} |
|---|
| 158 | do bind cfg/qt in qt-libs 'gui |
|---|
| 159 | ] |
|---|
| 160 | ] |
|---|
| 161 | if cfg/release [ |
|---|
| 162 | cxxflags {-DQT_NO_DEBUG} |
|---|
| 163 | ] |
|---|
| 164 | ] |
|---|
| 165 | |
|---|
| 166 | if cfg/x11 [ |
|---|
| 167 | include_from {/usr/X11R6/include} |
|---|
| 168 | libs_from %/usr/X11R6/lib {Xext X11 m} |
|---|
| 169 | ] |
|---|
| 170 | ] |
|---|
| 171 | |
|---|
| 172 | configure: does [ |
|---|
| 173 | output_file: rejoin either cfg_bundle |
|---|
| 174 | [[name %.app/Contents/MacOs/ name]] |
|---|
| 175 | [[output_dir name]] |
|---|
| 176 | do config |
|---|
| 177 | if cfg/qt [ |
|---|
| 178 | if cfg/qt = 3 [ |
|---|
| 179 | libs_from %"$(QTDIR)/lib" {qt} |
|---|
| 180 | ; If Qt is compiled as a static library. |
|---|
| 181 | lflags {-framework Carbon -lz} |
|---|
| 182 | ] |
|---|
| 183 | ] |
|---|
| 184 | ] |
|---|
| 185 | |
|---|
| 186 | macro_text: func [] |
|---|
| 187 | [ |
|---|
| 188 | emit [ |
|---|
| 189 | uc_name "_CFLAGS = " menv_cflags " " gnu_string "-D" defines eol |
|---|
| 190 | uc_name "_CXXFLAGS = $(" uc_name "_CFLAGS) " menv_cxxflags eol |
|---|
| 191 | uc_name "_INCPATH = " gnu_string "-I" include_paths eol |
|---|
| 192 | uc_name "_LFLAGS = " menv_lflags eol |
|---|
| 193 | uc_name "_LIBS = " gnu_string "-L" link_paths " " |
|---|
| 194 | gnu_string "-l" link_libs eol |
|---|
| 195 | ] |
|---|
| 196 | |
|---|
| 197 | ;if cfg/qt [ |
|---|
| 198 | ; emit [ |
|---|
| 199 | ; uc_name "_SRCMOC = " expand_list_gnu srcmoc_files eol |
|---|
| 200 | ; uc_name "_OBJMOC = " expand_list_gnu objmoc_files eol |
|---|
| 201 | ; ] |
|---|
| 202 | ;] |
|---|
| 203 | |
|---|
| 204 | emit [ |
|---|
| 205 | ;uc_name "_HEADERS = " expand_list_gnu header_files eol |
|---|
| 206 | uc_name "_SOURCES = " expand_list_gnu source_files eol |
|---|
| 207 | uc_name "_OBJECTS = " expand_list_gnu object_files eol |
|---|
| 208 | ] |
|---|
| 209 | ] |
|---|
| 210 | |
|---|
| 211 | clean: does [ rejoin [ "^(tab)-rm -f " output_file " " obj_macro eol ] ] |
|---|
| 212 | ; TODO: if cfg/qt [ "rm -f $(_SRCMOC)" ] |
|---|
| 213 | |
|---|
| 214 | dist: func [] [ |
|---|
| 215 | rejoin [" $(" uc_name "_SOURCES)" ] |
|---|
| 216 | ] |
|---|
| 217 | |
|---|
| 218 | rule_text: function [] [bdir] |
|---|
| 219 | [ |
|---|
| 220 | emit [ eol output_file ": " obj_macro m2/local_libs link_libs |
|---|
| 221 | {^/^(tab)$(} |
|---|
| 222 | either link_cxx ["LINK_CXX"]["LINK"] |
|---|
| 223 | {) -o $@ $(} uc_name {_LFLAGS) } obj_macro |
|---|
| 224 | { $(} uc_name {_LIBS)} eol |
|---|
| 225 | ] |
|---|
| 226 | |
|---|
| 227 | if cfg_bundle [ |
|---|
| 228 | bdir: to-file join name %.app/Contents/ |
|---|
| 229 | if not exists? bdir [ |
|---|
| 230 | make-dir/deep join bdir %MacOs |
|---|
| 231 | write join bdir %PkgInfo #{4150504c 3f3f3f3f 0a} |
|---|
| 232 | write join bdir %Info.plist rejoin bind info.plist 'name |
|---|
| 233 | |
|---|
| 234 | ;emit {^/# bundle} |
|---|
| 235 | ] |
|---|
| 236 | ] |
|---|
| 237 | ] |
|---|
| 238 | ] |
|---|
| 239 | |
|---|
| 240 | |
|---|
| 241 | lib_target: make exe_target [ |
|---|
| 242 | configure: does [ |
|---|
| 243 | output_file: rejoin [ output_dir "lib" name ".a" ] |
|---|
| 244 | do config |
|---|
| 245 | ] |
|---|
| 246 | |
|---|
| 247 | rule_text: func [] |
|---|
| 248 | [ |
|---|
| 249 | emit [ eol output_file ": " obj_macro |
|---|
| 250 | "^/^(tab)libtool -static -o $@ $^^ $(" uc_name "_LIBS)" |
|---|
| 251 | "^/^(tab)ranlib $@^/" |
|---|
| 252 | ] |
|---|
| 253 | ] |
|---|
| 254 | ] |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | shlib_target: make exe_target [ |
|---|
| 258 | configure: does [ |
|---|
| 259 | output_file: rejoin [ output_dir "lib" name ".dylib" ] |
|---|
| 260 | do config |
|---|
| 261 | cflags {-fPIC} |
|---|
| 262 | lflags {-dynamic} |
|---|
| 263 | ] |
|---|
| 264 | |
|---|
| 265 | rule_text: func [] |
|---|
| 266 | [ |
|---|
| 267 | emit [ eol output_file ": " obj_macro |
|---|
| 268 | {^/^(tab)libtool -o $@ } obj_macro { $(} uc_name {_LFLAGS) } |
|---|
| 269 | { $(} uc_name {_LIBS)} eol |
|---|
| 270 | ] |
|---|
| 271 | ] |
|---|
| 272 | ] |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | moc_exe: {$(QTDIR)/bin/moc} |
|---|
| 276 | |
|---|
| 277 | gnu_header: |
|---|
| 278 | {#---------------------------------------------------------------------------- |
|---|
| 279 | # Makefile for GNU make |
|---|
| 280 | # Generated by m2 at <now> |
|---|
| 281 | # Project: <m2/project_name> |
|---|
| 282 | #---------------------------------------------------------------------------- |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | #------ Compiler and tools |
|---|
| 286 | |
|---|
| 287 | CC = gcc |
|---|
| 288 | CXX = g++ |
|---|
| 289 | LINK = gcc |
|---|
| 290 | LINK_CXX = g++ |
|---|
| 291 | TAR = tar -cf |
|---|
| 292 | GZIP = gzip -9f |
|---|
| 293 | MOC = <moc_exe> |
|---|
| 294 | |
|---|
| 295 | } |
|---|
| 296 | ;#------ Project-wide settings |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | gnu_other_rules: |
|---|
| 300 | {<m2/makefile>: <project_file> |
|---|
| 301 | ^(tab)m2 <project_file> |
|---|
| 302 | |
|---|
| 303 | .PHONY: dist |
|---|
| 304 | dist: |
|---|
| 305 | ^(tab)$(TAR) $(ARCHIVE).tar --exclude CVS --exclude .svn --exclude *.o <project_file> <dist_files> $(DIST_FILES) |
|---|
| 306 | ^(tab)mkdir /tmp/$(ARCHIVE) |
|---|
| 307 | ^(tab)tar -C /tmp/$(ARCHIVE) -xf $(ARCHIVE).tar |
|---|
| 308 | ^(tab)tar -C /tmp -cf $(ARCHIVE).tar $(ARCHIVE) |
|---|
| 309 | ^(tab)rm -rf /tmp/$(ARCHIVE) |
|---|
| 310 | ^(tab)$(GZIP) $(ARCHIVE).tar |
|---|
| 311 | |
|---|
| 312 | .PHONY: clean |
|---|
| 313 | clean: |
|---|
| 314 | ^(tab)-rm -f core |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | info.plist: [ |
|---|
| 319 | {<?xml version="1.0" encoding="UTF-8"?> |
|---|
| 320 | <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD |
|---|
| 321 | PLIST 1.0//EN" |
|---|
| 322 | "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|---|
| 323 | <plist version="1.0"> |
|---|
| 324 | <dict> |
|---|
| 325 | <key>CFBundlePackageType</key> |
|---|
| 326 | <string>APPL</string> |
|---|
| 327 | <key>CFBundleExecutable</key> |
|---|
| 328 | <string>} name {</string> |
|---|
| 329 | <key>CFBundleIdentifier</key> |
|---|
| 330 | <string>com.mycompany.} name {</string> |
|---|
| 331 | <key>CFBundleDisplayName</key> |
|---|
| 332 | <string>} uc_name {</string> |
|---|
| 333 | <key>CFBundleName</key> |
|---|
| 334 | <string>} uc_name {</string> |
|---|
| 335 | <key>CFBundleIconFile</key> |
|---|
| 336 | <string>} name {</string> |
|---|
| 337 | <key>CFBundleSignature</key> |
|---|
| 338 | <string>????</string> |
|---|
| 339 | <key>CFBundleVersion</key> |
|---|
| 340 | <string>1</string> |
|---|
| 341 | <key>CFBundleShortVersionString</key> |
|---|
| 342 | <string>1.0</string> |
|---|
| 343 | </dict> |
|---|
| 344 | </plist> |
|---|
| 345 | } |
|---|
| 346 | ] |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | ;EOF |
|---|