summary refs log tree commit diff
path: root/www/text.causal.agency/001-make.7
blob: 51a702cf36067a62f3fd5c3dc43fea065fe92435 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
.Dd September 17, 2018
.Dt MAKE 7
.Os "Causal Agency"
.
.Sh NAME
.Nm Using Make
.Nd writing less Makefile
.
.Sh DESCRIPTION
Let's talk about
.Xr make 1 .
I think an important thing to know about
.Xr make 1
is that you don't need to write a
.Pa Makefile
to use it.
There are default rules
for C, C++ and probably Fortran.
To build
.Pa foo
from
.Pa foo.c ,
just run:
.
.Pp
.Dl make foo
.
.Pp
The default rule for C files uses the
.Ev CFLAGS
variable,
so you can set that in the environment
to pass flags to the C compiler:
.
.Pp
.Dl CFLAGS=-Wall make foo
.
.Pp
It also uses
.Ev LDLIBS
for linking,
so you can add libraries with:
.
.Pp
.Dl LDLIBS=-lcurses make foo
.
.Pp
Obviously writing this every time
would become tedious,
so it might be time to write a
.Pa Makefile .
But it really doesn't need much:
.
.Bd -literal -offset indent
CFLAGS += -Wall -Wextra
LDLIBS = -lcurses

foo:
.Ed
.
.Pp
Assigning
.Ev CFLAGS
with
.Ql +=
preserves the system default
or anything passed in the environment.
Declaring
.Pa foo
as the first rule
makes it the default when
.Ql make
is run without a target.
Note that the rule doesn't need a definition;
the default will still be used.
.
.Pp
If
.Pa foo
is built from serveral source files,
unfortunately a rule definition is required:
.
.Bd -literal -offset indent
OBJS = foo.o bar.o baz.o

foo: $(OBJS)
	$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@
.Ed
.
.Pp
This rule uses
.Ev LDFLAGS
for passing linker flags,
which is what the default rule does.
The
.Ql $@
variable here expands to
.Ql foo ,
so this rule can be copied easily
for other binary targets.
.
.Pp
If some sources depend on a header file,
they can be automatically rebuilt
when the header changes
by declaring a dependency rule:
.
.Pp
.Dl foo.o bar.o: foo.h
.
.Pp
Note that several files can appear
either side of the
.Ql ":" .
.
.Pp
Lastly,
it's always nice to add a
.Cm clean
target:
.
.Bd -literal -offset indent
clean:
	rm -f $(OBJS) foo
.Ed
.
.Pp
I hope this helps getting started with
.Xr make 1
without writing too much
.Pa Makefile !
.
.Sh EXAMPLES
The example
.Pa Makefile
in its entirety:
.
.Bd -literal -offset indent
CFLAGS += -Wall -Wextra
LDLIBS = -lcurses
OBJS = foo.o bar.o baz.o

foo: $(OBJS)
	$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $@

foo.o bar.o: foo.h

clean:
	rm -f $(OBJS) foo
.Ed
.
.Sh AUTHORS
.An Mt june@causal.agency
.
.Pp
This document is produced from
.Xr mdoc 7
source available from
.Lk https://code.causal.agency/june/src/src/branch/master/www/text.causal.agency "Code Toilet"
font size to 12June McEnroe 11 is what I use on macOS, but I feel like my eyes are working harder here. 2021-02-07Fully configure and rebind cwmJune McEnroe This is sort of a mix of trying to emulate macOS somewhat for my muscle memory and just rebinding some of the cwm defaults to use 4- rather than M-. 2021-02-07Add BintiJune McEnroe 2021-02-07Finish configuring xtermJune McEnroe 2021-02-06Enable tapping, reverse scroll, set scaling in wsconsctlJune McEnroe 2021-02-06Set root window to black on purple snowJune McEnroe 2021-02-06Add xmodmap configurationJune McEnroe 2021-02-06Add initial OpenBSD X configurationJune McEnroe cwm still needs a lot more rebinding, and I need to actually look at its other options. xterm definitely still needs some configuration, but I at least managed to get it to use a decent looking font. Very happy that OpenBSD includes Luxi Mono, which is what my usual font, Go Mono, is based on anyway. Still missing is xmodmap and such. 2021-02-06Add xterm output to schemeJune McEnroe