File tree 13 files changed +195
-178
lines changed
13 files changed +195
-178
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ all: build
2
2
3
3
build :
4
4
@dune build @all
5
- cp -f _build/default/mkocaml.exe /usr/local/bin/mkocaml
5
+ @ cp -f _build/default/bin /mkocaml.exe /usr/local/bin/mkocaml
6
6
7
7
install :
8
8
@dune install
Original file line number Diff line number Diff line change
1
+ (executable
2
+ (name mkocaml)
3
+ (libraries unix ioUtils gitUtils makefileUtils opamUtils))
Original file line number Diff line number Diff line change
1
+ open IoUtils
2
+ open GitUtils
3
+ open MakefileUtils
4
+ open OpamUtils
5
+
6
+ let lib_name = ref " "
7
+ let exe_name = ref " "
8
+
9
+ let bad_arg arg =
10
+ raise @@ Arg. Bad (Format. sprintf " Unrecognized argument: %s" arg)
11
+
12
+ let usage =
13
+ Format. sprintf " Usage: %s [-l name] [-e name]" Sys. argv.(0 )
14
+
15
+ let specs = [
16
+ " -l" , Arg. Set_string lib_name, " : Creates a library with the given name" ;
17
+ " -e" , Arg. Set_string exe_name, " : Creates an executable with the given name" ;
18
+ ]
19
+
20
+ let setup_exe project =
21
+ Format. sprintf " dune init exec %s bin" project |> cmd_;
22
+ if Sys. file_exists " Makefile" |> not then
23
+ makefile project `Exec account |> write_file " Makefile" ;
24
+ setup_opam project
25
+
26
+ let setup_lib project =
27
+ Format. sprintf " dune init lib %s lib --inline-tests && touch lib/%s.ml"
28
+ project project |> cmd_;
29
+ if Sys. file_exists " Makefile" |> not then
30
+ makefile project `Lib account |> write_file " Makefile" ;
31
+ setup_opam project
32
+
33
+ let () =
34
+ Arg. parse specs bad_arg usage;
35
+ if String. length ! lib_name > 0 then
36
+ let _ = setup_git () in
37
+ setup_lib ! lib_name
38
+ else
39
+ if String. length ! exe_name > 0 then
40
+ let _ = setup_git () in
41
+ setup_exe ! exe_name
42
+ else
43
+ print_endline usage
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ (library
2
+ (name gitUtils)
3
+ (libraries ioUtils))
Original file line number Diff line number Diff line change
1
+ open IoUtils
2
+
3
+ let username = exec " git config user.name"
4
+ let email = exec " git config user.email"
5
+ let dune_version = exec " dune --version"
6
+
7
+ let account =
8
+ let open String in
9
+ username |> lowercase_ascii |> split_on_char ' ' |> concat " "
10
+
11
+ let gitignore =
12
+ "
13
+ *.annot
14
+ *.cmo
15
+ *.cma
16
+ *.cmi
17
+ *.a
18
+ *.o
19
+ *.cmx
20
+ *.cmxs
21
+ *.cmxa
22
+
23
+ # ocamlbuild working directory
24
+ _build/
25
+
26
+ # ocamlbuild targets
27
+ *.byte
28
+ *.native
29
+
30
+ # oasis generated files
31
+ setup.data
32
+ setup.log
33
+
34
+ # Merlin configuring file for Vim and Emacs
35
+ .merlin
36
+
37
+ # Dune generated files
38
+ *.install
39
+
40
+ # Local OPAM switch
41
+ _opam/
42
+ notes
43
+ *DS_Store
44
+ "
45
+
46
+ let setup_git () =
47
+ cmd_ " git init" ;
48
+ write_file " .gitignore" gitignore
Original file line number Diff line number Diff line change
1
+ (library
2
+ (name ioUtils)
3
+ (libraries unix))
Original file line number Diff line number Diff line change
1
+ let exec cmd = cmd |> Unix. open_process_in |> input_line
2
+
3
+ let cmd_ cmd = let _ = Sys. command cmd in ()
4
+
5
+ let write_file name str =
6
+ let chan = open_out name in
7
+ output_string chan str;
8
+ close_out chan
Original file line number Diff line number Diff line change
1
+ (library
2
+ (name makefileUtils)
3
+ (libraries ioUtils))
Original file line number Diff line number Diff line change
1
+ let move_exe_to_bin project = function
2
+ | `Exec -> Format. sprintf
3
+ " \t @cp -f _build/default/bin/main.exe /usr/local/bin/%s\n " project
4
+ | _ -> " "
5
+
6
+ let makefile project project_type account =
7
+ let mv_cmd = move_exe_to_bin project project_type in
8
+ Format. sprintf
9
+ " all: build
10
+
11
+ build:
12
+ \t @dune build @all
13
+ %s
14
+ install:
15
+ \t @dune install
16
+
17
+ test: build
18
+ \t @dune runtest
19
+
20
+ doc: build
21
+ \t @opam install odoc
22
+ \t @dune build @doc
23
+
24
+ clean:
25
+ \t @dune clean
26
+
27
+ # Create a release on Github, then run git pull
28
+ publish:
29
+ \t @git tag 1.0
30
+ \t @git push origin 1.0
31
+ \t @git pull
32
+ \t @opam pin .
33
+ \t @opam publish https://github.com/%s/%s/archive/1.0.tar.gz
34
+ "
35
+ (* Move executables to /usr/local/bin *)
36
+ mv_cmd
37
+ (* Git account name *)
38
+ account
39
+ (* Git project name *)
40
+ project
Original file line number Diff line number Diff line change
1
+ (library
2
+ (name opamUtils)
3
+ (libraries ioUtils gitUtils))
Original file line number Diff line number Diff line change
1
+ open IoUtils
2
+ open GitUtils
3
+
4
+ let opam project =
5
+ Format. sprintf
6
+ "
7
+ opam-version: \" 2.0\"
8
+ version: \" 1.0\"
9
+ authors: \" %s <%s>\"
10
+ maintainer: \" %s <%s>\"
11
+ homepage: \" https://github.com/%s/%s\"
12
+ bug-reports: \" https://github.com/%s/%s/issues\"
13
+ dev-repo: \" git://github.com/%s/%s.git\"
14
+ synopsis: \"\"
15
+ build: [
16
+ [\" dune\" \" subst\" ] {pinned}
17
+ [\" dune\" \" build\" \" -p\" name \" -j\" jobs]
18
+ ]
19
+
20
+ depends: [
21
+ \" dune\" {>= \" %s\" }
22
+ ]
23
+ "
24
+ (* Authors *)
25
+ username email
26
+ (* Maintainers *)
27
+ username email
28
+ (* Homepage *)
29
+ account project
30
+ (* Bug reports *)
31
+ account project
32
+ (* Dev repo *)
33
+ account project
34
+ (* Build depends on user's dune version *)
35
+ dune_version
36
+
37
+ let setup_opam project =
38
+ let filename = project ^ " .opam" in
39
+ if Sys. file_exists filename |> not then
40
+ opam project |> write_file filename; cmd_ " dune build @install"
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments