forked from zeromq/zproject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zproject.gsl
271 lines (244 loc) · 8.25 KB
/
zproject.gsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
.template 0
# zproject
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/imatix/gsl for details.
#
# Copyright (c) the Contributors as noted in the AUTHORS file.
# This file is part of zproject.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Resolve XML includes
function resolve_includes (xml)
for my.xml.include
if !defined (include.filename)
abort "E: required attribute 'filename' not defined"
endif
my.include_file = my.xml.load_file (filename)?
if defined (my.include_file)
move my.include_file after include
else
abort "E: <include> failed: $(xml.error?)"
endif
endfor
endfunction
resolve_includes (project)
# Check if project contains one or more C++ sources
function project_use_cxx ()
use_cxx = 0
for class
if file.exists ("src/$(name:c).cc")
project.source_ext = "cc"
return 1
endif
endfor
for main
if file.exists ("src/$(name:c).cc")
project.source_ext = "cc"
return 1
endif
endfor
return 0
endfunction
function resolve_classfilename_option()
for classfilename
if defined (classfilename.pretty\-print)
project.filename_prettyprint = classfilename.pretty\-print
endif
if defined (classfilename.source\-extension)
project.source_ext = classfilename.source\-extension
endif
if defined (classfilename.header\-extension)
project.header_ext = classfilename.header\-extension
endif
if defined (classfilename.use\-cxx)
if classfilename.use\-cxx ?= "true"
use_cxx = 1
elsif classfilename.use\-cxx ?= "false"
use_cxx = 0
endif
endif
if defined (classfilename.keep\-tree)
if classfilename.keep\-tree ?= "true"
project.keep_tree = 1
elsif classfilename.keep\-tree ?= "false"
project.keep_tree = 0
endif
endif
return
endfor
endfunction
project.filename_prettyprint = "c"
project.header_ext = "h"
project.source_ext = "c"
project.use_cxx = project_use_cxx ()
project.keep_tree = 0
resolve_classfilename_option()
project.name ?= "myproject"
project.prefix ?= "$(project.name:c)"
project.linkname ?= project.prefix
project.libname ?= "lib" + project.linkname
project.prelude ?= project.prefix + "_prelude.h"
project.description ?= "Project"
project.header ?= "$(project.name:$(project.filename_prettyprint)).$(project.header_ext)"
if count (project.version) = 0
new version to project
endnew
endif
project->version.major ?= 0
project->version.minor ?= 0
project->version.patch ?= 0
project.email ?= "email@hostname.com"
if count (project.license) = 0
new license to project
endnew
endif
project->license. ?= "Copyright (c) the Authors"
project.has_main = (count (main) > 0)
project.exports_classes = (count (class, !defined (class.private)) > 0)
project.generated_warning_header ?= "\
################################################################################
# THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY #
# Read the zproject/README.md for information about making permanent changes. #
################################################################################"
project.generated_warning_header_for_dot_bat ?= "\
@::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@:: THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY ::
@:: Read the zproject/README.md for information about making permanent changes. ::
@::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::"
project.generated_warning_header_for_lua ?= "\
--------------------------------------------------------------------------------
-- THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY -
-- Read the zproject/README.md for information about making permanent changes. -
--------------------------------------------------------------------------------"
function chmod_x (filename)
my.shell = proc.new ("chmod +x $(my.filename:)")
my.shell.run ()
endfunction
function register_snippet (target, name)
new snippet to project
snippet.target = my.target
snippet.name = my.name
endnew
endfunction
function insert_snippet (target)
for project.snippet where snippet.target = my.target
snippet_$(snippet.target:c)_$(snippet.name:c) ()
endfor
endfunction
function register_target (target, detail)
new handler to project
handler.target = my.target
handler.detail = my.detail
endnew
endfunction
function assume_target (target)
if count (project.target, name = my.target) = 0
new target to project
target.name = my.target
endnew
endif
endfunction
function build_target_in_scope (target, detail)
echo "Building $(my.detail:) ($(my.target))"
copy project to root as project_copy
scope root->project_copy as project
# Resolve target options if any
for project.target where name = my.target
for option
if defined (option.value)
project.$(my.target)_$(option.name:c) = option.value
else
for option.item
copy item to project as $(my.target)_$(option.name:c)
endfor
endif
endfor
endfor
target_$(my.target:c) ()
endscope
if switches.save ?= 1
root->project_copy.save ("save.xml")
endif
delete root->project_copy
endfunction
function build_target (target)
if my.target = "?"
echo "Valid targets are:"
for project.handler by target
echo " $(target)\
$(detail:)"
endfor
elsif my.target = "-" # No targets
echo "Building without targets"
elsif my.target = "*" # All targets
for project.handler by target
if count (project.target, name = handler.target) = 0
build_target_in_scope (handler.target, detail)
endif
endfor
else
for project.handler where handler.target = my.target
build_target_in_scope (handler.target, detail)
else
echo "$(my.target) is not a valid target; valid targets are:"
for project.handler by target
echo " $(target)\
$(detail:)"
endfor
endfor
endif
endfunction
# These scripts must be run first to resolve missing or
# implicit details in the model before code generation.
gsl from "zproject_projects.gsl"
gsl from "zproject_skeletons.gsl"
gsl from "zproject_class_api.gsl"
# Generate main class support
gsl from "zproject_class.gsl"
# Always run these, in any order
gsl from "zproject_bench.gsl"
gsl from "zproject_git.gsl"
gsl from "zproject_valgrind.gsl"
# Load all targets
gsl from "zproject_android.gsl"
gsl from "zproject_autotools.gsl"
gsl from "zproject_cmake.gsl"
gsl from "zproject_cygwin.gsl"
gsl from "zproject_debian.gsl"
gsl from "zproject_docker.gsl"
gsl from "zproject_gyp.gsl"
gsl from "zproject_java.gsl"
gsl from "zproject_java_msvc.gsl"
gsl from "zproject_jenkins.gsl"
gsl from "zproject_mingw32.gsl"
gsl from "zproject_nodejs.gsl"
gsl from "zproject_nuget.gsl"
gsl from "zproject_obs.gsl"
gsl from "zproject_python.gsl"
gsl from "zproject_python_cffi.gsl"
gsl from "zproject_lua_ffi.gsl"
gsl from "zproject_qml.gsl"
gsl from "zproject_qt.gsl"
gsl from "zproject_redhat.gsl"
gsl from "zproject_rpi.gsl"
gsl from "zproject_ruby.gsl"
gsl from "zproject_systemd.gsl"
gsl from "zproject_travis.gsl"
gsl from "zproject_vagrant.gsl"
gsl from "zproject_vs2008.gsl"
gsl from "zproject_vs20xx.gsl"
gsl from "zproject_vs20xx_props.gsl"
# Build targets requested by project
if defined (switches.target)
build_target (switches.target)
else
assume_target ("autotools")
assume_target ("cmake")
for project.target
build_target (target.name)
endfor
endif
.endtemplate