docs: fix simple typo, embeded -> embedded
[sha1collisiondetection.git] / Makefile
blobaa2f0c1f0b580e558f759cf40afba3f9e2f7cec7
1 ##
2 ## Copyright 2017 Marc Stevens <marc@marc-stevens.nl>, Dan Shumow (danshu@microsoft.com)
3 ## Distributed under the MIT Software License.
4 ## See accompanying file LICENSE.txt or copy at
5 ## https://opensource.org/licenses/MIT
6 ##
8 # dynamic library compatibility
9 # 1. If the library source code has changed at all since the last update,
10 # then increment revision (‘c:r:a’ becomes ‘c:r+1:a’).
11 # 2. If any interfaces have been added, removed, or changed since the last update,
12 # increment current, and set revision to 0.
13 # 3. If any interfaces have been added since the last public release, then increment age.
14 # 4. If any interfaces have been removed or changed since the last public release,
15 # then set age to 0.
16 LIBCOMPAT=1:0:0
18 PREFIX ?= /usr/local
19 BINDIR=$(PREFIX)/bin
20 LIBDIR=$(PREFIX)/lib
21 INCLUDEDIR=$(PREFIX)/include/sha1dc
23 CC ?= gcc
24 LD ?= gcc
25 CC_DEP ?= $(CC)
27 ifeq ($(shell uname),Darwin)
28 LIBTOOL ?= glibtool
29 INSTALL ?= install
30 else
31 LIBTOOL ?= libtool
32 INSTALL ?= install
33 endif
36 CFLAGS=-O2 -Wall -Werror -Wextra -pedantic -std=c90 -Ilib
37 LDFLAGS=
39 LT_CC:=$(LIBTOOL) --tag=CC --mode=compile $(CC)
40 LT_CC_DEP:=$(CC)
41 LT_LD:=$(LIBTOOL) --tag=CC --mode=link $(CC)
42 LT_INSTALL:=$(LIBTOOL) --tag=CC --mode=install $(INSTALL)
44 MKDIR=mkdir -p
46 ifneq (, $(shell which $(LIBTOOL) 2>/dev/null ))
47 CC:=$(LT_CC)
48 CC_DEP:=$(LT_CC_DEP)
49 LD:=$(LT_LD)
50 LDLIB:=$(LT_LD)
51 LIB_EXT:=la
52 else
53 LIB_EXT:=a
54 LD:=$(CC)
55 LT_INSTALL:=$(INSTALL)
56 endif
58 CFLAGS+=$(TARGETCFLAGS)
59 LDFLAGS+=$(TARGETLDFLAGS)
62 LIB_DIR=lib
63 LIB_DEP_DIR=dep_lib
64 LIB_OBJ_DIR=obj_lib
65 SRC_DIR=src
66 SRC_DEP_DIR=dep_src
67 SRC_OBJ_DIR=obj_src
69 H_DEP:=$(shell find . -type f -name "*.h")
70 FS_LIB=$(wildcard $(LIB_DIR)/*.c)
71 FS_SRC=$(wildcard $(SRC_DIR)/*.c)
72 FS_OBJ_LIB=$(FS_LIB:$(LIB_DIR)/%.c=$(LIB_OBJ_DIR)/%.lo)
73 FS_OBJ_SRC=$(FS_SRC:$(SRC_DIR)/%.c=$(SRC_OBJ_DIR)/%.lo)
74 FS_OBJ=$(FS_OBJ_SRC) $(FS_OBJ_LIB)
75 FS_DEP_LIB=$(FS_LIB:$(LIB_DIR)/%.c=$(LIB_DEP_DIR)/%.d)
76 FS_DEP_SRC=$(FS_SRC:$(SRC_DIR)/%.c=$(SRC_DEP_DIR)/%.d)
77 FS_DEP=$(FS_DEP_SRC) $(FS_DEP_LIB)
79 .SUFFIXES: .c .d
81 .PHONY: all
82 all: library tools
84 .PHONY: install
85 install: all
86 $(LT_INSTALL) -d $(LIBDIR) $(BINDIR) $(INCLUDEDIR)
87 $(LT_INSTALL) bin/libsha1detectcoll.$(LIB_EXT) $(LIBDIR)/libsha1detectcoll.$(LIB_EXT)
88 $(LT_INSTALL) lib/sha1.h $(INCLUDEDIR)/sha1.h
89 $(LT_INSTALL) bin/sha1dcsum $(BINDIR)/sha1dcsum
90 $(LT_INSTALL) bin/sha1dcsum_partialcoll $(BINDIR)/sha1dcsum_partialcoll
92 .PHONY: uninstall
93 uninstall:
94 -$(RM) $(BINDIR)/sha1dcsum
95 -$(RM) $(BINDIR)/sha1dcsum_partialcoll
96 -$(RM) $(INCLUDEDIR)/sha1.h
97 -$(RM) $(LIBDIR)/libsha1detectcoll.$(LIB_EXT)
99 .PHONY: clean
100 clean:
101 -find . -type f -name '*.a' -print -delete
102 -find . -type f -name '*.d' -print -delete
103 -find . -type f -name '*.o' -print -delete
104 -find . -type f -name '*.la' -print -delete
105 -find . -type f -name '*.lo' -print -delete
106 -find . -type f -name '*.so' -print -delete
107 -find . -type d -name '.libs' -print | xargs rm -rv
108 -rm -rf bin
110 .PHONY: test
111 test: tools
112 test e98a60b463a6868a6ce351ab0166c0af0c8c4721 != `bin/sha1dcsum test/sha1_reducedsha_coll.bin | cut -d' ' -f1` || (echo "\nError: Compiled for incorrect endianness" && false)
113 test a56374e1cf4c3746499bc7c0acb39498ad2ee185 = `bin/sha1dcsum test/sha1_reducedsha_coll.bin | cut -d' ' -f1`
114 test 16e96b70000dd1e7c85b8368ee197754400e58ec = `bin/sha1dcsum test/shattered-1.pdf | cut -d' ' -f1`
115 test e1761773e6a35916d99f891b77663e6405313587 = `bin/sha1dcsum test/shattered-2.pdf | cut -d' ' -f1`
116 test dd39885a2a5d8f59030b451e00cb45da9f9d3828 = `bin/sha1dcsum_partialcoll test/sha1_reducedsha_coll.bin | cut -d' ' -f1`
117 test d3a1d09969c3b57113fd17b23e01dd3de74a99bb = `bin/sha1dcsum_partialcoll test/shattered-1.pdf | cut -d' ' -f1`
118 test 92246b0b718f4c704d37bb025717cbc66babf102 = `bin/sha1dcsum_partialcoll test/shattered-2.pdf | cut -d' ' -f1`
119 bin/sha1dcsum test/*
120 bin/sha1dcsum_partialcoll test/*
122 .PHONY: check
123 check: test
125 .PHONY: tools
126 tools: sha1dcsum sha1dcsum_partialcoll
128 .PHONY: sha1dcsum
129 sha1dcsum: bin/sha1dcsum
131 .PHONY: sha1dcsum_partialcoll
132 sha1dcsum_partialcoll: bin/sha1dcsum_partialcoll
135 .PHONY: library
136 library: bin/libsha1detectcoll.$(LIB_EXT)
138 bin/libsha1detectcoll.la: $(FS_OBJ_LIB)
139 $(MKDIR) $(shell dirname $@) && $(LDLIB) $(LDFLAGS) $(FS_OBJ_LIB) -rpath $(LIBDIR) -version-info $(LIBCOMPAT) -o bin/libsha1detectcoll.la
141 bin/libsha1detectcoll.a: $(FS_OBJ_LIB)
142 $(MKDIR) $(shell dirname $@) && $(AR) cru bin/libsha1detectcoll.a $(FS_OBJ_LIB)
144 bin/sha1dcsum: $(FS_OBJ_SRC) bin/libsha1detectcoll.$(LIB_EXT)
145 $(LD) $(LDFLAGS) $(FS_OBJ_SRC) -Lbin -lsha1detectcoll -o bin/sha1dcsum
147 bin/sha1dcsum_partialcoll: $(FS_OBJ_SRC) bin/libsha1detectcoll.$(LIB_EXT)
148 $(LD) $(LDFLAGS) $(FS_OBJ_SRC) -Lbin -lsha1detectcoll -o bin/sha1dcsum_partialcoll
151 $(SRC_DEP_DIR)/%.d: $(SRC_DIR)/%.c
152 $(MKDIR) $(shell dirname $@) && $(CC_DEP) $(CFLAGS) -M -MF $@ $<
154 $(SRC_OBJ_DIR)/%.lo ${SRC_OBJ_DIR}/%.o: ${SRC_DIR}/%.c ${SRC_DEP_DIR}/%.d $(H_DEP)
155 $(MKDIR) $(shell dirname $@) && $(CC) $(CFLAGS) -o $@ -c $<
158 $(LIB_DEP_DIR)/%.d: $(LIB_DIR)/%.c
159 $(MKDIR) $(shell dirname $@) && $(CC_DEP) $(CFLAGS) -M -MF $@ $<
161 $(LIB_OBJ_DIR)/%.lo $(LIB_OBJ_DIR)/%.o: $(LIB_DIR)/%.c $(LIB_DEP_DIR)/%.d $(H_DEP)
162 $(MKDIR) $(shell dirname $@) && $(CC) $(CFLAGS) -o $@ -c $<
164 -include $(FS_DEP)