1all: bzip2.bc bzip2_from_bitcode test
2
3CLANG = $(shell which clang)
4ifeq ($(CLANG),)
5	CLANG = gclang
6endif
7
8./bzip2:
9	git clone git://sourceware.org/git/bzip2.git
10# the patch is to remove the hard coded "CC=gcc". Bad Julian. No biscuit.
11	patch bzip2/Makefile < patch.txt
12
13./bzip2/bzip2: bzip2
14	CC=gclang make -C bzip2
15
16./bzip2.bc: bzip2/bzip2
17	get-bc -o bzip2.bc bzip2/bzip2
18
19# to build an bitcode archive we do not use any additional flags; the '-m' flag writes the manifest (i.e. the ingredients)
20libbz2.bca:
21	get-bc -m -o libbz2.bca bzip2/libbz2.a
22
23# to build a module we just use the '-b' flag; the '-m' flag writes the manifest (i.e. the ingredients)
24libbz2.a.bc:
25	get-bc -m -b -o libbz2.a.bc bzip2/libbz2.a
26
27# groked this list from the manifests
28modules: bzip2/bzip2
29	cp ./bzip2/.bzip2.c.o.bc      bzip2.c.o.bc
30	cp ./bzip2/.blocksort.c.o.bc  blocksort.c.o.bc
31	cp ./bzip2/.huffman.c.o.bc    huffman.c.o.bc
32	cp ./bzip2/.crctable.c.o.bc   crctable.c.o.bc
33	cp ./bzip2/.randtable.c.o.bc  randtable.c.o.bc
34	cp ./bzip2/.compress.c.o.bc   compress.c.o.bc
35	cp ./bzip2/.decompress.c.o.bc decompress.c.o.bc
36	cp ./bzip2/.bzlib.c.o.bc      bzlib.c.o.bc
37
38
39# the override flag is necessary and is there to prevent any complaints about multiple definitions.
40bzip2_from_bitcode: bzip2.bc modules
41	${CLANG} bzip2.c.o.bc blocksort.c.o.bc huffman.c.o.bc crctable.c.o.bc randtable.c.o.bc compress.c.o.bc decompress.c.o.bc bzlib.c.o.bc -o bzip2_from_bitcode
42
43test: bzip2_from_bitcode
44	./bzip2_from_bitcode -1  < ./bzip2/sample1.ref > sample1.rb2
45	./bzip2_from_bitcode -2  < ./bzip2/sample2.ref > sample2.rb2
46	./bzip2_from_bitcode -3  < ./bzip2/sample3.ref > sample3.rb2
47	./bzip2_from_bitcode -d  < ./bzip2/sample1.bz2 > sample1.tst
48	./bzip2_from_bitcode -d  < ./bzip2/sample2.bz2 > sample2.tst
49	./bzip2_from_bitcode -ds < ./bzip2/sample3.bz2 > sample3.tst
50	cmp ./bzip2/sample1.bz2 sample1.rb2
51	cmp ./bzip2/sample2.bz2 sample2.rb2
52	cmp ./bzip2/sample3.bz2 sample3.rb2
53	cmp sample1.tst ./bzip2/sample1.ref
54	cmp sample2.tst ./bzip2/sample2.ref
55	cmp sample3.tst ./bzip2/sample3.ref
56
57clean:
58	rm -f *.bc *.bca *.manifest bzip2_from_bitcode *.rb2 *.tst bzip2_slashed
59	rm -rf slash_specialized
60	make -C bzip2 clean
61
62spotless: clean
63	rm -rf bzip2 bzip2_tests
64
65
66
67.PHONY: clean spotless modules
68