-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (116 loc) · 5.37 KB
/
Makefile
File metadata and controls
138 lines (116 loc) · 5.37 KB
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
CFLAGS = -Wall -Wextra -Wpedantic -O2 -std=c11
SRCS = main.c crypto.c password.c compat.c
# ---------------------------------------------------------------------------
# Native build (linux/amd64)
# ---------------------------------------------------------------------------
CC = gcc
LDFLAGS = -lssl -lcrypto -l:libargon2.so.1
TARGET = ccryp
OBJS = $(SRCS:.c=.o)
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
%.o: %.c crypto.h password.h compat.h
$(CC) $(CFLAGS) -c -o $@ $<
# ---------------------------------------------------------------------------
# Cross-compilation layout: dist/<os>/<arch>/ccryp[.exe]
# ---------------------------------------------------------------------------
DIST = dist
# ---------------------------------------------------------------------------
# Linux cross-compilation
#
# Setup (Debian/Ubuntu/Kali):
# sudo dpkg --add-architecture arm64
# sudo dpkg --add-architecture armhf
# sudo apt update
# sudo apt install \
# gcc-aarch64-linux-gnu gcc-arm-linux-gnueabihf \
# libssl-dev:arm64 libssl-dev:armhf \
# libargon2-dev:arm64 libargon2-dev:armhf
# ---------------------------------------------------------------------------
LINUX_LDFLAGS = -lssl -lcrypto -l:libargon2.so.1
linux-amd64: $(DIST)/linux/amd64/ccryp
linux-arm64: $(DIST)/linux/arm64/ccryp
linux-arm: $(DIST)/linux/arm/ccryp
$(DIST)/linux/amd64/ccryp: $(SRCS) crypto.h password.h compat.h | $(DIST)/linux/amd64
gcc $(CFLAGS) -o $@ $(SRCS) $(LINUX_LDFLAGS)
$(DIST)/linux/arm64/ccryp: $(SRCS) crypto.h password.h compat.h | $(DIST)/linux/arm64
aarch64-linux-gnu-gcc $(CFLAGS) -o $@ $(SRCS) $(LINUX_LDFLAGS)
$(DIST)/linux/arm/ccryp: $(SRCS) crypto.h password.h compat.h | $(DIST)/linux/arm
arm-linux-gnueabihf-gcc $(CFLAGS) -o $@ $(SRCS) $(LINUX_LDFLAGS)
# ---------------------------------------------------------------------------
# Windows cross-compilation (mingw-w64)
#
# Setup:
# sudo apt install gcc-mingw-w64-x86-64 gcc-mingw-w64-aarch64
#
# You must also provide cross-compiled OpenSSL and argon2 for Windows.
# Point WIN_LIBS to a sysroot containing include/ and lib/:
#
# make windows-amd64 WIN_LIBS=/path/to/windows-libs
#
# To build OpenSSL for Windows:
# git clone https://github.com/openssl/openssl && cd openssl
# ./Configure mingw64 --cross-compile-prefix=x86_64-w64-mingw32- \
# --prefix=/path/to/windows-libs no-shared
# make && make install
#
# To build argon2 for Windows:
# git clone https://github.com/P-H-C/phc-winner-argon2 && cd phc-winner-argon2
# make CC=x86_64-w64-mingw32-gcc LIBRARY_LENGTH_LIMIT=1 \
# PREFIX=/path/to/windows-libs install
# ---------------------------------------------------------------------------
WIN_LIBS ?= /usr/x86_64-w64-mingw32
WIN_CFLAGS = $(CFLAGS) -I$(WIN_LIBS)/include
WIN_LDFLAGS = -L$(WIN_LIBS)/lib -lssl -lcrypto -largon2 \
-lws2_32 -lgdi32 -lcrypt32 -lbcrypt -static-libgcc
windows-amd64: $(DIST)/windows/amd64/ccryp.exe
windows-arm64: $(DIST)/windows/arm64/ccryp.exe
$(DIST)/windows/amd64/ccryp.exe: $(SRCS) crypto.h password.h compat.h | $(DIST)/windows/amd64
x86_64-w64-mingw32-gcc $(WIN_CFLAGS) -o $@ $(SRCS) $(WIN_LDFLAGS)
$(DIST)/windows/arm64/ccryp.exe: $(SRCS) crypto.h password.h compat.h | $(DIST)/windows/arm64
aarch64-w64-mingw32-gcc $(WIN_CFLAGS) -o $@ $(SRCS) $(WIN_LDFLAGS)
# ---------------------------------------------------------------------------
# macOS cross-compilation (osxcross)
#
# Setup:
# 1. Clone osxcross: https://github.com/tpoechtrager/osxcross
# 2. Obtain a macOS SDK (e.g. MacOSX13.sdk.tar.xz) and place it in tarballs/
# 3. Build: SDK_VERSION=13 ./build.sh
# 4. Add <osxcross>/target/bin to PATH
#
# Point MAC_LIBS to a sysroot with macOS OpenSSL and argon2 (e.g. from Homebrew
# extracted via a macOS machine, or cross-compiled with osxcross toolchain).
#
# make macos-amd64 OSXCROSS_TARGET=x86_64-apple-darwin22 MAC_LIBS=/path/to/macos-libs
# make macos-arm64 OSXCROSS_TARGET=arm64-apple-darwin22 MAC_LIBS=/path/to/macos-libs
# ---------------------------------------------------------------------------
OSXCROSS_TARGET ?= x86_64-apple-darwin22
MAC_LIBS ?= /opt/macos-libs
MAC_CFLAGS = $(CFLAGS) -I$(MAC_LIBS)/include
MAC_LDFLAGS = -L$(MAC_LIBS)/lib -lssl -lcrypto -largon2
macos-amd64: $(DIST)/macos/amd64/ccryp
macos-arm64: $(DIST)/macos/arm64/ccryp
$(DIST)/macos/amd64/ccryp: $(SRCS) crypto.h password.h compat.h | $(DIST)/macos/amd64
x86_64-apple-darwin22-clang $(MAC_CFLAGS) -o $@ $(SRCS) $(MAC_LDFLAGS)
$(DIST)/macos/arm64/ccryp: $(SRCS) crypto.h password.h compat.h | $(DIST)/macos/arm64
arm64-apple-darwin22-clang $(MAC_CFLAGS) -o $@ $(SRCS) $(MAC_LDFLAGS)
# ---------------------------------------------------------------------------
# Convenience targets
# ---------------------------------------------------------------------------
all-linux: linux-amd64 linux-arm64 linux-arm
all-windows: windows-amd64 windows-arm64
all-macos: macos-amd64 macos-arm64
all-dist: all-linux all-windows all-macos
# Create output directories
$(DIST)/linux/amd64 $(DIST)/linux/arm64 $(DIST)/linux/arm \
$(DIST)/windows/amd64 $(DIST)/windows/arm64 \
$(DIST)/macos/amd64 $(DIST)/macos/arm64:
mkdir -p $@
clean:
rm -f $(OBJS) $(TARGET)
rm -rf $(DIST)
.PHONY: all linux-amd64 linux-arm64 linux-arm \
windows-amd64 windows-arm64 \
macos-amd64 macos-arm64 \
all-linux all-windows all-macos all-dist clean