How to write a Makefile for a project in ATS

115 views
Skip to first unread message

gmhwxi

unread,
Oct 19, 2013, 8:40:47 PM10/19/13
to ats-lan...@googlegroups.com
FYI.

I put on-line some code to demonstrate a simple way to do a project in ATS:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/EFFECTIVATS/DiningPhil

The Makefile I used is of a very simple style that can be easily adapted for handling other projects:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/EFFECTIVATS/DiningPhil/Makefile

The support in patsopt for computing file dependency (depgen) makes it very convenient to generate
file dependency information that can used directly by 'make'.


Brandon Barker

unread,
Dec 22, 2013, 3:16:10 PM12/22/13
to ats-lan...@googlegroups.com
I would be curious to see a recommended template for ATS that allows compilation from c source using a C compiler as an intermediate step (in case users do not have ATS installed). Here is a working (but possibly improvable) example from ATS 1. 

Apologies if this has been covered previously, as I thought it had, but I couldn't find where.

gmhwxi

unread,
Dec 22, 2013, 3:36:41 PM12/22/13
to ats-lan...@googlegroups.com

I suggest that you use the following rules to generate C code from ATS source:

%_sats.c: %.sats; $(ATSCC) --cc -o $@ $<
%_dats.c: %.dats; $(ATSCC) --cc -o $@ $<

Also, it is good to generate a dependency file .depend and then add the following line

-include .depend

gmhwxi

unread,
Dec 22, 2013, 4:07:45 PM12/22/13
to ats-lan...@googlegroups.com
Here is an example showing how to generate C code first from ATS source and then compile
the generated C code all at once:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/PROJECT/SMALL/GameOf24/OBJC

Brandon Barker

unread,
Dec 24, 2013, 11:25:20 PM12/24/13
to ats-lan...@googlegroups.com
At this point I am wondering if the ideal situation would be to have an option to atscc to simply replace staload, dynload, etc. with #includes when a "portable" argument is specified.

My code is pretty small, so I will probably just replace all staload/dynloads with #includes for now (it is ATS1 anyway so I am not requesting any new features for this purpose). I guess there is no reason why this wouldn't work with the garbage collector as well, right?

Merry Christmas :-)

gmhwxi

unread,
Dec 25, 2013, 4:13:09 PM12/25/13
to ats-lan...@googlegroups.com
Merry Chrismas!

I can think of many ways of generating standalone C code from ATS source.
Probably the simplest way is to put all the ATS code of a project in one single file.

Say you have foo1.dats and foo2.dats. Create a file of the name standalone.dats
and put the following lines inside standalone:

local #include "./foo1.dats" in (*nothing*) end // using [local] to avoid name collision
local #include "./foo2.dats" in (*nothing*) end // using [local] to avoid name collision

Then do:

patscc -ccats standalone.dats

Then the generated standalone_dats.c is essentially what you want.

Do not replace staload/dynload in foo1.dats and foo2.dats with #include.
You still want to keep the structure of the project. Think of standalone.dats
as a file solely for the purpose of packaging.

Of course, you still need various header files (that is, CATS-files in ATS) in order
to compile standalone_dats.c?

Brandon Barker

unread,
Dec 26, 2013, 9:58:22 PM12/26/13
to ats-lan...@googlegroups.com
Thanks for the hints - I was wondering if there was an automated way for these dependencies (CATS, etc.) to be added in by atsopt, or a list of files printed. At least for reading the help for atscc and atsopt (ATS1), I didn't see anything that stood out. gcc -MM seems to list a lot of stuff that isn't actually needed but is included by ATS just in case, so I guess this is the best bet for the moment - I will give it a try.

Ian Denhardt

unread,
Dec 27, 2013, 8:39:37 PM12/27/13
to gmhwxi, ats-lan...@googlegroups.com
I had a thought.

I'd like my makefiles to look more like:

> include $(PATSHOME)/mk/pre.mk
>
> SOURCESsta := \
> DiningPhil.sats \
>
> SOURCESdyn := \
> DiningPhil.dats \
> DiningPhil_fork.dats \
> DiningPhil_dine.dats \
> DiningPhil_think.dats
>
> TARGET := cmdname
>
> include $(PATSHOME)/mk/post.mk

Rather than have a set of idioms for writing makefiles for each project,
we could just say, we're using gnu make, if you write some software in
ATS, include those makefiles from the $PATSHOME directory, and just
specify the information that's unique about your project. Why have a
convention when you can just have a library?

I believe the gnu implemenetation of objective C provides something like
this, and Plan 9 From Bell Labs does something very similar throughout
it's build system. The go programming language used this before they'd
written their own build tools.

Thoughts?

Quoting gmhwxi (2013-10-19 20:40:47)
> --
> You received this message because you are subscribed to the Google
> Groups "ats-lang-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to ats-lang-user...@googlegroups.com.
> To post to this group, send email to ats-lan...@googlegroups.com.
> To view this discussion on the web visit
> [1]https://groups.google.com/d/msgid/ats-lang-users/bf413957-049f-4037-
> b169-eb983ab1d7d2%40googlegroups.com.
>
> References
>
> 1. https://groups.google.com/d/msgid/ats-lang-users/bf413957-049f-4037-b169-eb983ab1d7d2%40googlegroups.com

gmhwxi

unread,
Dec 27, 2013, 10:28:51 PM12/27/13
to ats-lan...@googlegroups.com
I like this simple idea.

I put two files in $(PATSHOME)/share:

atsmake-pre.mk
atsmake-post.mk

I also renamed SOURCESsta to SOURCES_SATS and SOURCESdyn to SOURCES_DATS.

Here is an example:

https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/EFFECTIVATS/DiningPhil2/Makefile

For now, this is all experimental.
Reply all
Reply to author
Forward
0 new messages