root/trunk/m2/m2_linux.r

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