forked from victorvde/jpeg2png
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
173 lines (148 loc) · 3.88 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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# Reset implicit rules as if using -r
.SUFFIXES:
# Reset implicit variables as if using -R
$(foreach var,$(filter-out .% MAKE% SUFFIXES,$(.VARIABLES)),\
$(if $(findstring $(origin $(var)),default),\
$(if $(filter undefine,$(.FEATURES)),\
$(eval undefine $(var)),\
$(eval $(var)=))))
# Build options
BUILTINS=1
PRAGMA_FP_CONTRACT=0
SIMD=1
OPENMP=1
DEBUG=0
PROFILE=0
SAVE_ASM=0
WINDOWS=0
# VARIABLES
CFLAGS+=-std=c11 -pedantic
CFLAGS+=-msse2 -mfpmath=sse
CFLAGS+=-g
WARN_FLAGS+=-Wall -Wextra -Winline -Wshadow
NO_WARN_FLAGS+=-w
ifeq ($(CC),)
CC=$(HOST)gcc
endif
ifeq ($(WINDRES),)
WINDRES=$(HOST)windres
endif
LIBS+=-ljpeg -lpng -lm -lz
OBJS+=jpeg2png.o utils.o jpeg.o png.o box.o compute.o logger.o progressbar.o fp_exceptions.o gopt/gopt.o ooura/dct.o
HOST=
EXE=
# Detect the environment to set compiler and flags
ifneq ($(MSYSTEM),)
ifeq ($(MSYSTEM),CLANG64)
CC = clang
BFLAGS += -fopenmp=libomp
LIBS += -ljpeg -lpng -lm -lz -lpsapi
else ifeq ($(MSYSTEM),CLANG32)
CC = clang
BFLAGS += -fopenmp=libomp
LIBS += -ljpeg -lpng -lm -lz -lpsapi
else ifeq ($(MSYSTEM),MINGW64)
CC = x86_64-w64-mingw32-gcc
else ifeq ($(MSYSTEM),MINGW32)
CC = i686-w64-mingw32-gcc
WINDRES = windres --target=pe-i386
endif
endif
# Apply specific flags when CC is clang
ifeq ($(CC),clang)
BFLAGS += -fopenmp=libomp
LIBS += -ljpeg -lpng -lm -lz -lpsapi
endif
ifeq ($(BUILTINS),1)
CFLAGS+=-DBUILTIN_UNREACHABLE -DBUILTIN_ASSUME_ALIGNED -DATTRIBUTE_UNUSED
endif
ifeq ($(PRAGMA_FP_CONTRACT),1)
CFLAGS+=-DPRAGMA_FP_CONTRACT
else # not supported by gcc
CFLAGS+=-ffp-contract=off
endif
ifeq ($(SIMD),1)
CFLAGS+=-DUSE_SIMD
endif
ifeq ($(OPENMP),1)
BFLAGS+=-fopenmp
endif
ifeq ($(DEBUG),1)
CFLAGS+=-Og -DDEBUG
else
CFLAGS+=-O3 -DNDEBUG
endif
ifeq ($(PROFILE),1)
BFLAGS+=-pg
endif
ifeq ($(WINDOWS),1)
# Set HOST based on environment if not already set
ifeq ($(HOST),)
ifeq ($(shell uname -s),Linux)
ifeq ($(shell uname -m),x86_64)
HOST=x86_64-w64-mingw32-
else
HOST=i686-w64-mingw32-
endif
else ifeq ($(shell uname -s),Darwin)
ifeq ($(shell uname -m),x86_64)
HOST=x86_64-w64-mingw32-
else
HOST=i686-w64-mingw32-
endif
else ifeq ($(findstring MINGW,$(shell uname -s)),MINGW)
ifeq ($(shell uname -m),x86_64)
HOST=x86_64-w64-mingw32-
else
HOST=i686-w64-mingw32-
endif
endif
endif
EXE=.exe
LDFLAGS+=-static -s
CFLAGS+=-mstackrealign
RES+=icon.rc.o
# Set WINDRES based on environment and architecture
ifeq ($(MSYSTEM),MINGW32)
WINDRES = windres --target=pe-i386
else ifeq ($(MSYSTEM),CLANG32)
WINDRES = windres --target=pe-i386
else ifeq ($(findstring MINGW,$(shell uname -s)),MINGW)
ifeq ($(HOST),i686-w64-mingw32-)
WINDRES = windres --target=pe-i386
else
WINDRES = windres
endif
else
ifeq ($(HOST),i686-w64-mingw32-)
WINDRES = $(HOST)windres --target=pe-i386
else
WINDRES = $(HOST)windres
endif
endif
else
CFLAGS+=-D_POSIX_C_SOURCE=200112
endif
ifeq ($(SAVE_ASM),1)
CFLAGS+=-save-temps -masm=intel -fverbose-asm
endif
CFLAGS+=$(BFLAGS)
LDFLAGS+=$(BFLAGS)
# RULES
.PHONY: clean all install uninstall
all: jpeg2png$(EXE)
jpeg2png$(EXE): $(OBJS) $(RES) Makefile
$(CC) $(OBJS) $(RES) -o $@ $(LDFLAGS) $(LIBS)
-include $(OBJS:.o=.d)
gopt/gopt.o: gopt/gopt.c gopt/gopt.h Makefile
$(CC) $< -c -o $@ $(CFLAGS) $(NO_WARN_FLAGS)
%.o: %.c Makefile
$(CC) -MP -MMD $< -c -o $@ $(CFLAGS) $(WARN_FLAGS)
%.rc.o: %.rc Makefile
$(WINDRES) $< $@
clean:
git clean -Xf
install: all
install -Dm755 jpeg2png "$(DESTDIR)"/usr/bin/jpeg2png
uninstall:
rm "$(DESTDIR)"/usr/bin/jpeg2png