root/trunk/m2/m2_cygwin.r

Revision 227, 7.4 kB (checked in by krobillard, 2 years ago)

M2 - Added target_env/uc_name. A 'lib target on Linux & Windows can now bring in other libraries.

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