This is an automated email from the git hooks/post-receive script. glondu pushed a commit to branch master in repository cppo.
commit 5b2862767f169a35dc295e5855099dfe68afe02b Author: Stephane Glondu <st...@glondu.net> Date: Sun Aug 17 14:42:47 2014 +0200 Imported Upstream version 0.9.4 --- META | 8 + Makefile | 91 ++++--- README | 374 ---------------------------- README.md | 449 ++++++++++++++++++++++++++++++++++ ocamlbuild_plugin/_tags | 1 + ocamlbuild_plugin/ocamlbuild_cppo.ml | 30 +++ ocamlbuild_plugin/ocamlbuild_cppo.mli | 2 + opam | 13 + 8 files changed, 548 insertions(+), 420 deletions(-) diff --git a/META b/META new file mode 100644 index 0000000..4b2fa06 --- /dev/null +++ b/META @@ -0,0 +1,8 @@ +description = "Cppo ocamlbuild plugin" +version = "dev" + +requires = "ocamlbuild" +archive(byte) = "ocamlbuild_cppo.cma" +archive(byte, plugin) = "ocamlbuild_cppo.cma" +archive(native) = "ocamlbuild_cppo.cmxa" +archive(native, plugin) = "ocamlbuild_cppo.cmxs" diff --git a/Makefile b/Makefile index 6aa477a..7f9177e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,10 @@ -VERSION = 0.9.3 +VERSION = 0.9.4 + +ifeq "$(shell ocamlc -config |grep os_type)" "os_type: Win32" +EXE=.exe +else +EXE= +endif ifndef OCAMLYACC OCAMLYACC = ocamlyacc @@ -16,9 +22,31 @@ ifndef BINDIR endif export BINDIR + + +BEST := opt +NATDYNLINK ?= $(shell if [ -f `ocamlc -where`/dynlink.cmxa ]; then \ + echo YES; \ + else \ + echo NO; \ + fi) + +OCAMLBUILD_IMPL := ocamlbuild_cppo.cma + +ifeq "${BEST}" "opt" +OCAMLBUILD_IMPL += ocamlbuild_cppo.cmxa ocamlbuild_cppo.a +ifeq "${NATDYNLINK}" "YES" +OCAMLBUILD_IMPL += ocamlbuild_cppo.cmxs +endif +endif + +OCAMLBUILD_INSTALL = ocamlbuild_plugin/_build/ocamlbuild_cppo.cmi \ + $(addprefix ocamlbuild_plugin/_build/,$(OCAMLBUILD_IMPL)) + + .PHONY: default all opt install clean test -default: opt +default: opt ocamlbuild ML = cppo_version.ml cppo_types.ml \ cppo_parser.mli cppo_parser.ml \ @@ -26,16 +54,27 @@ ML = cppo_version.ml cppo_types.ml \ cppo_command.ml \ cppo_eval.ml cppo_main.ml +OCAMLBUILD_ML = ocamlbuild_cppo.ml + all: $(ML) - ocamlc -o cppo -dtypes unix.cma $(ML) + ocamlc -o cppo$(EXE) -dtypes unix.cma $(ML) opt: $(ML) - ocamlopt -o cppo -dtypes unix.cmxa $(ML) + ocamlopt -o cppo$(EXE) -dtypes unix.cmxa $(ML) -install: +ocamlbuild: + cd ocamlbuild_plugin && ocamlbuild -use-ocamlfind $(OCAMLBUILD_IMPL) + +install: install-bin install-lib + +install-bin: install -m 0755 cppo $(BINDIR) || \ install -m 0755 cppo.exe $(BINDIR) +install-lib: + ocamlfind install -patch-version ${VERSION} "cppo_ocamlbuild" \ + META $(OCAMLBUILD_INSTALL) + cppo_version.ml: Makefile echo 'let cppo_version = "$(VERSION)"' > cppo_version.ml @@ -60,44 +99,4 @@ clean: cppo \ cppo_parser.mli cppo_parser.ml cppo_lexer.ml cppo_version.ml cd examples; $(MAKE) clean - -SUBDIRS = testdata examples -SVNURL = svn+ssh://mjam...@svn.forge.ocamlcore.org/svnroot/cppo/trunk/cppo - -archive: - @echo "Making archive for version $(VERSION)" - @if [ -z "$$WWW" ]; then \ - echo '*** Environment variable WWW is undefined ***' >&2; \ - exit 1; \ - fi - @if [ -n "$$(svn status -q)" ]; then \ - echo "*** There are uncommitted changes, aborting. ***" >&2; \ - exit 1; \ - fi - $(MAKE) && ./cppo -help > $$WWW/cppo-help.txt - rm -rf /tmp/cppo /tmp/cppo-$(VERSION) && \ - cd /tmp && \ - svn co "$(SVNURL)" && \ - for x in "." $(SUBDIRS); do \ - rm -rf /tmp/cppo/$$x/.svn; \ - done && \ - cd /tmp && cp -r cppo cppo-$(VERSION) && \ - tar czf cppo.tar.gz cppo && \ - tar cjf cppo.tar.bz2 cppo && \ - tar czf cppo-$(VERSION).tar.gz cppo-$(VERSION) && \ - tar cjf cppo-$(VERSION).tar.bz2 cppo-$(VERSION) - mv /tmp/cppo.tar.gz /tmp/cppo.tar.bz2 ../releases - mv /tmp/cppo-$(VERSION).tar.gz /tmp/cppo-$(VERSION).tar.bz2 ../releases - cp ../releases/cppo.tar.gz $$WWW/ - cp ../releases/cppo.tar.bz2 $$WWW/ - cp ../releases/cppo-$(VERSION).tar.gz $$WWW/ - cp ../releases/cppo-$(VERSION).tar.bz2 $$WWW/ - cd ../releases && \ - svn add cppo.tar.gz cppo.tar.bz2 \ - cppo-$(VERSION).tar.gz cppo-$(VERSION).tar.bz2 && \ - svn commit -m "cppo version $(VERSION)" - cp README $$WWW/cppo-manual-$(VERSION).txt - cp LICENSE $$WWW/cppo-license.txt - cp Changes $$WWW/cppo-changes.txt - echo 'let cppo_version = "$(VERSION)"' \ - > $$WWW/cppo-version.ml + cd ocamlbuild_plugin; ocamlbuild -clean diff --git a/README b/README deleted file mode 100644 index 0b31e9f..0000000 --- a/README +++ /dev/null @@ -1,374 +0,0 @@ - +=======================+ - | cppo: cpp for OCaml | - +=======================+ - -Introduction -============ - -Cppo is an equivalent of the C preprocessor for OCaml programs. -It allows the definition of simple macros and file inclusion. - -Cppo is: - -- OCaml-friendly (unlike cpp) -- easy to learn without consulting a manual (unlike m4 or camlp4) -- reasonably fast (unlike camlmix) -- simple to install and to maintain (unlike camlp4-based tools) - - -User guide -========== - -Cppo is a preprocessor for programming languages that follow lexical rules -compatible with OCaml. - -Cppo supports a number of directives. A directive is a '#' sign placed -at the beginning of a line, possibly preceded by some whitespace, and followed -by a valid directive name or by a number: - - BLANK* "#" BLANK* ("define"|"undef" - |"if"|"ifdef"|"ifndef"|"else"|"elif"|"endif" - |"include" - |"warning"|"error" - |"ext"|"endext") ... - -Directives can be split into multiple lines by placing a backslash \ at -the end of the line to be continued. In general, any special character -can used as a normal character by preceding it with backslash. - - -1. File inclusion ------------------ - - #include "hello.ml" - -This is how a source file "hello.ml" can be included. -Relative paths are searched first in the directory of the current file -and then in the search paths added on the command line using -I, if any. - - -2. Macros ---------- - -This is a simple macro that doesn't take an argument ("object-like -macro" in the cpp jargon): - - #define Ms Mississippi - - match state with - Ms -> true - | _ -> false - -After preprocessing by cppo, the code above becomes: -match state with - Mississippi -> true - | _ -> false - -If needed, defined macros can be undefined. This is required prior to -redefining a macro: - - #undef X - -An important distinction with cpp is that only previously-defined -macros are accessible. Defining, undefining or redefining a macro has -no effect on how previous macros will expand. - -Macros can take arguments ("function-like macro" in the cpp -jargon). Both in the definition (#define) and in macro application the -opening parenthesis must stick to the macro's identifier: - - #define debug(args) if !debugging then Printf.eprintf args else () - - debug("Testing %i" (1 + 1)) - -is expanded into: - - if !debugging then Printf.eprintf "Testing %i" (1 + 1) else () - -Here is a multiline macro definition. Newlines occurring between -tokens must be protected by a backslash: - - #define repeat_until(action,condition) \ - action; \ - while not (condition) do \ - action \ - done - -All user-definable macros are constant. There are however two -predefined variable macros: __FILE__ and __LINE__ which take the value -of the position in the source file where the macro is being expanded. - - #define loc (Printf.sprintf "File %S, line %i" __FILE__ __LINE__) - -Macros can be defined on the command line as follows: - - # preprocessing only - cppo -D 'VERSION 1.0' example.ml - - # preprocessing and compiling - ocamlopt -c -pp "cppo -D 'VERSION 1.0'" example.ml - - -3. Conditionals ---------------- - -Here is a quick reference on conditionals available in cppo. If you -are not familiar with #ifdef, #ifndef, #if, #else and #elif, please -refer to the corresponding section in the cpp manual. - - #ifndef VERSION - #warning "VERSION is undefined" - #define VERSION "n/a" - #endif - #ifndef VERSION - #error "VERSION is undefined" - #endif - #if OCAML_MAJOR >= 3 && OCAML_MINOR >= 10 - ... - #endif - #ifdef X - ... - #elif defined Y - ... - #else - ... - #endif - -The boolean expressions following #if and #elif may perform arithmetic -operations and tests over 64-bit ints. - -Boolean expressions: - - defined ... followed by an identifier, returns true if such a macro exists - true - false - ( ... ) - ... && ... - ... || ... - not ... - -Arithmetic comparisons used in boolean expressions: - - ... = ... - ... < ... - ... > ... - ... <> ... - ... <= ... - ... >= ... - -Arithmetic operators over signed 64-bit ints: - - ( ... ) - ... + ... - ... - ... - ... * ... - ... / ... - ... mod ... - ... lsl ... - ... lsr ... - ... asr ... - ... land ... - ... lor ... - ... lxor ... - lnot ... - -Macro identifiers can be used in place of ints as long as they expand -to an int literal, e.g.: - - #define one 1 - - #if one + one <> 2 - #error "Something's wrong." - #endif - - -4. Source file location ------------------------ - -Location directives are the same as OCaml and are echoed in the -output. They consist of a line number optionally followed by a file name: - - # 123 - # 456 "source" - - -5. Messages ------------ - -Warnings and error messages can be produced by the preprocessor: - - #ifndef X - #warning "Assuming default value for X" - #define X 1 - #elif X = 0 - #error "X may not be null" - #endif - - -6. Calling an external processor --------------------------------- - -Cppo provides a mechanism for converting sections of a file using -and external program. Such a section must be placed between #ext and -#endext directives. - - $ cat foo - ABC - #ext lowercase - DEF - #endext - GHI - #ext lowercase - KLM - NOP - #endext - QRS - - $ cppo -x lowercase:'tr "[A-Z]" "[a-z]"' foo - # 1 "foo" - ABC - def - # 5 "foo" - GHI - klm - nop - # 10 "foo" - QRS - -In the example above, "lowercase" is the name given on the -command-line to external command 'tr "[A-Z]" "[a-z]"' that reads -input from stdin and writes its output to stdout. - - -7. Escaping ------------ - -The following characters can be escaped by a backslash when needed: - ( - ) - , - # - -In OCaml # is used for method calls. It is usually not a problem -because in order to be interpreted as a preprocessor directive, it -must be the first non-blank character of a line and be a known -directive. If an object has a define method and you want # to appear -first on a line, you would have to use \# instead: - - obj - \#define - -Line directives in the usual format supported by OCaml are correctly -interpreted by cppo. - -Comments and string literals constitute single tokens even when they -span across multiple lines. Therefore newlines within string literals -and comments should remain as-is (no preceding backslash) even in a -macro body: - - #define welcome \ - "********** - *Welcome!* - ********** - " - -8. Concatenation ----------------- - -CONCAT() is a predefined macro that takes two arguments, removes any -whitespace between and around them and fuses them into a single identifier. -The result of the concatenation must be a valid identifier of the -form [A-Za-z_][A-Za-z0-9_]+ or [A-Za-z], or empty. - -For example, - - #define x 123 - CONCAT(z, x) - -expands into: - - z123 - -However the following is illegal: - - #define x 123 - CONCAT(x, z) - -because 123z does not form a valid identifier. - -CONCAT(a,b) is roughly the equivalent a##b in cpp syntax. - - -9. Stringification ------------------- - -STRINGIFY() is a predefined macro that takes one argument, removes any leading -and trailing whitespace, reduces each internal whitespace sequence to -a single space character and produces a valid OCaml string literal. - -For example, - - #define TRACE(f) Printf.printf ">>> %s\n" STRINGIFY(f); f - TRACE(print_endline) "Hello" - -is expanded into: - - Printf.printf ">>> %s\n" "print_endline"; print_endline "Hello" - - -STRINGIFY(x) is the equivalent of #x in cpp syntax. - - -10. Detailed command-line usage and options ------------------------------------------- - -Usage: ./cppo [OPTIONS] [FILE1 [FILE2 ...]] -Options: - -D DEF - Equivalent of interpreting '#define DEF' before processing the - input - -U IDENT - Equivalent of interpreting '#undef IDENT' before processing the - input - -I DIR - Add directory DIR to the search path for included files - -o FILE - Output file - -q - Identify and preserve camlp4 quotations - -s - Output line directives pointing to the exact source location of - each token, including those coming from the body of macro - definitions. This behavior is off by default. - -n - Do not output any line directive other than those found in the - input (overrides -s). - -version - Print the version of the program and exit. - -x NAME:CMD_TEMPLATE - Define a custom preprocessor target section starting with: - #ext "NAME" - and ending with: - #endext - - NAME must be a lowercase identifier of the form [a-z][A-Za-z0-9_]* - - CMD_TEMPLATE is a command template supporting the following - special sequences: - %F file name (unescaped; beware of potential scripting attacks) - %B number of the first line - %E number of the last line - %% a single percent sign - - Filename, first line number and last line number are also - available from the following environment variables: - CPPO_FILE, CPPO_FIRST_LINE, CPPO_LAST_LINE. - - The command produced is expected to read the data lines from stdin - and to write its output to stdout. - -help Display this list of options - --help Display this list of options - - ------------------------------------------------------------------------------- -Martin Jambon <mar...@mjambon.com> diff --git a/README.md b/README.md new file mode 100644 index 0000000..c1a762e --- /dev/null +++ b/README.md @@ -0,0 +1,449 @@ +Cppo: cpp for OCaml +=================== + +Cppo is an equivalent of the C preprocessor for OCaml programs. +It allows the definition of simple macros and file inclusion. + +Cppo is: + +* more OCaml-friendly than cpp +* easy to learn without consulting a manual +* reasonably fast +* simple to install and to maintain + + +User guide +---------- + +Cppo is a preprocessor for programming languages that follow lexical rules +compatible with OCaml. + +Cppo supports a number of directives. A directive is a `#` sign placed +at the beginning of a line, possibly preceded by some whitespace, and followed +by a valid directive name or by a number: + +```ocaml +BLANK* "#" BLANK* ("define"|"undef" + |"if"|"ifdef"|"ifndef"|"else"|"elif"|"endif" + |"include" + |"warning"|"error" + |"ext"|"endext") ... +``` + +Directives can be split into multiple lines by placing a backslash `\` at +the end of the line to be continued. In general, any special character +can used as a normal character by preceding it with backslash. + + +File inclusion +-------------- + +```ocaml +#include "hello.ml" +``` + +This is how a source file `hello.ml` can be included. +Relative paths are searched first in the directory of the current file +and then in the search paths added on the command line using `-I`, if any. + + +Macros +------ + +This is a simple macro that doesn't take an argument ("object-like +macro" in the cpp jargon): + +```ocaml +#define Ms Mississippi + +match state with + Ms -> true + | _ -> false +``` + +After preprocessing by cppo, the code above becomes: + +```ocaml +match state with + Mississippi -> true + | _ -> false +``` + +If needed, defined macros can be undefined. This is required prior to +redefining a macro: + +```ocaml +#undef X +``` + +An important distinction with cpp is that only previously-defined +macros are accessible. Defining, undefining or redefining a macro has +no effect on how previous macros will expand. + +Macros can take arguments ("function-like macro" in the cpp +jargon). Both in the definition (`#define`) and in macro application the +opening parenthesis must stick to the macro's identifier: + +```ocaml +#define debug(args) if !debugging then Printf.eprintf args else () + +debug("Testing %i" (1 + 1)) +``` + +is expanded into: + +```ocaml +if !debugging then Printf.eprintf "Testing %i" (1 + 1) else () +``` + +Here is a multiline macro definition. Newlines occurring between +tokens must be protected by a backslash: + +```ocaml +#define repeat_until(action,condition) \ + action; \ + while not (condition) do \ + action \ + done +``` + +All user-definable macros are constant. There are however two +predefined variable macros: `__FILE__` and `__LINE__` which take the value +of the position in the source file where the macro is being expanded. + +```ocaml +#define loc (Printf.sprintf "File %S, line %i" __FILE__ __LINE__) +``` + +Macros can be defined on the command line as follows: + +```ocaml +# preprocessing only +cppo -D 'VERSION 1.0' example.ml + +# preprocessing and compiling +ocamlopt -c -pp "cppo -D 'VERSION 1.0'" example.ml +``` + +Conditionals +------------ + +Here is a quick reference on conditionals available in cppo. If you +are not familiar with `#ifdef`, `#ifndef`, `#if`, `#else` and `#elif`, please +refer to the corresponding section in the cpp manual. + +```ocaml +#ifndef VERSION +#warning "VERSION is undefined" +#define VERSION "n/a" +#endif +#ifndef VERSION +#error "VERSION is undefined" +#endif +#if OCAML_MAJOR >= 3 && OCAML_MINOR >= 10 +... +#endif +#ifdef X +... +#elif defined Y +... +#else +... +#endif +``` + +The boolean expressions following `#if` and `#elif` may perform arithmetic +operations and tests over 64-bit ints. + +Boolean expressions: + +* `defined` ... followed by an identifier, returns true if such a macro exists +* `true` +* `false` +* `(` ... `)` +* ... `&&` ... +* ... `||` ... +* `not` ... + +Arithmetic comparisons used in boolean expressions: + +* ... `=` ... +* ... `<` ... +* ... `>` ... +* ... `<>` ... +* ... `<=` ... +* ... `>=` ... + +Arithmetic operators over signed 64-bit ints: + +* `(` ... `)` +* ... `+` ... +* ... `-` ... +* ... `*` ... +* ... `/` ... +* ... `mod` ... +* ... `lsl` ... +* ... `lsr` ... +* ... `asr` ... +* ... `land` ... +* ... `lor` ... +* ... `lxor` ... +* `lnot` ... + +Macro identifiers can be used in place of ints as long as they expand +to an int literal, e.g.: + +```ocaml +#define one 1 + +#if one + one <> 2 +#error "Something's wrong." +#endif +``` + +Source file location +-------------------- + +Location directives are the same as OCaml and are echoed in the +output. They consist of a line number optionally followed by a file name: + +```ocaml +# 123 +# 456 "source" +``` + +Messages +-------- + +Warnings and error messages can be produced by the preprocessor: + +```ocaml +#ifndef X + #warning "Assuming default value for X" + #define X 1 +#elif X = 0 + #error "X may not be null" +#endif +``` + +Calling an external processor +----------------------------- + +Cppo provides a mechanism for converting sections of a file using +and external program. Such a section must be placed between `#ext` and +`#endext` directives. + +```bash +$ cat foo +ABC +#ext lowercase +DEF +#endext +GHI +#ext lowercase +KLM +NOP +#endext +QRS + +$ cppo -x lowercase:'tr "[A-Z]" "[a-z]"' foo +# 1 "foo" +ABC +def +# 5 "foo" +GHI +klm +nop +# 10 "foo" +QRS +``` + +In the example above, `lowercase` is the name given on the +command-line to external command `'tr "[A-Z]" "[a-z]"'` that reads +input from stdin and writes its output to stdout. + + +Escaping +-------- + +The following characters can be escaped by a backslash when needed: + +```ocaml +( +) +, +# +``` + +In OCaml `#` is used for method calls. It is usually not a problem +because in order to be interpreted as a preprocessor directive, it +must be the first non-blank character of a line and be a known +directive. If an object has a define method and you want `#` to appear +first on a line, you would have to use `\#` instead: + +```ocaml +obj + \#define +``` + +Line directives in the usual format supported by OCaml are correctly +interpreted by cppo. + +Comments and string literals constitute single tokens even when they +span across multiple lines. Therefore newlines within string literals +and comments should remain as-is (no preceding backslash) even in a +macro body: + +```ocaml +#define welcome \ +"********** +*Welcome!* +********** +" +``` + +Concatenation +------------- + +`CONCAT()` is a predefined macro that takes two arguments, removes any +whitespace between and around them and fuses them into a single identifier. +The result of the concatenation must be a valid identifier of the +form [A-Za-z_][A-Za-z0-9_]+ or [A-Za-z], or empty. + +For example, + +```ocaml +#define x 123 +CONCAT(z, x) +``` + +expands into: + +```ocaml +z123 +``` + +However the following is illegal: + +```ocaml +#define x 123 +CONCAT(x, z) +``` + +because 123z does not form a valid identifier. + +`CONCAT(a,b)` is roughly equivalent to `a##b` in cpp syntax. + + +Stringification +--------------- + +`STRINGIFY()` is a predefined macro that takes one argument, +removes any leading and trailing whitespace, reduces each internal +whitespace sequence to a single space character and produces +a valid OCaml string literal. + +For example, + +```ocaml +#define TRACE(f) Printf.printf ">>> %s\n" STRINGIFY(f); f +TRACE(print_endline) "Hello" +``` + +is expanded into: + +```ocaml +Printf.printf ">>> %s\n" "print_endline"; print_endline "Hello" +``` + +`STRINGIFY(x)` is the equivalent of `#x` in cpp syntax. + + +Ocamlbuild plugin +------------------ + +An ocamlbuild plugin is available. To use it, you can call ocamlbuild with the argument `--plugin-tag package(cppo_ocamlbuild)` (only since 4.01). + +With Oasis : +``` +OCamlVersion: >= 4.01 +AlphaFeatures: ocamlbuild_more_args +XOCamlbuildPluginTags: package(cppo_ocamlbuild) +``` + +After that, you need to add in your `myocamlbuild.ml` : +```ocaml +let () = + Ocamlbuild_plugin.dispatch + (fun hook -> + Ocamlbuild_cppo.dispatcher hook ; + ) +``` + +The plugin will apply cppo on all files ending in `.cppo.ml` in order to produce`.ml` files. The following tags are available: +* `cppo_D(X)` ≡ `-D X` +* `cppo_U(X)` ≡ `-U X` +* `cppo_q` ≡ `-q` +* `cppo_s` ≡ `-s` +* `cppo_n` ≡ `-n` +* `cppo_x(NAME:CMD_TEMPLATE)` ≡ `-x NAME:CMD_TEMPLATE` +* The tag `cppo_I(foo)` can behave in two way: + * If `foo` is a directory, it's equivalent to `-I foo`. + * If `foo` is a file, it adds `foo` as a dependency and apply `-I parent(foo)`. + +Detailed command-line usage and options +--------------------------------------- + +``` +Usage: ./cppo [OPTIONS] [FILE1 [FILE2 ...]] +Options: + -D DEF + Equivalent of interpreting '#define DEF' before processing the + input + -U IDENT + Equivalent of interpreting '#undef IDENT' before processing the + input + -I DIR + Add directory DIR to the search path for included files + -o FILE + Output file + -q + Identify and preserve camlp4 quotations + -s + Output line directives pointing to the exact source location of + each token, including those coming from the body of macro + definitions. This behavior is off by default. + -n + Do not output any line directive other than those found in the + input (overrides -s). + -version + Print the version of the program and exit. + -x NAME:CMD_TEMPLATE + Define a custom preprocessor target section starting with: + #ext "NAME" + and ending with: + #endext + + NAME must be a lowercase identifier of the form [a-z][A-Za-z0-9_]* + + CMD_TEMPLATE is a command template supporting the following + special sequences: + %F file name (unescaped; beware of potential scripting attacks) + %B number of the first line + %E number of the last line + %% a single percent sign + + Filename, first line number and last line number are also + available from the following environment variables: + CPPO_FILE, CPPO_FIRST_LINE, CPPO_LAST_LINE. + + The command produced is expected to read the data lines from stdin + and to write its output to stdout. + -help Display this list of options + --help Display this list of options +``` + +Author +------ + +Martin Jambon <mar...@mjambon.com> diff --git a/ocamlbuild_plugin/_tags b/ocamlbuild_plugin/_tags new file mode 100644 index 0000000..dc946a1 --- /dev/null +++ b/ocamlbuild_plugin/_tags @@ -0,0 +1 @@ +true: package(ocamlbuild) diff --git a/ocamlbuild_plugin/ocamlbuild_cppo.ml b/ocamlbuild_plugin/ocamlbuild_cppo.ml new file mode 100644 index 0000000..42cf246 --- /dev/null +++ b/ocamlbuild_plugin/ocamlbuild_cppo.ml @@ -0,0 +1,30 @@ + +open Ocamlbuild_plugin + +let dispatcher = function + | After_rules -> begin + let dep = "%(name).cppo.ml" in + let prod1 = "%(name: <*> and not <*.cppo>).ml" in + let prod2 = "%(name: <**/*> and not <**/*.cppo>).ml" in + let f prod env _build = + let dep = env dep in + let prod = env prod in + let tags = tags_of_pathname prod ++ "cppo" in + Cmd (S[A "cppo"; T tags; S [A "-o"; P prod]; P dep ]) + in + rule "cppo1" ~dep ~prod:prod1 (f prod1) ; + rule "cppo2" ~dep ~prod:prod2 (f prod2) ; + pflag ["cppo"] "cppo_D" (fun s -> S [A "-D"; A s]) ; + pflag ["cppo"] "cppo_U" (fun s -> S [A "-U"; A s]) ; + pflag ["cppo"] "cppo_I" (fun s -> + if Pathname.is_directory s then S [A "-I"; P s] + else S [A "-I"; P (Pathname.dirname s)] + ) ; + pdep ["cppo"] "cppo_I" (fun s -> + if Pathname.is_directory s then [] else [s]) ; + flag ["cppo"; "cppo_q"] (A "-q") ; + flag ["cppo"; "cppo_s"] (A "-s") ; + flag ["cppo"; "cppo_s"] (A "-n") ; + pflag ["cppo"] "cppo_x" (fun s -> S [A "-x"; A s]) + end + | _ -> () diff --git a/ocamlbuild_plugin/ocamlbuild_cppo.mli b/ocamlbuild_plugin/ocamlbuild_cppo.mli new file mode 100644 index 0000000..692d887 --- /dev/null +++ b/ocamlbuild_plugin/ocamlbuild_cppo.mli @@ -0,0 +1,2 @@ + +val dispatcher : Ocamlbuild_plugin.hook -> unit diff --git a/opam b/opam new file mode 100644 index 0000000..b8af947 --- /dev/null +++ b/opam @@ -0,0 +1,13 @@ +opam-version: "1" +maintainer: "cont...@ocamlpro.com" +authors: ["Martin Jambon"] +homepage: "http://mjambon.com/cppo.html" +license: "BSD-3-Clause" +build: [ + [make] + [make "install-lib"] +] + +remove: [ + ["ocamlfind" "remove" "cppo_ocamlbuild"] +] \ No newline at end of file -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/cppo.git _______________________________________________ Pkg-ocaml-maint-commits mailing list Pkg-ocaml-maint-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-ocaml-maint-commits