caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* A Tutorial on GNU Make with OCaml
@ 2010-05-21  3:53 Jeff Shaw
  2010-05-21  5:18 ` [Caml-list] " Michael Grünewald
  2010-05-21  8:28 ` Goswin von Brederlow
  0 siblings, 2 replies; 5+ messages in thread
From: Jeff Shaw @ 2010-05-21  3:53 UTC (permalink / raw)
  To: caml-list

Dear OCamlers,
I spent quite a lot of time today getting better acquainted with GNU 
make and decided I to share my experience and results. It's a bit on the 
newbie friendly side of instruction.

http://shawjeff.blogspot.com/2010/05/this-is-storytutorial-about-how-i_20.html

I hope someone finds it helpful!

Jeff Shaw
shawjef3@msu.edu


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] A Tutorial on GNU Make with OCaml
  2010-05-21  3:53 A Tutorial on GNU Make with OCaml Jeff Shaw
@ 2010-05-21  5:18 ` Michael Grünewald
  2010-05-21  8:17   ` David Allsopp
  2010-05-21  8:28 ` Goswin von Brederlow
  1 sibling, 1 reply; 5+ messages in thread
From: Michael Grünewald @ 2010-05-21  5:18 UTC (permalink / raw)
  To: OCaml users

Dear Jeff,

Jeff Shaw wrote:
>
> Dear OCamlers,
> I spent quite a lot of time today getting better acquainted with GNU
> make and decided I to share my experience and results. It's a bit on the
> newbie friendly side of instruction.
>
> http://shawjeff.blogspot.com/2010/05/this-is-storytutorial-about-how-i_20.html

ten years ago I learned GNU Make and found it awful to program. I had 
the feeling that it is nit meant to write complex (or mildly complex) 
makefiles. Instead makefiles should be written by another program. I may 
be wrong but I think that GNU Make shines when it is used as part of the 
auto-tools chain, that you may also need to learn.

My personal taste goes rather to BSD Make (make in FreeBSD, bsdmake in 
OS-X and bmake in some other places): I found it much mor eeasy to 
program, and the FreeBSD build toolchain and ports collection provide a 
significant amount of Makefile techniques one can draws its inspiration 
from. I wrote my own macros for my OCaml projects. You can find them here:

   http://home.gna.org/bsdmakepscripts/


If you are interested in make and makefile techniques, you may have 
interest in the macros I wrote. You can see them in action in

   https://forge.ocamlcore.org/scm/viewvc.php/trunk/?root=libertine

Read the various makefiles you found in the repository!

Note that if you are looking for an efficient way to handle your 
projects, it seems that ocamlbuild might be a more reasonable approach. 
I never used it though.

The OCaml build system I wrote is not that good as I would like it to 
be, for instance it lacks the possibility to compile several versions of 
a library or program against different ocamlbuild predicates. For simple 
things, it works very good, however! Of course I am very busy (math 
post-doc) so I never really wrote documentation for these macros, but 
the examples are here and I may have time for questions.

Remark: the TeX oriented macros I also wrote *are* a bit documented! See 
http://home.gna.org/bsdmakepscripts/tex.html
-- 
Cheers,
Michael


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [Caml-list] A Tutorial on GNU Make with OCaml
  2010-05-21  5:18 ` [Caml-list] " Michael Grünewald
@ 2010-05-21  8:17   ` David Allsopp
  2010-05-21  8:42     ` Michaël Grünewald
  0 siblings, 1 reply; 5+ messages in thread
From: David Allsopp @ 2010-05-21  8:17 UTC (permalink / raw)
  To: 'Michael Grünewald', 'OCaml users'

Michael Grünewald wrote:
> Dear Jeff,
> 
> Jeff Shaw wrote:
> >
> > Dear OCamlers,
> > I spent quite a lot of time today getting better acquainted with GNU
> > make and decided I to share my experience and results. It's a bit on
> > the newbie friendly side of instruction.
> >
> > http://shawjeff.blogspot.com/2010/05/this-is-storytutorial-about-how-i
> > _20.html
> 
> ten years ago I learned GNU Make and found it awful to program. I had the
> feeling that it is nit meant to write complex (or mildly complex)
> makefiles.

I could be wrong about the way it's constructed, but I think you'll find
that the Linux kernel build system is *written* (rather than generated) in
GNU make cf. Managing Projects with GNU Make 3rd Ed pp. 218--228.

> Instead makefiles should be written by another program. I may
> be wrong but I think that GNU Make shines when it is used as part of the
> auto-tools chain, that you may also need to learn.

IMO users of auto-tools fall into two categories - users who need Makefiles
that work cross-platform (so package maintainers) and programmers who don't
regard the build system of their code as worth spending any time on. I
similarly 10 years ago (nearly) learned GNU make but my reaction was the
opposite to yours - I now have handwritten Makefiles for quite large
projects which build projects containing only OCaml but C, JavaScript, XHTML
templates and various other text files, maintain patches against 3rd party
libraries. The Makefile for my website is written in GNU make, runs
cross-platform and uses a parallel and distributed build system (distributed
only because it has to compile some programs on BSD and then pull them back
to Windows before uploading) with not an auto-tool in sight (assuming that
we're allowed dependency generators, of course). Granted, I spent a day
writing it but to me that's the divide - are you willing to spend the time
handcrafting a fully optimised (and possibly therefore faster) build system
or stick with something that takes a few seconds in an auto-tool.

> My personal taste goes rather to BSD Make (make in FreeBSD, bsdmake in OS-
> X and bmake in some other places): I found it much mor eeasy to program,
> and the FreeBSD build toolchain and ports collection provide a significant
> amount of Makefile techniques one can draws its inspiration from. I wrote
> my own macros for my OCaml projects.

So essentially you dislike make in general (bmake and gmake aren't *that*
different - though that said on BSD I always use gmake) - simply that on BSD
there are a large number of pre-written Makefiles and Makefile fragments
which allow you to produce your Makefiles more quickly.


David


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] A Tutorial on GNU Make with OCaml
  2010-05-21  3:53 A Tutorial on GNU Make with OCaml Jeff Shaw
  2010-05-21  5:18 ` [Caml-list] " Michael Grünewald
@ 2010-05-21  8:28 ` Goswin von Brederlow
  1 sibling, 0 replies; 5+ messages in thread
From: Goswin von Brederlow @ 2010-05-21  8:28 UTC (permalink / raw)
  To: Jeff Shaw; +Cc: caml-list

Jeff Shaw <shawjef3@msu.edu> writes:

> Dear OCamlers,
> I spent quite a lot of time today getting better acquainted with GNU
> make and decided I to share my experience and results. It's a bit on
> the newbie friendly side of instruction.
>
> http://shawjeff.blogspot.com/2010/05/this-is-storytutorial-about-how-i_20.html
>
> I hope someone finds it helpful!
>
> Jeff Shaw
> shawjef3@msu.edu

Some comments:

- For things you don't want to be deleted even though make sees they
will never be reused on subsequent make calls look up .PRECIOUS

- Targets that have no dependencies and create no file are implicitly
PHONY. No need to specify it as such. A reason for why one might do it
anyway would be to protect against someone doing "touch clean" by
accident:

% touch clean
% make clean
make: `clean' is up to date.

A .PHONY: clean would prevent that and run clean anyway.

- Don't create interface files if there are none

If you start writing a module and haven't decided on the exact interface
it will be a pain to delete the generated interface file every time. It
is also completly useless as you can generate the cmi file from the .ml
file directly. No need to create .mli first.

- Use ocamldep

Ocamldep figures out wich modules depend on other modules and generates
that in Makefile syntax for you. Unfortunately ocamldep lacks an option
to generate a dependency line for the final binary so SOURCES below must
be set by hand and in the right order.

- List source files, not generated files and use pattern substitution to
get the later


Here is my own version of a Makefile for a trivial project. I hardcoded
it for native code but you already know how to use 'TARGET=byte' from
your Makefile. Merging the two is left as an execise.

PROG       := prog
LIBS       := graphics unix
SOURCES    := foo.ml bar.ml baz.ml

# No user servicable parts below
INTERFACES := $(wildcard *.mli)
OBJS       := $(patsubst %.ml,%.cmx,$(SOURCES))
LIBS       := $(patsubst %,%.cmxa,$(LIBS))

# Count number of cores and use them all, no idea how do to that for windows
PARALLEL   := -j$(shell cat /proc/cpuinfo | grep processor | wc -l)

all:
	$(MAKE) $(PARALLEL) $(PROG)

$(PROG): $(OBJS)
        ocamlopt -o $@ $(LIBS) $(OBJS)

clean:
        rm -rf $(PROG) *.o *.cmx *.cmi *~

%.cmx: %.ml
        ocamlopt -c $*.ml

%.cmi: %.mli
        ocamlopt -c $*.mli

.depend: $(SOURCES) $(INTERFACES)
        ocamldep -native $(SOURCES) $(INTERFACES) >.depend

include .depend


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] A Tutorial on GNU Make with OCaml
  2010-05-21  8:17   ` David Allsopp
@ 2010-05-21  8:42     ` Michaël Grünewald
  0 siblings, 0 replies; 5+ messages in thread
From: Michaël Grünewald @ 2010-05-21  8:42 UTC (permalink / raw)
  To: David Allsopp; +Cc: 'OCaml users'

Hi David,

David Allsopp wrote:

>Michael Grünewald wrote:
>  
>
>>My personal taste goes rather to BSD Make (make in FreeBSD, bsdmake in OS-
>>X and bmake in some other places): I found it much mor eeasy to program,
>>and the FreeBSD build toolchain and ports collection provide a significant
>>amount of Makefile techniques one can draws its inspiration from. I wrote
>>my own macros for my OCaml projects.
>>    
>>
>
>So essentially you dislike make in general (bmake and gmake aren't *that*
>different - though that said on BSD I always use gmake) - simply that on BSD
>there are a large number of pre-written Makefiles and Makefile fragments
>which allow you to produce your Makefiles more quickly.
>  
>
Oh no, not at all, I really love make and the central role it plays in 
my use of a UNIX workstation. Since I have to work on Mac OS-X, Linux 
and Solaris, while I have FreeBSD at home, I had to pay special 
attention to the portability of the macros and reimplemented many 
mechanisms presented in the `standard' BSD Makefiles.  I use them all 
the time, and they usually work like a charm!

The most polished sets are for the production of TeX/LaTeX documents 
(with METAPOST and BIBTeX support) and the production of a web page 
(with sgmlnorm and tidy). The OCaml macros work but some parts really 
need to be rewritten.

You are quite right that bmake and gmake are not that different. When I 
switched from GNU Make to BMake, I found it easy and straightforward to 
program and appreciate the lot of meaningful examples I could study to 
learn the proper use of the program. It does not need to mean that such 
examples do not exist for gmake, just that I did not found them in times 
of need.

Best Regards,
Michael


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-05-21  8:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-21  3:53 A Tutorial on GNU Make with OCaml Jeff Shaw
2010-05-21  5:18 ` [Caml-list] " Michael Grünewald
2010-05-21  8:17   ` David Allsopp
2010-05-21  8:42     ` Michaël Grünewald
2010-05-21  8:28 ` Goswin von Brederlow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).