-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
108 lines (91 loc) · 3.41 KB
/
Makefile
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
# default MingW path for Qt 6.3.x:
WIN_MINGW_BIN_PATH=C:\\Qt\\Tools\\mingw1120_64\\bin
LIB_VERSION=2022.25.08a
LIBNAME=libdither
SRCDIR=src/$(LIBNAME)
OBJDIR=build
DISTDIR=dist
SRC=libdither.c ditherimage.c random.c gamma.c hash.c queue.c dither_dbs.c dither_dotdiff.c \
dither_errordiff.c dither_kallebach.c dither_ordered.c dither_riemersma.c dither_threshold.c \
dither_varerrdiff.c dither_pattern.c dither_dotlippens.c dither_grid.c
OBJ=$(patsubst %.c, $(OBJDIR)/%.o, $(SRC))
OBJFILES=$(patsubst %.c, %.o, $(SRC))
CFLAGS=-std=c99 -Wall -Wextra -Wconversion -Wshadow -Wstrict-overflow -Wformat=2 \
-Wundef -fno-common -O2 -Os -Wpedantic -pedantic -Werror -Wno-sign-conversion \
-Wno-strict-prototypes -D"LIB_VERSION=\"$(LIB_VERSION)\""
ifdef OS # Windows:
define fn_mkdir
if not exist "$(1)" mkdir "$(1)"
endef
CP=copy
DELTREE=rd /s /q
CC=SET PATH=$(WIN_MINGW_BIN_PATH);%PATH% && gcc
LIBEXT=dll
SEP=\\
else # Unix based platforms
define fn_mkdir
@mkdir -p "$(1)"
endef
CP=cp
DELTREE=rm -Rf
SEP=/
ifeq ($(shell uname), Darwin) # macOS
CC=clang
LIBEXT=dylib
else # other Unix / Linux
CC=gcc
LIBEXT=so
UNIXFLAGS=-Wl,-R.
endif
endif
libdither: TARGETARCH=
libdither_x64: TARGETARCH=-target x86_64-apple-macos10.12
libdither_arm64: TARGETARCH=-target arm64-apple-macos11
.PHONY: all
all:
@echo "Targets:"
@echo "* libdither - build library for current platform (gcc/clang/MingW)"
@echo "* libdither_x64 - build macOS x86 library"
@echo "* libdither_arm64 - build macOS apple silicon library"
@echo "* libdither_universal - build universal macOS library"
@echo "* libdither_msvc - build using MSVC on Windows"
@echo "* demo - builds a small executable for the current platform to demo libdither's capabilities"
@echo "* clean"
$(LIBNAME)_universal:
make $(LIBNAME)_arm64
$(call fn_mkdir,$(DISTDIR)/arm64)
mv $(DISTDIR)/$(LIBNAME).$(LIBEXT) $(DISTDIR)/arm64/$(LIBNAME).$(LIBEXT)
-$(DELTREE) $(OBJDIR)
make $(LIBNAME)_x64
$(call fn_mkdir,$(DISTDIR)/x64)
mv $(DISTDIR)/$(LIBNAME).$(LIBEXT) $(DISTDIR)/x64/$(LIBNAME).$(LIBEXT)
cd $(DISTDIR) && lipo x64/$(LIBNAME).$(LIBEXT) arm64/$(LIBNAME).$(LIBEXT) -output $(LIBNAME).$(LIBEXT) -create
$(LIBNAME)_x64: $(LIBNAME)_build
$(LIBNAME)_arm64: $(LIBNAME)_build
$(LIBNAME): $(LIBNAME)_build
$(LIBNAME)_build: $(OBJDIR)/$(LIBNAME).$(LIBEXT)
$(call fn_mkdir,$(DISTDIR))
$(CP) $(OBJDIR)$(SEP)$(LIBNAME).$(LIBEXT) $(DISTDIR)$(SEP)$(LIBNAME).$(LIBEXT)
@echo "$(LIBNAME) build successfully $(TARGETARCH)"
$(OBJDIR)/$(LIBNAME).$(LIBEXT): $(OBJ)
cd $(OBJDIR) && $(CC) $(TARGETARCH) -shared $(OBJFILES) -fPIC -o $(LIBNAME).$(LIBEXT)
$(OBJDIR)/%.o: $(addprefix $(SRCDIR)/, %.c)
$(call fn_mkdir,$(OBJDIR))
$(CC) $(CFLAGS) $(TARGETARCH) -c -fPIC -c $< -o $@
libdither_msvc:
@echo Make sure to run vcvars64.bat or this target will fail...
$(call fn_mkdir,$(OBJDIR))
cd build && cl.exe ..\\src\\libdither\\*.c /LD /DLL /Fe: libdither.dll
cd build && cl.exe ..\\src\\demo\\demo.c ..\src\demo\bmp.c libdither.lib /I..\\src\\libdither /L. /Fe: demo.exe
$(call fn_mkdir,$(DISTDIR))
copy src\\demo\\*.bmp $(DISTDIR)
copy build\\demo.exe $(DISTDIR)
copy build\\libdither.dll $(DISTDIR)
demo: libdither
cd dist && $(CC) $(UNIXFLAGS) -I../src/libdither -L. ../src/demo/demo.c ../src/demo/bmp.c -ldither -lm -o demo
$(CP) src$(SEP)demo$(SEP)david.bmp $(DISTDIR)
$(CP) src$(SEP)demo$(SEP)blue_noise.bmp $(DISTDIR)
.PHONY: clean
clean:
-@$(DELTREE) $(DISTDIR)
-@$(DELTREE) $(OBJDIR)