-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
128 lines (107 loc) · 4.02 KB
/
Makefile
File metadata and controls
128 lines (107 loc) · 4.02 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
# default MingW path for Qt 6.3.x:
WIN_MINGW_BIN_PATH=C:\\Qt\\Tools\\mingw1310_64\\bin
LIB_VERSION=2025.10.04a
LIBNAME=libdither
SRCDIR=src/$(LIBNAME)
OBJDIR=build
DISTDIR=dist
SRC=libdither.c ditherimage.c random.c gamma.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 \
color_bytepalette.c color_floatcolor.c color_models.c color_quant_mediancut.c color_cachedpalette.c \
color_colorimage.c color_floatpalette.c color_bytecolor.c color_quant_wu.c color_quant_kdtree.c \
kdtree/kdtree.c tetrapal/tetrapal.c
OBJ=$(patsubst %.c, $(OBJDIR)/%.o, $(SRC))
OBJFILES=$(patsubst %.c, %.o, $(SRC))
CFLAGS=-std=c11 -Wall -Wextra -Wconversion -Wshadow -Wstrict-overflow -Wformat=2 -Wundef -fno-common -O3 -Os \
-Wpedantic -pedantic -Werror -Wno-int-to-pointer-cast -D"LIB_VERSION=\"$(LIB_VERSION)\""
ifdef OS # Windows:
define fn_mkdir
@if not exist "$(1)" mkdir "$(1)"
endef
SHELL=cmd
CP=copy
DELTREE=rd /s /q
CC=SET PATH=$(WIN_MINGW_BIN_PATH);%PATH% && gcc
LIBEXT=dll
SEP=\\
DEMOCMD=cd dist && demo
else # Unix based platforms
define fn_mkdir
@mkdir -p "$(1)"
endef
CP=cp
DELTREE=rm -Rf
SEP=/
DEMOCMD=cd dist && ./demo
ifeq ($(shell uname), Darwin) # macOS
CC=clang
LIBEXT=dylib
else # other Unix / Linux
CC=gcc
LIBEXT=so
UNIXFLAGS=-Wl,-R.
CFLAGS+=-Wno-type-limits
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 (run vcvar64.bat first!)"
@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))
-$(call fn_mkdir,$(OBJDIR)/tetrapal)
-$(call fn_mkdir,$(OBJDIR)/kdtree)
$(CC) $(CFLAGS) $(TARGETARCH) -c -fPIC -c $< -o $@
.PHONY: libdither_msvc
libdither_msvc:
@echo Make sure to run vcvars64.bat (for Visual Studio 2022) or this target will fail...
msbuild libdither.vcxproj /p:Configuration=Release
# building without msbuild:
# cd build && cl.exe ..\\src\\libdither\\*.c ..\\src\\libdither\\tetrapal\\*.c ..\\src\\libdither\\kdtree\\*.c /LD /DLL /Fe: libdither.dll
# cd build && cl.exe ..\\src\\demo\\demo.c ..\src\demo\lodepng.c libdither.lib /I..\\src\\libdither /Fe: demo.exe
.PHONY: demo_msvc
demo_msvc:
msbuild demo.vcxproj /p:Configuration=Release
.PHONY: demo
demo:
cd dist && $(CC) $(UNIXFLAGS) -I../src/libdither -L. ../src/demo/demo.c ../src/demo/lodepng.c -ldither -lm -o demo
$(CP) src$(SEP)demo$(SEP)*.png $(DISTDIR)
$(CP) src$(SEP)demo$(SEP)blue_noise.bmp $(DISTDIR)
.PHONY: demo_run
demo_run:
$(DEMOCMD)
.PHONY: demo_run_msvc
demo_run_msvc:
cd dist\Release && demo
.PHONY: clean
clean:
-@$(DELTREE) $(DISTDIR)
-@$(DELTREE) $(OBJDIR)