Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
283 lines (254 sloc) 8.62 KB
.template 0
# zproject
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/zeromq/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
if defined (classfilename.pkgincludedir)
if classfilename.pkgincludedir ?= "true"
project.pkgincludedir = 1
elsif classfilename.pkgincludedir ?= "false"
project.pkgincludedir = 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
project.pkgincludedir = 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.has_bin = (count (bin) > 0)
project.has_classes = (count (class) > 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