File: Makefile

package info (click to toggle)
gmic 2.4.5-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,480 kB
  • sloc: ansic: 77,136; cpp: 32,580; xml: 5,097; makefile: 539; lisp: 32; sh: 19
file content (773 lines) | stat: -rw-r--r-- 30,359 bytes parent folder | download
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
#
#  File        : Makefile
#                ( Makefile for GNU 'make' utility )
#
#  Description : Makefile for compiling :
#
#                 . the G'MIC command line tool (type 'make cli').
#                 . the G'MIC library, with the C++ API (type 'make lib').
#                 . the G'MIC library, with the C API (type 'make libc' or 'make libcstatic').
#                 . the G'MIC plug-in for GIMP, recommended Qt-based version (type 'make gimp').
#                 . the G'MIC plug-in for Krita (type 'make krita').
#                 . To compile all of them, just type 'make', or 'make all').
#
#                ( https://gmic.eu )
#
#  Copyright   : David Tschumperle
#                ( https://tschumperle.users.greyc.fr/ )
#
#  Licenses    : This file is 'dual-licensed', you have to choose one
#      	          of the two licenses below to apply.
#
#                CeCILL-C
#                The CeCILL-C license is close to the GNU LGPL.
#                ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html )
#
#            or  CeCILL v2.1
#                The CeCILL license is compatible with the GNU GPL.
#                ( http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.html )
#
#  This software is governed either by the CeCILL or the CeCILL-C license
#  under French law and abiding by the rules of distribution of free software.
#  You can  use, modify and or redistribute the software under the terms of
#  the CeCILL or CeCILL-C licenses as circulated by CEA, CNRS and INRIA
#  at the following URL: "http://www.cecill.info".
#
#  As a counterpart to the access to the source code and  rights to copy,
#  modify and redistribute granted by the license, users are provided only
#  with a limited warranty  and the software's author,  the holder of the
#  economic rights,  and the successive licensors  have only  limited
#  liability.
#
#  In this respect, the user's attention is drawn to the risks associated
#  with loading,  using,  modifying and/or developing or reproducing the
#  software by the user in light of its specific status of free software,
#  that may mean  that it is complicated to manipulate,  and  that  also
#  therefore means  that it is reserved for developers  and  experienced
#  professionals having in-depth computer knowledge. Users are therefore
#  encouraged to load and test the software's suitability as regards their
#  requirements in conditions enabling the security of their systems and/or
#  data to be ensured and,  more generally, to use and operate it in the
#  same conditions as regards security.
#
#  The fact that you are presently reading this means that you have had
#  knowledge of the CeCILL and CeCILL-C licenses and that you accept its terms.
#

#---------------------------
# Set OS-specific variables.
#---------------------------

# Try to auto-detect target OS.
OS = $(shell uname)
USR = /usr
LIB = lib
BIN = bin
INCLUDE = include
SO = .so
PIC = -fPIC
EXE =
WGET = wget --no-check-certificate --quiet -O
PLUGINDIR = $(shell gimptool-2.0 --gimpplugindir)/plug-ins
VERSION = $(shell grep 'gmic_version\ ' gmic.h | tail -c4 | head -c3)
VERSION1 = $(shell grep 'gmic_version\ ' gmic.h | tail -c4 | head -c1)
VERSION2 = $(shell grep 'gmic_version\ ' gmic.h | tail -c3 | head -c1)
VERSION3 = $(shell grep 'gmic_version\ ' gmic.h | tail -c2 | head -c1)
SVERSION=$(VERSION1).$(VERSION2).$(VERSION3)
SRC_PATH=$(shell pwd)

# Check that versions of files 'CImg.h' and 'gmic.h' match.
ifneq (,$(wildcard CImg.h))
CIMG_VERSION = $(shell grep 'cimg_version\ ' CImg.h | tail -c4 | head -c3)
else
CIMG_VERSION = $(VERSION)
endif
ifneq ($(VERSION),$(CIMG_VERSION))
MISMATCH_VERSIONS=1
else
MISMATCH_VERSIONS=0
endif

ifeq ($(OS),Linux)
OS = Unix
endif

ifeq ($(OS),GNU/kFreeBSD)
OS = Unix
endif

ifeq ($(OS),GNU)
OS = Unix
endif

ifeq ($(OS),FreeBSD)
OS = Unix
USR = /usr/local
endif

ifeq ($(OS),DragonFly)
OS = Unix
USR = /usr/local
endif

ifeq ($(OS),NetBSD)
OS = Unix
endif

ifneq (, $(findstring MINGW, $(OS)))
OS = Windows
endif

ifeq ($(OS),Darwin)
ifeq (,$(wildcard /opt/local))
USR = /usr/local
PLUGINDIR = $(HOME)/Library/Application\ Support/Gimp/plug-ins
else
USR = /opt/local
endif
WGET = curl -k -L --silent -o
endif

ifeq ($(OS),Windows)
EXE = .exe
SO = .dll
PIC =
endif

ifeq ($(shell echo $(notdir $(CXX)) | head -c3),g++)
IS_GCC = 1
endif
ifeq ($(shell echo $(notdir $(CXX)) | head -c7),clang++)
IS_CLANG = 1
endif
ifeq ($(shell echo $(notdir $(CXX)) | head -c4),icpc)
IS_ICPC = 1
endif

ifdef NOSTRIP
STRIP = echo skip strip
else
STRIP = strip
endif

ifndef QMAKE
QMAKE = qmake
endif

#--------------------------------------------------------
# Define compilation flags to se for each enable feature.
#--------------------------------------------------------

# Flags set to describe a 'prerelease' version.
NO_PRERELEASE = $(shell date +%y%m%d)
NO_PRERELEASE_CFLAGS = -Dgmic_prerelease="\\\"$(PRERELEASE)\\\""

# Minimal set of flags mandatory to compile G'MIC.
MANDATORY_CFLAGS = -Dgmic_build -Dcimg_date=\\\"\\\" -Dcimg_time=\\\"\\\" -Dcimg_use_zlib $(shell pkg-config --cflags zlib || echo -I$(USR)/$(INCLUDE)) $(PRERELEASE_CFLAGS) $(EXTRA_CFLAGS)
MANDATORY_LIBS = $(shell pkg-config --libs zlib || echo -lz) $(EXTRA_LIBS)
ifndef NO_SRIPDLIB
MANDATORY_CFLAGS += -std=c++11 -pedantic
endif
MANDATORY_LIBS += -L$(USR)/$(LIB)
ifdef IS_GCC
MANDATORY_CFLAGS += -Wall -Wextra -Wfatal-errors -Werror=unknown-pragmas -Werror=unused-label
MANDATORY_LIBS += -lm
endif
ifeq ($(OS),Unix)
MANDATORY_CFLAGS += -Dcimg_use_vt100
endif
ifeq ($(OS),Darwin)
ifndef NO_STDLIB
MANDATORY_CFLAGS += -stdlib=libc++
endif
endif
ifeq ($(OS),Windows)
MANDATORY_LIBS += -Wl,--stack,16777216
endif

# Enable optimizations.
OPT_CFLAGS = -Ofast
ifdef IS_GCC
OPT_CFLAGS = -Ofast -mtune=generic # -fno-finite-math-only
endif
ifdef icpc
OPT_CFLAGS = -fast
endif

# Enable multi-threading support.
PARALLEL_CFLAGS = -Dgmic_is_parallel
ifneq ($(OS),Windows)
PARALLEL_LIBS = -lpthread
endif

# Enable parallelization in CImg, using OpenMP.
# (http://www.openmp.org/)
OPENMP_CFLAGS = -fopenmp -Dcimg_use_openmp
OPENMP_LIBS = -lgomp

# Enable software debugging.
# (Use address sanitizer and thus slows down the code)
ifeq ($(OS),Windows)
DEBUG_CFLAGS = -pedantic -Dcimg_verbosity=3 -Dcimg_strict_warnings -g
else
DEBUG_CFLAGS = -pedantic -Dcimg_verbosity=3 -Dcimg_strict_warnings -g -fsanitize=address # -fsanitize=thread # -fsanitize=undefined # Removed '-ansi' as it (silently) disables c++11.
endif

# Enable extra checking of image buffer pointers.
# (Useful for debug, also slows down the code)
ifneq ($(OS),Darwin)
CHECKIMAGE_CFLAGS = # -Dgmic_check_image
endif

# Enable cancellation points in CImg methods.
ABORT_CFLAGS = -Dcimg_use_abort

# Enable image display, using X11 (Unix).
# (Keep /usr/ dirname here since X11 is located in /usr/ on Mac too)
ifneq ($(OS),Darwin)
X11_CFLAGS = -Dcimg_display=1 $(shell pkg-config --cflags x11 || echo -I/usr/X11R6/include) #-Dcimg_use_xrandr
X11_LIBS = $(shell pkg-config --libs x11 || echo -L/usr/X11R6/lib -lX11) -lpthread # $(shell pkg-config --libs xrandr || echo -lXrandr)
else
ifeq (,$(wildcard /usr/X11))
X11_CFLAGS = -Dcimg_display=0 #-Dcimg_use_xrandr
X11_LIBS = -lpthread # $(shell pkg-config --libs xrandr || echo -lXrandr)
else
X11_CFLAGS = -Dcimg_display=1 $(shell pkg-config --cflags x11 || echo -I/usr/X11/include) #-Dcimg_use_xrandr
X11_LIBS = -L/usr/X11/lib -lX11 -lpthread # $(shell pkg-config --libs xrandr || echo -lXrandr)
endif
endif

# Enable faster X11 display, using XShm extension.
# (ftp://www.x.org/pub/X11R7.7/doc/man/man3/XShm.3.xhtml)
XSHM_CFLAGS = -Dcimg_use_xshm $(shell pkg-config --cflags xcb-shm)
XSHM_LIBS = $(shell pkg-config --libs xcb-shm || echo -L$(USR)/X11R6/lib -lXext)

# Enable image display, using GDI32 (Windows).
GDI32_CFLAGS = -Dcimg_display=2
GDI32_LIBS = -lgdi32

# Enable native support of PNG image files, using the PNG library.
# (http://www.libpng.org/pub/png/libpng.html)
ifneq ($(OS),Darwin)
PNG_CFLAGS = -Dcimg_use_png $(shell pkg-config --cflags libpng)
PNG_LIBS = $(shell pkg-config --libs libpng || echo -lpng -lz)
else
ifeq (,$(wildcard /tmp/skl))
PNG_CFLAGS = -Dcimg_use_png $(shell pkg-config --cflags libpng)
PNG_LIBS = $(shell pkg-config --libs libpng || echo -lpng -lz)
else
PNG_CFLAGS = -Dcimg_use_png
PNG_LIBS = -lpng -lz
endif
endif

# Enable native support of JPEG image files, using the JPEG library.
# (http://libjpeg.sourceforge.net/)
JPEG_CFLAGS = -Dcimg_use_jpeg
JPEG_LIBS = -ljpeg

# Enable native support of TIFF image files, using the TIFF library.
# (http://www.libtiff.org/)
TIFF_CFLAGS = -Dcimg_use_tiff $(shell pkg-config --cflags libtiff-4)
TIFF_LIBS = $(shell pkg-config --libs libtiff-4 || echo -ltiff)

# Enable native support of MINC2 image files, using the MINC2 library.
# ( http://en.wikibooks.org/wiki/MINC/Reference/MINC2.0_Users_Guide )
MINC2_CFLAGS = -Dcimg_use_minc2 -I${HOME}/local/include
MINC2_LIBS = -lminc_io -lvolume_io2 -lminc2 -lnetcdf -lhdf5 -lz -L${HOME}/local/lib

# Enable native support for downloading files from the network.
# ( http://curl.haxx.se/libcurl/ )
CURL_CFLAGS = -Dcimg_use_curl $(shell pkg-config --cflags libcurl)
CURL_LIBS = $(shell pkg-config --libs libcurl || echo -lcurl)

# Enable native support of webcams and video streaming, using the OpenCV library.
# (https://opencv.org/)
OPENCV_CFLAGS = -Dcimg_use_opencv $(shell pkg-config opencv4 --cflags || echo -I/usr/include/opencv) -I/usr/include/opencv
OPENCV_LIBS = $(shell pkg-config opencv4 --libs || echo -lopencv_core -lopencv_highgui)

# Enable support of most classical image file formats, using the GraphicsMagick++ library.
# (http://www.graphicsmagick.org/Magick++/)
MAGICK_CFLAGS = -Dcimg_use_magick $(shell pkg-config --cflags GraphicsMagick++ || echo -I$(USR)/$(INCLUDE)/GraphicsMagick)
MAGICK_LIBS = $(shell pkg-config --libs GraphicsMagick++ || echo -lGraphicsMagick++)

# Enable native support of EXR image files, using the OpenEXR library.
# (http://www.openexr.com/)
OPENEXR_CFLAGS = -Dcimg_use_openexr -I$(USR)/$(INCLUDE)/OpenEXR
OPENEXR_LIBS = -lIlmImf -lHalf

# Enable Fast Fourier Transforms, using the FFTW3 library.
# (http://www.fftw.org/)
FFTW_CFLAGS = -Dcimg_use_fftw3 $(shell pkg-config --cflags fftw3)
FFTW_LIBS = $(shell pkg-config --libs fftw3 || echo -lfftw3)
ifneq ($(OS),Windows)
FFTW_LIBS += -lfftw3_threads
endif

# Enable native support of the BOARD library.
# (https://github.com/c-koi/libboard)
BOARD_CFLAGS = -Dcimg_use_board
BOARD_LIBS = -lboard

#-------------------------------
# Define main Makefile entries.
#-------------------------------

# Multi-targets
#--------------
all:
	@echo "**"
ifeq ($(OS),Unix)
	@echo "** Start building G'MIC with default Unix configuration."
else
ifeq ($(OS),Darwin)
	@echo "** Start building G'MIC with default MacOSX configuration."
else
	@echo "** Start building G'MIC with default Windows configuration."
endif
endif
	@echo "**"
	$(MAKE) cli lib gimp krita gmic_qt libc zart

native:
	$(MAKE) "CFLAGS+=$(GMIC_CLI_CFLAGS) -Ofast -march=native" "LIBS+=$(GMIC_CLI_LIBS)" cli

# CLI (standard)
#---------------
GMIC_CLI_CFLAGS = $(MANDATORY_CFLAGS) $(ABORT_CFLAGS) $(PARALLEL_CFLAGS) $(FFTW_CFLAGS) $(CURL_CFLAGS) $(PNG_CFLAGS) $(JPEG_CFLAGS) $(TIFF_CFLAGS)
GMIC_CLI_LIBS = $(MANDATORY_LIBS) $(PARALLEL_LIBS) $(FFTW_LIBS) $(CURL_LIBS) $(PNG_LIBS) $(JPEG_LIBS) $(TIFF_LIBS)
ifeq ($(OS),Unix) # Unix.
GMIC_CLI_CFLAGS += $(OPENMP_CFLAGS) $(X11_CFLAGS) $(OPENEXR_CFLAGS) $(OPENCV_CFLAGS) # $(XSHM_CFLAGS) $(MAGICK_CFLAGS)
GMIC_CLI_LIBS += $(OPENMP_LIBS) $(X11_LIBS) $(OPENEXR_LIBS) $(OPENCV_LIBS) # $(XSHM_LIBS) # $(MAGICK_LIBS)
else
ifeq ($(OS),Darwin) # MacOSX.
GMIC_CLI_CFLAGS += $(X11_CFLAGS) $(OPENEXR_CFLAGS) $(OPENCV_CFLAGS)
GMIC_CLI_LIBS += $(X11_LIBS) $(OPENEXR_LIBS) $(OPENCV_LIBS) $(OPT_LIBS)
else # Windows.
GMIC_CLI_CFLAGS += $(OPENMP_CFLAGS) $(GDI32_CFLAGS) $(OPENCV_CFLAGS)
GMIC_CLI_LIBS += $(OPENMP_LIBS) $(GDI32_LIBS) $(OPENCV_LIBS)
endif
endif

cli:
	$(MAKE) "CFLAGS+=$(GMIC_CLI_CFLAGS) $(OPT_CFLAGS)" "LIBS+=$(GMIC_CLI_LIBS)" _cli
	$(STRIP) gmic$(EXE)

debug:
	$(MAKE) "CFLAGS+=$(GMIC_CLI_CFLAGS) $(DEBUG_CFLAGS)" "LIBS+=$(GMIC_CLI_LIBS)" _cli

_cli: check_versions gmic.cpp gmic.h gmic_stdlib.h CImg.h
	$(CXX) -o gmic_cli.o -c gmic.cpp $(CFLAGS)
	$(CXX) -o gmic gmic_cli.cpp gmic_cli.o $(CFLAGS) $(LIBS)

# CLI (static)
#-------------
GMIC_STATIC_CLI_PATH = $(USR)/$(LIB)/x86_64-linux-gnu
GMIC_STATIC_CLI_EXTRA =
GMIC_STATIC_CLI_CFLAGS = $(MANDATORY_CFLAGS) $(ABORT_CFLAGS) $(PARALLEL_CFLAGS) $(ZLIB_CFLAGS) $(FFTW_CFLAGS) $(PNG_CFLAGS) $(JPEG_CFLAGS) -Dcimg_display=0
GMIC_STATIC_CLI_LIBS = $(PARALLEL_LIBS) \
	               $(GMIC_STATIC_CLI_PATH)/libpng.a \
	               $(GMIC_STATIC_CLI_PATH)/libjpeg.a \
                       $(GMIC_STATIC_CLI_PATH)/libz.a \
                       $(GMIC_STATIC_CLI_PATH)/libfftw3.a $(GMIC_STATIC_CLI_PATH)/libfftw3_threads.a \
	               $(GMIC_STATIC_CLI_EXTRA)

static:
	$(MAKE) "CFLAGS+=$(GMIC_STATIC_CLI_CFLAGS) $(OPT_CFLAGS)" "LIBS+=$(GMIC_STATIC_CLI_LIBS)" _cli
	$(STRIP) gmic$(EXE)

# Libgmic
#--------
GMIC_LIB_CFLAGS = $(MANDATORY_CFLAGS) $(ABORT_CFLAGS) $(PARALLEL_CFLAGS) $(FFTW_CFLAGS) $(CURL_CFLAGS) $(PNG_CFLAGS) $(JPEG_CFLAGS) $(TIFF_CFLAGS)
GMIC_LIB_LIBS = $(MANDATORY_LIBS) $(PARALLEL_LIBS) $(FFTW_LIBS) $(CURL_LIBS) $(PNG_LIBS) $(JPEG_LIBS) $(TIFF_LIBS)
ifeq ($(OS),Unix) # Unix.
GMIC_LIB_CFLAGS += $(OPENMP_CFLAGS) $(X11_CFLAGS)
GMIC_LIB_LIBS += $(OPENMP_LIBS) $(X11_LIBS)
else
ifeq ($(OS),Darwin) # MacOSX.
GMIC_LIB_CFLAGS += $(X11_CFLAGS)
GMIC_LIB_LIBS += $(X11_LIBS) $(OPT_LIBS)
else # Windows.
GMIC_LIB_CFLAGS += $(OPENMP_CFLAGS) $(GDI32_CFLAGS)
GMIC_LIB_LIBS += $(OPENMP_LIBS) $(GDI32_LIBS)
endif
endif

lib:
	$(MAKE) "CFLAGS+=$(GMIC_LIB_CFLAGS) $(OPT_CFLAGS)" "LIBS+=$(GMIC_LIB_LIBS)" _lib

_lib: libgmic.o use_libgmic.cpp
	ar rcs libgmic.a libgmic.o
ifeq ($(OS),Darwin)
	$(CXX) -shared -o libgmic.so libgmic.o $(LIBS)
else
	$(CXX) -shared -Wl,-soname,libgmic.so.$(VERSION1) -o libgmic.so libgmic.o $(LIBS)
	$(CXX) -o use_libgmic use_libgmic.cpp -L. -lgmic $(LIBS)
endif

libgmic.o: check_versions gmic.cpp gmic.h gmic_stdlib.h CImg.h
	$(CXX) -o libgmic.o -c gmic.cpp $(PIC) $(CFLAGS)

# LibCgmic (standard)
#--------------------
GMIC_LIBC_CFLAGS = $(MANDATORY_CFLAGS) $(ABORT_CFLAGS) $(PARALLEL_CFLAGS) $(FFTW_CFLAGS) $(CURL_CFLAGS) $(PNG_CFLAGS) $(JPEG_CFLAGS) $(TIFF_CFLAGS)
GMIC_LIBC_LIBS = $(MANDATORY_LIBS) $(PARALLEL_LIBS) $(FFTW_LIBS) $(CURL_LIBS) $(PNG_LIBS) $(JPEG_LIBS) $(TIFF_LIBS)
ifeq ($(OS),Unix) # Unix.
GMIC_LIBC_CFLAGS += $(OPENMP_CFLAGS) $(X11_CFLAGS)
GMIC_LIBC_LIBS += $(OPENMP_LIBS) $(X11_LIBS)
else
ifeq ($(OS),Darwin) # MacOSX.
GMIC_LIBC_CFLAGS += $(X11_CFLAGS)
GMIC_LIBC_LIBS += $(X11_LIBS) $(OPT_LIBS)
else # Windows.
GMIC_LIBC_CFLAGS += $(OPENMP_CFLAGS) $(GDI32_CFLAGS)
GMIC_LIBC_LIBS += $(OPENMP_LIBS) $(GDI32_LIBS)
endif
endif

libc:
	$(MAKE) "CFLAGS+=$(GMIC_LIBC_CFLAGS) $(OPT_CFLAGS)" "LIBS+=$(GMIC_LIBC_LIBS)" _libc

_libc: libcgmic_files libgmic.o libcgmic.o
	ar rcs libcgmic.a libcgmic.o
ifeq ($(OS),Darwin)
	$(CXX) -shared -o libcgmic.so libcgmic.o libgmic.o $(LIBS)
else
ifeq ($(OS),Windows)
	$(CXX) -shared -Wl,-soname,libcgmic.so.$(VERSION1) -o libcgmic$(SO) libcgmic.o libgmic.o -Wl,--output-def,libcgmic.def,--out-implib,libcgmic.a $(LIBS)
else
	$(CXX) -shared -Wl,-soname,libcgmic.so.$(VERSION1) -o libcgmic$(SO) libcgmic.o libgmic.o $(LIBS)
endif
endif
	$(CC) -std=c99 -o use_libcgmic use_libcgmic.c -L. -lcgmic

libcgmic.o: check_versions gmic.cpp gmic.h gmic_stdlib.h CImg.h
	$(CXX) -o libcgmic.o -c gmic_libc.cpp $(PIC) $(CFLAGS)

libcgmic_files:
	@echo "> Retrieve G'MIC libcgmic files..."
	@if [ ! -f gmic_libc.cpp ]; then \
	  if [ -d ../../gmic-community/libcgmic ]; then \
	    ln -fs ../../gmic-community/libcgmic/gmic_libc.cpp .; \
	    ln -fs ../../gmic-community/libcgmic/gmic_libc.h .; \
	    ln -fs ../../gmic-community/libcgmic/use_libcgmic.c .; \
	  else \
            $(WGET) gmic_libc.cpp https://raw.githubusercontent.com/dtschump/gmic-community/master/libcgmic/gmic_libc.cpp; \
            $(WGET) gmic_libc.h https://raw.githubusercontent.com/dtschump/gmic-community/master/libcgmic/gmic_libc.h; \
            $(WGET) use_libcgmic.c https://raw.githubusercontent.com/dtschump/gmic-community/master/libcgmic/use_libcgmic.c; \
            touch gmic_libc.cpp gmic_libc.h use_libcgmic.c; \
	  fi; \
	fi
	@echo " done!"

# LibCgmic (static)
#------------------
GMIC_LIBC_STATIC_CFLAGS = $(MANDATORY_CFLAGS) $(ABORT_CFLAGS) $(PARALLEL_CFLAGS) $(FFTW_CFLAGS) $(PNG_CFLAGS) $(JPEG_CFLAGS) # $(CURL_CFLAGS) $(TIFF_CFLAGS)
ifeq ($(OS),Window)
GMIC_LIBC_STATIC_LIBS = -Bstatic -lpthread
endif
GMIC_LIBC_STATIC_LIBS += $(MANDATORY_LIBS) $(PARALLEL_LIBS) $(FFTW_LIBS) $(PNG_LIBS) $(JPEG_LIBS) # $(CURL_LIBS) $(TIFF_LIBS)
ifeq ($(OS),Unix) # Unix.
GMIC_LIBC_STATIC_CFLAGS += $(OPENMP_CFLAGS) $(X11_CFLAGS)
GMIC_LIBC_STATIC_LIBS += $(OPENMP_LIBS) $(X11_LIBS)
else
ifeq ($(OS),Darwin) # MacOSX.
GMIC_LIBC_STATIC_CFLAGS += $(X11_CFLAGS)
GMIC_LIBC_STATIC_LIBS += $(X11_LIBS) $(OPT_LIBS)
else # Windows.
GMIC_LIBC_STATIC_CFLAGS += $(OPENMP_CFLAGS) $(GDI32_CFLAGS)
GMIC_LIBC_STATIC_LIBS += $(OPENMP_LIBS) $(GDI32_LIBS)
endif
endif

libcstatic:
	rm -f libgmic.o
	$(MAKE) "CFLAGS+=$(GMIC_LIBC_STATIC_CFLAGS) $(OPT_CFLAGS)" "LIBS+=$(GMIC_LIBC_STATIC_LIBS)" _libcstatic

_libcstatic: libcgmic_files libgmic.o libcgmicstatic.o
	ar rcs libcgmicstatic.a libcgmicstatic.o
ifeq ($(OS),Darwin)
	$(CXX) -shared -static -o libcgmicstatic.so libcgmicstatic.o libgmic.o $(PIC) $(CFLAGS) $(LIBS)
else
ifeq ($(OS),Windows)
	$(CXX) -shared -static -Wl,-soname,libcgmicstatic.so.$(VERSION1) -o libcgmicstatic$(SO) libcgmicstatic.o libgmic.o $(PIC) -Wl,--output-def,libcgmicstatic.def,--out-implib,libcgmicstatic.a $(CFLAGS) $(LIBS)
else
	$(CXX) -shared -Wl,-soname,libcgmicstatic.so.$(VERSION1) -o libcgmicstatic$(SO) libcgmicstatic.o libgmic.o $(PIC) $(CFLAGS) $(LIBS)
endif
endif
	$(CC) -std=c99 -o use_libcgmic_static use_libcgmic.c -L. -lcgmicstatic

libcgmicstatic.o: check_versions gmic.cpp gmic.h gmic_stdlib.h CImg.h
	$(CXX) -o libcgmicstatic.o -c gmic_libc.cpp $(PIC) $(CFLAGS)

# All interfaces, sharing the same dynamic library
#--------------------------------------------------
allshared:
	$(MAKE) "CFLAGS+=$(GMIC_CLI_CFLAGS) $(OPT_CFLAGS)" "LIBS+=$(GMIC_CLI_LIBS)" _allshared

_allshared: libgmic_shared.o
	ar rcs libgmic_shared.a libgmic_shared.o
	$(CXX) -shared -Wl,-soname,libgmic_shared.so.$(VERSION1) -o libgmic_shared.so libgmic_shared.o $(LIBS)
	$(CXX) -o use_libgmic use_libgmic.cpp -L. -lgmic_shared $(LIBS)

	$(CXX) -o gmic gmic_cli.cpp $(CFLAGS) -lgmic_shared $(LIBS)
	$(STRIP) gmic$(EXE)

libgmic_shared.o: check_versions CImg.h gmic_stdlib.h
	$(CXX) -o libgmic_shared.o -c gmic.cpp $(PIC) $(CFLAGS)

# G'MIC Online
#-------------
GMICOL_LIB_PATH = /usr/lib/x86_64-linux-gnu/
GMICOL_CFLAGS = $(MANDATORY_CFLAGS) $(PARALLEL_CFLAGS) $(FFTW_CFLAGS) $(PNG_CFLAGS) $(JPEG_CFLAGS) $(ZLIB_CFLAGS) -Dcimg_display=0 # $(OPENMP_CFLAGS)
GMICOL_LIBS = $(MANDATORY_LIBS) $(PARALLEL_LIBS) $(PNG_LIBS) $(JPEG_LIBS) $(ZLIB_LIBS) $(GMICOL_LIB_PATH)/libfftw3.a $(GMICOL_LIB_PATH)/libfftw3_threads.a # $(OPENMP_LIBS)

gmicol:
	$(MAKE) "CFLAGS+=$(GMICOL_CFLAGS) $(OPT_CFLAGS)" "LIBS+=$(GMICOL_LIBS)" _cli
	$(STRIP) gmic$(EXE)

# G'MIC-Qt
#---------
gimp: check_versions gmic_qt_files CImg.h gmic_stdlib.h
	cd ../gmic-qt && $(QMAKE) CONFIG+=release GMIC_PATH=$(SRC_PATH) PRERELEASE=$(PRERELEASE) HOST=gimp gmic_qt.pro && $(MAKE)
	@echo "Executable 'gmic_gimp_qt' has been successfully compiled in '../gmic-qt/'."

krita: check_versions gmic_qt_files CImg.h gmic_stdlib.h
	cd ../gmic-qt && $(QMAKE) CONFIG+=release GMIC_PATH=$(SRC_PATH) PRERELEASE=$(PRERELEASE) HOST=krita gmic_qt.pro && $(MAKE)
	@echo "Executable 'gmic_krita_qt' has been successfully compiled in '../gmic-qt/'."

gmic_qt: check_versions gmic_qt_files CImg.h gmic_stdlib.h
	cd ../gmic-qt && $(QMAKE) CONFIG+=release GMIC_PATH=$(SRC_PATH) PRERELEASE=$(PRERELEASE) HOST=none gmic_qt.pro && $(MAKE)
	@echo "Executable 'gmic_qt' has been successfully compiled in '../gmic-qt/'."

gmic_qt_files:
	@if [ ! -d ../gmic-qt ]; then \
	  if [ ! -d ../../gmic-qt ]; then \
	    echo "**"; \
	    echo "** Warning: folder 'gmic-qt' was not found !"; \
	    echo "** It is mandatory to compile the G'MIC plug-in for GIMP and Krita ('gmic_gimp_qt' and 'gmic_krita_qt'),"; \
	    echo "** as well as the standalone Qt-based interface 'gmic_qt'."; \
            echo "** Trying to retrieve it, with: $$ cd ../../ && git clone https://github.com/c-koi/gmic-qt.git"; \
	    echo "**"; \
	    if cd ../../ && git clone https://github.com/c-koi/gmic-qt.git; then \
	      echo "**"; \
              echo "** Success !"; \
	      echo "**"; \
	    else \
	      echo "**"; \
              echo "** Fatal error: Failed to retrieve folder 'gmic-qt', compilation will probably ends shortly !"; \
	      echo "**"; \
	    fi; \
	  fi; \
	  if [ -d ../../gmic-qt ]; then ln -fs ../gmic-qt ..; fi \
	fi

# ZArt
#-----
zart: check_versions zart_files CImg.h gmic_stdlib.h
ifeq ($(OS),Darwin)
	cd ../zart && $(QMAKE) CONFIG+=release GMIC_PATH=$(SRC_PATH) zart.pro && $(MAKE) && $(STRIP) zart.app/Contents/MacOS/zart
else
	cd ../zart && $(QMAKE) CONFIG+=release GMIC_PATH=$(SRC_PATH) zart.pro && $(MAKE) && $(STRIP) zart
endif
	@echo "Executable 'zart' has been successfully compiled in '../zart/'."

zart_files:
	@if [ ! -d ../zart ]; then \
	  if [ ! -d ../../zart ]; then \
	    echo "**"; \
	    echo "** Warning: folder 'zart' was not found !"; \
	    echo "** It is mandatory to compile 'zart'."; \
            echo "** Trying to retrieve it, with: $$ cd ../../ && git clone https://github.com/c-koi/zart.git"; \
	    echo "**"; \
	    if cd ../../ && git clone https://github.com/c-koi/zart.git; then \
	      echo "**"; \
              echo "** Success !"; \
	      echo "**"; \
	    else \
              echo "**"; \
              echo "** Fatal error: Failed to retrieve folder 'zart', compilation will probably ends shortly !"; \
              echo "**"; \
	    fi; \
	  fi; \
	  if [ -d ../../zart ]; then ln -fs ../zart ..; fi \
	fi

# Get header files
#------------------
gmic_stdlib.h: gmic_stdlib.gmic
	@echo "> Retrieve G'MIC Standard Library..."
	@if [ ! -f ./gmic_stdlib.h ]; then \
	  $(WGET) gmic_stdlib.h https://gmic.eu/gmic_stdlib$(VERSION).h; \
	  touch gmic_stdlib.h; \
	fi
	@echo " done!"

CImg.h:
	@echo "> Retrieve CImg Library..."
	@if [ -f ../../CImg/CImg.h ]; then \
          if [ ! -f ./CImg.h ]; then ln -s ../../CImg/CImg.h .; fi; \
        elif [ ! -e ./CImg.h ]; then \
          $(WGET) CImg.h https://framagit.org/dtschump/CImg/raw/master/CImg.h; \
          touch CImg.h; \
        fi
	@echo " done!"

check_versions:
	@if [ $(MISMATCH_VERSIONS) = 1 ]; then \
	  echo >&2 "make: *** Version numbers of files 'gmic.h' (v.$(VERSION)) and 'CImg.h' (v.$(CIMG_VERSION)) do not match."; \
	  echo >&2 "make: *** Try make 'clean' to ensure you get the latest version of the CImg library."; \
          false; \
        fi

do_gmic_stdlib.h:
	@echo "/*\n\
 #\n\
 #  File        : gmic_stdlib.h (v.$(SVERSION))\n\
 #                ( C++ header file )\n\
 #\n\
 #  Description : Raw data arrays encoding the G'MIC standard library\n\
 #                into a compressed form.\n\
 #                This file has been automatically generated by the Makefile entry\n\
 #                'do_gmic_stdlib.h:', from the G'MIC source file 'gmic_stdlib.gmic'.\n\
 #                ( https://gmic.eu )\n\
 #\n\
 #  Copyright   : David Tschumperle\n\
 #                ( https://tschumperle.users.greyc.fr/ )\n\
 #\n\
 #  Licenses    : This file is 'dual-licensed', you have to choose one\n\
 #      	   of the two licenses below to apply.\n\
 #\n\
 #                CeCILL-C\n\
 #                The CeCILL-C license is close to the GNU LGPL.\n\
 #                ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html )\n\
 #\n\
 #            or  CeCILL v2.1\n\
 #                The CeCILL license is compatible with the GNU GPL.\n\
 #                ( http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.html )\n\
 #\n\
 #  This software is governed either by the CeCILL or the CeCILL-C license\n\
 #  under French law and abiding by the rules of distribution of free software.\n\
 #  You can  use, modify and or redistribute the software under the terms of\n\
 #  the CeCILL or CeCILL-C licenses as circulated by CEA, CNRS and INRIA\n\
 #  at the following URL: \"http://www.cecill.info\".\n\
 #\n\
 #  As a counterpart to the access to the source code and  rights to copy,\n\
 #  modify and redistribute granted by the license, users are provided only\n\
 #  with a limited warranty  and the software's author,  the holder of the\n\
 #  economic rights,  and the successive licensors  have only  limited\n\
 #  liability.\n\
 #\n\
 #  In this respect, the user's attention is drawn to the risks associated\n\
 #  with loading,  using,  modifying and/or developing or reproducing the\n\
 #  software by the user in light of its specific status of free software,\n\
 #  that may mean  that it is complicated to manipulate,  and  that  also\n\
 #  therefore means  that it is reserved for developers  and  experienced\n\
 #  professionals having in-depth computer knowledge. Users are therefore\n\
 #  encouraged to load and test the software's suitability as regards their\n\
 #  requirements in conditions enabling the security of their systems and/or\n\
 #  data to be ensured and,  more generally, to use and operate it in the\n\
 #  same conditions as regards security.\n\
 #\n\
 #  The fact that you are presently reading this means that you have had\n\
 #  knowledge of the CeCILL and CeCILL-C licenses and that you accept its terms.\n\
 #\n\
*/\n" > gmic_stdlib.h
	@\gmic gmic_stdlib.gmic raw:gmic_stdlib.gmic,char compress_gmic 1 a y serialize char,1,0 o -.h,uchar | sed 's/unsigned char/const unsigned char/' | sed 's/unnamed/gmic_stdlib/' >> gmic_stdlib.h
	@echo "\nconst unsigned long size_data_gmic_stdlib = (unsigned long)sizeof(data_gmic_stdlib);" >> gmic_stdlib.h
	@\gmic v - _update_server_upload gmic_stdlib.h
	@cp -f gmic_stdlib.h /tmp/gmic_stdlib$(VERSION).h
	@\gmic v - _update_server_upload /tmp/gmic_stdlib$(VERSION).h
	@\gmic v - _update_server_upload gmic_stdlib.h

# Bash completion script
#-----------------------
bashcompletion:
	@mkdir -p ../resources
	@\gmic v - gmic_stdlib.gmic raw:gmic_stdlib.gmic,uchar nm gmic document_gmic bash 2> ../resources/gmic_bashcompletion.sh
	@echo "Bash completion script 'gmic_bashcompletion.sh' has been successfully generated in '../resources/'."

# Man pages
#----------
man:
	@mkdir -p ../man
	@\gmic v - gmic_stdlib.gmic raw:gmic_stdlib.gmic,uchar __help man 2> ../man/gmic.1
	@gzip -f ../man/gmic.1
	@echo "Man file 'gmic.1.gz' has been successfully generated in '../man/'."

# Install / uninstall / clean.
#-----------------------------
install:
	mkdir -p $(DESTDIR)$(PLUGINDIR)/
	cp -f ../resources/gmic_film_cluts.gmz $(DESTDIR)$(PLUGINDIR)/
	mkdir -p $(DESTDIR)$(USR)/$(BIN)/
	cp -f gmic $(DESTDIR)$(USR)/$(BIN)/
	mkdir -p $(DESTDIR)$(USR)/$(INCLUDE)/
	cp -f gmic.h $(DESTDIR)$(USR)/$(INCLUDE)/
	@if [ -f gmic_libc.h ]; then cp -f gmic_libc.h $(DESTDIR)$(USR)/$(INCLUDE)/; fi
	@if [ -f ../zart/zart ]; then cp -f ../zart/zart $(DESTDIR)$(USR)/$(BIN)/; fi
	@if [ -f ../gmic-qt/gmic_qt ]; then cp -f ../gmic-qt/gmic_qt $(DESTDIR)$(USR)/$(BIN)/; fi
	@if [ -f ../gmic-qt/gmic_gimp_qt ]; then cp -f ../gmic-qt/gmic_gimp_qt $(DESTDIR)$(PLUGINDIR)/; fi
	@if [ -f ../gmic-qt/gmic_krita_qt ]; then cp -f ../gmic-qt/gmic_krita_qt $(DESTDIR)$(USR)/$(BIN)/; fi

ifneq ($(OS),Darwin)
	mkdir -p $(DESTDIR)$(USR)/share
	mkdir -p $(DESTDIR)$(USR)/$(LIB)
	cp -f libgmic.so $(DESTDIR)$(USR)/$(LIB)/libgmic.so.$(VERSION)
	ln -fs libgmic.so.$(VERSION) $(DESTDIR)$(USR)/$(LIB)/libgmic.so.$(VERSION1)
	ln -fs libgmic.so.$(VERSION1) $(DESTDIR)$(USR)/$(LIB)/libgmic.so
	@if [ -f libcgmic.so ]; then \
	  cp -f gmic_libc.h $(DESTDIR)$(USR)/$(INCLUDE)/; \
	  cp -f libcgmic.so $(DESTDIR)$(USR)/$(LIB)/libcgmic.so.$(VERSION); \
          ln -fs libcgmic.so.$(VERSION) $(DESTDIR)$(USR)/$(LIB)/libcgmic.so.$(VERSION1) ; \
          ln -fs libcgmic.so.$(VERSION1) $(DESTDIR)$(USR)/$(LIB)/libcgmic.so; \
        fi
endif
	mkdir -p $(DESTDIR)$(USR)/share/man/
	mkdir -p $(DESTDIR)$(USR)/share/man/man1/
	mkdir -p $(DESTDIR)$(USR)/share/man/fr/man1/
	@if [ -f ../man/gmic.1.gz ]; then \
	  cp -f ../man/gmic.1.gz $(DESTDIR)$(USR)/share/man/man1/gmic.1.gz; \
	  cp -f ../man/gmic.1.gz $(DESTDIR)$(USR)/share/man/fr/man1/gmic.1.gz; \
	fi
	@if [ -f ../resources/gmic_bashcompletion.sh ]; then \
	  if [ -d /usr/share/bash-completion/completions ]; then \
	    mkdir -p $(DESTDIR)/usr/share/bash-completion/completions/; \
            cp -f ../resources/gmic_bashcompletion.sh $(DESTDIR)/usr/share/bash-completion/completions/gmic; \
	  fi; \
	  if [ -d /opt/local/etc/bash_completion.d/ ]; then \
            mkdir -p $(DESTDIR)/opt/local/etc/bash_completion.d/; \
            cp -f ../resources/gmic_bashcompletion.sh $(DESTDIR)/opt/local/etc/bash_completion.d/gmic; \
          fi; \
        fi

uninstall:
	rm -f $(DESTDIR)$(PLUGINDIR)/gmic_gimp_qt
	rm -f $(DESTDIR)$(PLUGINDIR)/gmic_krita_qt
	rm -f $(DESTDIR)$(USR)/$(BIN)/gmic
	rm -f $(DESTDIR)$(USR)/$(BIN)/zart
	rm -f $(DESTDIR)$(USR)/$(BIN)/gmic_qt
	rm -f $(DESTDIR)$(USR)/$(INCLUDE)/gmic.h
	rm -f $(DESTDIR)$(USR)/$(LIB)/libgmic.so.$(VERSION)
	rm -f $(DESTDIR)$(USR)/$(LIB)/libgmic.so.$(VERSION1)
	rm -f $(DESTDIR)$(USR)/$(LIB)/libgmic.so
	rm -f $(DESTDIR)$(USR)/$(LIB)/libcgmic.so.$(VERSION)
	rm -f $(DESTDIR)$(USR)/$(LIB)/libcgmic.so.$(VERSION1)
	rm -f $(DESTDIR)$(USR)/$(LIB)/libcgmic$(SO)
	rm -rf $(DESTDIR)$(USR)/share/doc/gmic/
	rm -f $(DESTDIR)$(USR)/share/man/man1/gmic.1.gz
	rm -f $(DESTDIR)$(USR)/share/man/fr/man1/gmic.1.gz

distclean: clean

clean:
	rm -rf gmic$(EXE) use_libgmic$(EXE) use_libcgmic$(EXE) use_libcgmic_static$(EXE) gmic*.o libgmic* libcgmic* *~
	@if [ -f ../zart/Makefile ]; then cd ../zart && $(MAKE) clean; fi
	@if [ -h ../zart ]; then rm -f ../zart; fi
	@if [ -f ../gmic-qt/Makefile ]; then cd ../gmic-qt && $(MAKE) clean; fi
	@if [ -h ../gmic-qt ]; then rm -f ../gmic-qt; fi
	@if [ -h gmic_libc.h ]; then rm -f gmic_libc.h; fi
	@if [ -h gmic_libc.cpp ]; then rm -f gmic_libc.cpp; fi
	@if [ -h use_libcgmic.c ]; then rm -f use_libcgmic.c; fi

# End of Makefile.