-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAtdgen.mk
103 lines (90 loc) · 3.61 KB
/
Atdgen.mk
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
# Atdgen.mk: atdgen plugin for GNU Make http://www.gnu.org/software/make
#
# Author: Martin Jambon
# Copyright (c) 2011 MyLife
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
######################### About this version #########################
ATDGEN_MAKE_VERSION = 1.0
# First public release.
######################### Setup and usage #########################
# Requires: GNU Make ("make" or "gmake" command), atdgen >= 1.2.0
#
# Usage:
#
# For ATD files foo.atd and bar.atd, first place this in the Makefile:
#
# ATDGEN_SOURCES = foo.atd bar.atd
#
# Options can be specified via the ATDGEN_FLAGS variable.
# For standard JSON output, use -j-std:
#
# ATDGEN_FLAGS = -j-std
#
# Place this line after the definition of ATDGEN_SOURCES and ATDGEN_FLAGS:
#
# include Atdgen.mk
#
#
# Atdgen.mk creates rules for building the following files:
# - type definitions: foo_t.mli, foo_t.ml
# - biniou serialization/deserialization: foo_b.mli foo_b.ml
# - JSON serialization/deserialization: foo_j.mli, foo_j.ml
# [same with files bar*]
#
# Generated files are added to the variable ATDGEN_OUTFILES which
# is convenient for removing them. A "clean" target for an OCaml
# project might look like this:
#
# .PHONY: clean
# clean:
# rm -f *.o *.a *.cm* *~ *.annot $(ATDGEN_OUTFILES)
#
# The files in $(ATDGEN_OUTFILES) are automatically added to the TRASH
# variable, for convenience and compatibility with OCamlMakefile.
# http://www.ocaml.info/home/ocaml_sources.html#ocaml-make
############################### Implementation ###############################
# atdgen base command
ifndef ATDGEN
ATDGEN := atdgen
endif
# Output files (.mli, .ml) generated by atdgen
ATDGEN_OUTFILES := \
$(patsubst %.atd,%_t.mli,$(ATDGEN_SOURCES)) \
$(patsubst %.atd,%_b.mli,$(ATDGEN_SOURCES)) \
$(patsubst %.atd,%_j.mli,$(ATDGEN_SOURCES)) \
$(patsubst %.atd,%_v.mli,$(ATDGEN_SOURCES)) \
$(patsubst %.atd,%_t.ml,$(ATDGEN_SOURCES)) \
$(patsubst %.atd,%_b.ml,$(ATDGEN_SOURCES)) \
$(patsubst %.atd,%_j.ml,$(ATDGEN_SOURCES)) \
$(patsubst %.atd,%_v.ml,$(ATDGEN_SOURCES))
TRASH += $(ATDGEN_OUTFILES)
%_t.mli %_t.ml: %.atd
$(ATDGEN) -t $(ATDGEN_FLAGS) $<
%_b.mli %_b.ml: %.atd
$(ATDGEN) -b $(ATDGEN_FLAGS) $<
%_j.mli %_j.ml: %.atd
$(ATDGEN) -j $(ATDGEN_FLAGS) $<
%_v.mli %_v.ml: %.atd
$(ATDGEN) -v $(ATDGEN_FLAGS) $<