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 -g
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="-std=c99 \$$CPPIN -o \$$CPPOUT -P $(CFLAGS)" --cpp=cpp \
20 	--fno-static-inline
21
22# Our final program will be compiled into main.
23all: main
24
25# Cogent creates a number of intermediary files.
26clean:
27	rm -rf generated.[hc] main_pp.ac main_pp_inferred.c main
28
29# Cogent will currently output to a file with a name based on the name
30# of the anti-quoted C file. We can simply compile this output to get
31# our final program.
32main: main_pp_inferred.c
33	$(CC) $(CFLAGS) -o $@ $^
34
35run:
36	$(CC) $(CFLAGS) main_pp_inferred.c -o main
37
38# This is how we get cogent to generate a C file based on our
39# anti-quoted C and cogent source.
40#
41# --infer-c-funcs tells cogent where the anti-quoted C comes from.
42# -ogenerated tells cogent to output the C generated from the cogent
43#     source into a pair of files called generated.c and generated.h
44# -g telss cogent to generate C code from the cogent source
45main_pp_inferred.c: main.ac test-dargent.cogent
46	cogent \
47		${COGENTFLAGS} \
48		--infer-c-funcs=main.ac \
49		--ext-types=types.cfg \
50		--entry-funcs=entrypoints.cfg \
51		-ogenerated \
52		-g test-dargent.cogent
53
54