1# This is the bare minimum needed to build a functioning program with
2# Cogent.
3
4# The cogent compiler knows where stdgum lives but needs some help in
5# setting up arguments for the C preprocessor.
6#
7# Code generated by cogent relies on definitions from stdgum for
8# primitive items.
9LIBGUM=$(shell cogent --libgum-dir)
10
11# We are going to rely on the stdgum libraries on the C preprocessor
12# when used by cogent and also in our C compiler.
13CFLAGS+=-I${LIBGUM} -I${LIBGUM}gum/anti -O2
14
15# We need to tell cogent, which uses the C preprocessor for anti-quoted
16# C, how to invoke the C preprocessor so that it knows where all of the
17# necessary libraries are.
18COGENTFLAGS= \
19	--cpp-args="\$$CPPIN -o \$$CPPOUT -P $(CFLAGS)" --cpp=cpp
20
21# Our final program will be compiled into main.
22all: main
23
24# Cogent creates a number of intermediary files.
25clean:
26	rm -rf generated.{h,c} main_pp.ac main_pp_inferred.c main
27
28# Cogent will currently output to a file with a name based on the name
29# of the anti-quoted C file. We can simply compile this output to get
30# our final program.
31main: main_pp_inferred.c
32	$(CC) $(CFLAGS) -o $@ $^
33
34# This is how we get cogent to generate a C file based on our
35# anti-quoted C and cogent source.
36#
37# --infer-c-funcs tells cogent where the anti-quoted C comes from.
38# -ogenerated tells cogent to output the C generated from the cogent
39#     source into a pair of files called generated.c and generated.h
40# -g telss cogent to generate C code from the cogent source
41main_pp_inferred.c: main.ac Iter.cogent
42	cogent \
43		${COGENTFLAGS} \
44		--infer-c-funcs=main.ac \
45		-ogenerated \
46		-g Iter.cogent
47