Some improvements to Linux build scripts.
[CodeSign.git] / Makefile
bloba7a63760e6f1f28ea708a810b3833caedb39946d
1 SHELL := bash
3 # ---------------------------------------------------------------------------
4 # FLAGS
5 # ---------------------------------------------------------------------------
7 MACHINE := $(shell $(CC) -dumpmachine)
8 ifeq ($(MACHINE),$(filter x86_64-%,$(MACHINE)))
9 MYCPU := x64
10 MARCH := x86-64
11 MTUNE := znver3
12 else
13 MYCPU := x86
14 MARCH := i486
15 MTUNE := intel
16 endif
18 CFLAGS = -march=$(MARCH) -mtune=$(MTUNE) -Os -DNDEBUG -Wall -flto -Ideps/$(MYCPU)/include
19 LDFLAGS = -Ldeps/$(MYCPU)/lib -static -Wl,--strip-all -Wl,--trace
20 LIBS = -lcrypto
22 ifeq ($(MACHINE),$(filter %-mingw32,$(MACHINE)))
23 SUFFIX = .exe
24 LDFLAGS += -municode
25 endif
27 ifneq ($(XCFLAGS),)
28 CFLAGS += $(XCFLAGS)
29 endif
30 ifneq ($(XLDFLAGS),)
31 LDFLAGS += $(XLDFLAGS)
32 endif
33 ifneq ($(XLIBS),)
34 LIBS += $(XLIBS)
35 endif
37 # ---------------------------------------------------------------------------
38 # RULES
39 # ---------------------------------------------------------------------------
41 .PHONY: all keygen sign verify subdirs clean
43 all: keygen sign verify
45 keygen: subdirs src/.magic.h rsrc
46 $(CC) $(CFLAGS) $(LDFLAGS) -o bin/codesign_keygen$(SUFFIX) src/codesign_keygen.c src/common.c obj/version_keygen.o $(LIBS)
48 sign: subdirs src/.magic.h
49 $(CC) $(CFLAGS) $(LDFLAGS) -o bin/codesign_sign$(SUFFIX) src/codesign_sign.c src/common.c obj/version_sign.o $(LIBS)
51 verify: subdirs src/.magic.h rsrc
52 $(CC) $(CFLAGS) -UEMBED_PUBKEY $(LDFLAGS) -o bin/codesign_verify$(SUFFIX) src/codesign_verify.c src/common.c obj/version_verify.o $(LIBS)
53 $(CC) $(CFLAGS) -DEMBED_PUBKEY $(LDFLAGS) -o bin/codesign_verifz$(SUFFIX) src/codesign_verify.c src/common.c obj/version_verify.o $(LIBS)
55 src/.magic.h:
56 str=$$(tr -dc '0-9A-F' < /dev/urandom | head -c 26); \
57 printf 'static const unsigned char MAGIC_NMBR[] = { ' > $@; \
58 for i in {0..12}; do \
59 [ $$i -gt 0 ] && printf ', '; \
60 printf '0x%s' $${str:((2*i)):2}; \
61 done >> $@; \
62 printf ' };\n' >> $@
64 rsrc: subdirs
65 ifeq ($(MACHINE),$(filter %-mingw32,$(MACHINE)))
66 windres -DAPP="Key Generator ($(MYCPU))" -DNAME=keygen -o obj/version_keygen.o res/version.rc
67 windres -DAPP="Signer ($(MYCPU))" -DNAME=sign -o obj/version_sign.o res/version.rc
68 windres -DAPP="Verifier ($(MYCPU))" -DNAME=verify -o obj/version_verify.o res/version.rc
69 else
70 $(CC) -o obj/version_keygen.o -xc -c - < /dev/null
71 $(CC) -o obj/version_sign.o -xc -c - < /dev/null
72 $(CC) -o obj/version_verify.o -xc -c - < /dev/null
73 endif
75 subdirs: deps/$(MYCPU)/lib/libcrypto.a deps/$(MYCPU)/lib/libssl.a
76 @mkdir -p bin obj
78 clean:
79 rm -rf bin obj
80 rm -f src/.magic.h