summaryrefslogtreecommitdiff
path: root/Makefile
blob: ccdd8f2e456177dc4d4ba2e352b4d13b17dcc152 (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
# Copyright (C) 2024 Aiden Gall
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

.POSIX:

.PHONY: all clean dist install format

include config.mk

SRC   = src/spirt.c src/util.c src/util_cl.c src/camera.c
CLSRC = src/cl/spirt.cl
HDR   = src/util.h src/util_cl.h src/camera.h

LL  = ${CLSRC:.cl=.ll}
SPV = ${CLSRC:.cl=.spv}

OBJ = ${SRC:.c=.o} ${CLSRC:.cl=.o}

all: spirt

src/util.o: config.mk
src/util_cl.o: config.mk src/util.h
src/camera.o: config.mk src/camera.h
src/spirt.o: config.mk src/util.h src/util_cl.h src/camera.h
src/cl/spirt.o: config.mk

spirt: ${OBJ}
	${CC} $(LDFLAGS) $^ $(LDLIBS) -o $@

%.o: %.c
	${CC} $(CFLAGS) -c -o $@ $<

%.o: %.spv
	objcopy ${OBJFLAGS} $< $@

%.spv: %.ll
	llvm-spirv $< -o $@

%.ll: %.cl
	clang -c ${CLFLAGS} $< -o $@

compile_commands.json: config.mk
	echo ${SRC} | \
		jq -nR "[ inputs | split(\" \").[] | { \
		directory:\".\", \
		command:(\"${CC} -c ${CFLAGS} \" + .), \
		file:. } ]" > $@

clean:
	rm -f spirt ${OBJ} ${LL} ${SPV}

dist: clean
	mkdir -p spirt-${VERSION}
	cp -R LICENSE Makefile config.mk src/ .clang-format spirt-${VERSION}
	tar -cf - spirt-${VERSION} | gzip > spirt-${VERSION}.tar.gz
	rm -rf spirt-${VERSION}

install: all
	mkdir -p ${DESTDIR}${PREFIX}/bin
	cp -f spirt ${DESTDIR}${PREFIX}/bin
	chmod 755 ${DESTDIR}${PREFIX}/bin/spirt

format:
	for src in ${SRC} ${HDR} ${CLSRC}; do clang-format -i "$$src"; done