summaryrefslogtreecommitdiff
path: root/GNUmakefile
blob: ba9f396544236450a57a8e40e7468d03e2961042 (plain)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#    Never export any environment variables, unless exported explicitly.
#    This keeps the environment small and surprises low.
#    Make sure that utilities have no hidden dependency on locales.
#    For example, date(1) output depends on LANG.
unexport                  # Never export to sub-makes.
unexport C_INCLUDE_PATH   # Remove from shell environment; confuses gcc.
export LANG   = C.UTF-8
export LC_ALL = C.UTF-8

.DEFAULT_GOAL = install

TOP_LEVEL_TARGETS = lscp
TOP_LEVEL_TARGETS += txttopng
TOP_LEVEL_TARGETS += srctohex
TOP_LEVEL_TARGETS += hextobdf
TOP_LEVEL_TARGETS += gallant.bdf
TOP_LEVEL_TARGETS += gallant.fnt


.PHONY: all
all: $(TOP_LEVEL_TARGETS)

lscp: lscp.o

srctohex: srctohex.o

hextobdf: hextobdf.o

tsttopng: tsttopng.o

gallant.bdf: gallant.hex
	./hextobdf < $^ > $@

gallant.hex: gallant.src
	./srctohex < $^ > $@

gallant.fnt: gallant.hex
	  vtfontcvt -v -o $@ $^

.PHONY: install
install: gallant.bdf gallant.fnt
	cp gallant.bdf ~/.fonts
	cd ~/.fonts && mkfontdir && xset fp rehash
	if test $$(uname -s) = FreeBSD; then \
	  if test -w /dev/ttyv7; then \
	    vidcontrol -f gallant.fnt < /dev/ttyv7; \
	  fi; \
	fi

.PHONY: images
images:
	./make-images.sh

# Find un-sorted codepoints in gallant.src.
#
.PHONY: check
check:
	@grep ^STARTCHAR gallant.src | sort -c

# FreeBSD: Libs and <uniname.h> are in devel/libunistring
CC = cc -std=c99
APP_WARNS  += -Werror
APP_WARNS  += -Wall
APP_WARNS  += -Wextra
APP_WARNS  += -Wcast-align
APP_WARNS  += -Wcast-qual
APP_WARNS  += -Wfloat-equal
APP_WARNS  += -Wformat=2
APP_WARNS  += -Wno-format-nonliteral
APP_WARNS  += -Winline
APP_WARNS  += -Wstrict-prototypes
APP_WARNS  += -Wmissing-prototypes
APP_WARNS  += -Wno-unused
APP_WARNS  += -Wold-style-definition
APP_WARNS  += -Wpedantic
APP_WARNS  += -Wpointer-arith
APP_WARNS  += -Wredundant-decls
APP_WARNS  += -Wshadow
APP_WARNS  += -Wsign-conversion
APP_WARNS  += -Wswitch-enum
APP_WARNS  += -Wuninitialized
APP_WARNS  += -Wvla
APP_WARNS  += -Wwrite-strings
APP_WARNS  += -Wignored-qualifiers
APP_WARNS  += -Wmissing-field-initializers

APP_SOURCE_INCDIRS = -I /usr/local/include
APP_LIBDIRS = -L /usr/local/lib

lscp: lscp.o
	$(CC) -o $@ $(APP_LIBDIRS) -luninameslist -lunistring $^

hextobdf: hextobdf.o
	$(CC) -o $@ $^

srctohex: srctohex.o
	$(CC) -o $@ $^

txttopng: txttopng.o
	$(CC) -o $@ $(APP_LIBDIRS) -lpng $^

lint: txttopng.c lscp.c hextobdf.c srctohex.c
	@for c in $^; do flexelint lint.lnt $$c; done

# X11 in x.out:
# BDF Error on line 114938: char 'U+10000' has encoding too large (65536)

################################################################################
#                           ____        _                                      #
#                          |  _ \ _   _| | ___  ___                            #
#                          | |_) | | | | |/ _ \/ __|                           #
#                          |  _ <| |_| | |  __/\__ \                           #
#                          |_| \_\\__,_|_|\___||___/                           #
#                                                                              #
#                        How to build stuff in general.                        #
################################################################################

#   Delete the match anything rules.
MAKEFLAGS += --no-builtin-rules

#   Clear the suffix list so no default rules are used.
.SUFFIXES:
.SUFFIXES: .asm .c .elf .i .o .p .s

#   How to compile a C source to an object file.
#
%.o: %.c
	$(CC) -c $(APP_CFLAGS) $(APP_WARNS) $(APP_SOURCE_INCDIRS) $(APP_MACROS) -o $@ $<

#   How to compile a C source to an assembler file.
#
%.s: %.c
	$(CC) -S $(APP_CFLAGS) $(APP_WARNS) $(APP_SOURCE_INCDIRS) $(APP_MACROS) -o $@ $<

#   How to pre-process a C source file with the compiler and save result in a *.i file.
#
%.i: %.c
	$(CC) -E $(APP_CFLAGS) $(APP_WARNS) $(APP_SOURCE_INCDIRS) $(APP_MACROS) -o $@ $<

#   How to pre-process a C source file with FlexeLint and save result in a *.p file.
#
%.p: %.c
	$(FLINT) -p $(LNT) $(APP_INCDIRS) $(APP_MACROS) $< > $@

#   How to preprocess with the compiler, without # linemarkers and indented.
#
%.pp: %.c
	@mkdir -p $(@D)
	$(CC) -E -P -DCOMPILING=1 $(APP_CFLAGS) $(APP_MACROS) $(APP_SOURCE_INCDIRS) $< | \
	gindent -st - \
	  --ignore-profile \
	  -T  int8_t -T  int16_t -T  int32_t -T  int64_t -T float32_t \
	  -T uint8_t -T uint16_t -T uint32_t -T uint64_t -T float64_t \
	  --k-and-r-style \
	  --ignore-newlines \
	  --braces-on-func-def-line \
	  --dont-line-up-parentheses \
	  --continuation-indentation1 \
	  --indent-level1 \
	  --line-length9999 \
	  --no-tabs \
	  --tab-size1 > $@

#   How to extract functions from *.pp file.
#
%.func: %.pp
	awk '/^[[:alpha:]_].*) {$$/,/^}$$/' $< > $@

################################################################################
#        _   _      _                   _____                    _             #
#       | | | | ___| |_ __   ___ _ __  |_   _|_ _ _ __ __ _  ___| |_ ___       #
#       | |_| |/ _ \ | '_ \ / _ \ '__|   | |/ _` | '__/ _` |/ _ \ __/ __|      #
#       |  _  |  __/ | |_) |  __/ |      | | (_| | | | (_| |  __/ |_\__ \      #
#       |_| |_|\___|_| .__/ \___|_|      |_|\__,_|_|  \__, |\___|\__|___/      #
#                    |_|                              |___/                    #
#                                                                              #
################################################################################

#------------------------------------------------------------------------------#
#                                    Clean                                     #
#------------------------------------------------------------------------------#

.PHONY: clean
clean:
	git clean -fdx

#------------------------------------------------------------------------------#
#                          Tags - Create tags for vi                           #
#------------------------------------------------------------------------------#

# Create tags from the actual files compiled, and the actually included
# headers. Examine the preprocessor output's '# LINE "FILE"' directives.

#PREPROCESSED = $(APP_C_SOURCE:.c=.i)
PREPROCESSED = lscp.i txttopng.i hextobdf.i srctohex.i

# make tags: create vi tags file.
#
CTAGS = jexctags
.PHONY: tags
tags: $(PREPROCESSED)
	@awk '/^# / {print $$3}' $^ | sort -u | grep -v \< | tr -d \" > list
	@$(CTAGS) -L list -f $@ \
	         --regex-c='/\<(REQ_[[:upper:]_]*([[:digit:]_]{7}))\>/\2/'
	@$(CTAGS) -L list -f $@.p --language-force=c --c-kinds=p
	@rm -f list

# make typenames: output list of C language typedef names used in source code.
#                 Useful for .indent.pro.
#
.PHONY: typenames
typenames: $(PREPROCESSED)
	@awk '/^# / {print $$3}' $^ | sort -u | grep -v \< | tr -d \" | \
	$(CTAGS) -L - -f - --language-force=c --c-kinds=t | \
	cut -f 1 | sort -u

APP_SYSTEM_INCDIRS = -I/usr/include -I/usr/local/include
# make tooltips: create tooltips.vim for vim to source and show macros.
#
.PHONY: tooltips tooltips.vim
tooltips: tooltips.vim
tooltips.vim: lscp.c txttopng.c
	{ \
	printf "function! MyBalloonExpr()\n"; \
	printf "  let macros = {\n"; \
	$(CC) -E -dM $(APP_SOURCE_INCDIRS) $(APP_SYSTEM_INCDIRS) $(APP_MACROS) $^ | \
	sort -uk 1,2 | \
	sed -e 's,\\,\\\\,g; s,",\\",g' | \
	while read -r define macro repl; do \
	  case $$macro in \
	  (HASH) printf "\\ 'HASH':\"HASH\\\\n0x12345678u\",\n";; \
	  (*) printf "\\ '%s':\"%s\\\\n%s\",\n" "$${macro%%(*}" "$$macro" "$$repl"; \
	  esac; \
	done; \
	printf "\\ }\n"; \
	printf "  return get(macros, v:beval_text, '')\n"; \
	printf "endfunction\n"; \
	printf "set balloonexpr=MyBalloonExpr()\n"; \
	printf "set ballooneval\n"; \
	printf "set balloonevalterm\n"; \
	} > $@

# make types.vim: create syntax coloring info for types in the code.
#
types.vim: $(PREPROCESSED)
	@$(CTAGS) --language-force=c --c-kinds=stu -o- $^ | \
	  awk 'BEGIN {print "autocmd Syntax * syntax keyword Type"} \
	             {print "\\ " $$1}' | uniq > $@


# vim: set syntax=make noexpandtab tabstop=8 sw=2: