-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
126 lines (100 loc) · 3.69 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
SRC_DIR := src
OBJ_DIR := obj
SRC_FILES := $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/gif/*.c) $(wildcard $(SRC_DIR)/png/*.c)
OBJ := $(SRC_FILES:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
UNAME := $(shell uname)
CFLAGS := -Iinclude -fPIC
LDFLAGS := -lz -lm
PREFIX ?= usr/local
DESTDIR ?= /
ifeq ($(UNAME), Darwin)
ADDCFLAGS += -framework Cocoa -Isupport/
IMAGE_VIEWER_TARGET += support/animator.m support/appdelegate.m support/image_viewer_mac.m
LFLAGS += -Wl,-undefined -Wl,dynamic_lookup
else
ADDCFLAGS += -lX11 -Isupport/
IMAGE_VIEWER_TARGET += support/image_viewer_linux.c
LFLAGS += -shared -o libpngif.so.0
endif
all: $(SRC_FILES)
make static
make dynamic
make tests
# Generic rule for .o files.
$(OBJ): $(OBJ_DIR)/%.o : $(SRC_DIR)/%.c
@mkdir -p obj/gif
@mkdir -p obj/png
gcc $(CFLAGS) -c $< -o $@
clean:
rm -rf $(OBJ)
rm -rf bin/test_gif_parsed bin/test_gif_codes bin/test_gif_decoded bin/test_gif_image \
bin/test_png_parsed bin/test_png_decoded bin/test_png_image bin/test_png_chunks \
bin/test_image_viewer bin/*.dSYM
rm -f bin/libpngif.a bin/libpngif.so.0.1
# Libraries
bin/libpngif.a: $(SRC_FILES) $(OBJ)
@mkdir -p bin
ar r bin/libpngif.a $(OBJ)
ranlib bin/libpngif.a
static: bin/libpngif.a
bin/libpngif.so.0.1: $(SRC_FILES) $(OBJ)
@mkdir -p bin
gcc -Wall $(LFLAGS) -o bin/libpngif.so.0.1 $(OBJ)
dynamic: bin/libpngif.so.0.1
# Installation
install: static dynamic
cp -R include/pngif $(DESTDIR)$(PREFIX)/include/
cp bin/libpngif.so.0.1 $(DESTDIR)$(PREFIX)/lib/libpngif.so.0.1
ln -s -f $(DESTDIR)$(PREFIX)/lib/libpngif.so.0.1 $(DESTDIR)$(PREFIX)/lib/libpngif.so
cp bin/libpngif.a $(DESTDIR)$(PREFIX)/lib/libpngif.a
uninstall:
rm -rf $(DESTDIR)$(PREFIX)/include/pngif
rm $(DESTDIR)$(PREFIX)/lib/libpngif.so.0.1 \
$(DESTDIR)$(PREFIX)/lib/libpngif.so \
$(DESTDIR)$(PREFIX)/lib/libpngif.a
# Tests - GIF
test_setup:
@mkdir -p bin
test_gif_parsed: $(SRC_FILES) test/test_gif_parsed.c
make test_setup
gcc -Wall -o bin/test_gif_parsed $(LDFLAGS) $(CFLAGS) $(SRC_FILES) test/test_gif_parsed.c
test_gif_codes: $(SRC_FILES) test/test_read_code.c
make test_setup
gcc -Wall -o bin/test_gif_codes $(LDFLAGS) $(CFLAGS) $(SRC_FILES) test/test_read_code.c
test_gif_decoded: $(SRC_FILES) test/test_gif_decoded.c
make test_setup
gcc -Wall -o bin/test_gif_decoded $(LDFLAGS) $(CFLAGS) $(ADDCFLAGS) \
$(SRC_FILES) test/test_gif_decoded.c $(IMAGE_VIEWER_TARGET)
test_gif_image: $(SRC_FILES) test/test_gif_image.c
make test_setup
gcc -Wall -o bin/test_gif_image $(LDFLAGS) $(CFLAGS) $(ADDCFLAGS) \
$(SRC_FILES) test/test_gif_image.c $(IMAGE_VIEWER_TARGET)
# Tests - PNG
test_png_chunks: $(SRC_FILES) test/test_png_chunks.c
make test_setup
gcc -Wall -o bin/test_png_chunks $(LDFLAGS) $(CFLAGS) $(SRC_FILES) test/test_png_chunks.c
test_png_parsed: $(SRC_FILES) test/test_png_parsed.c
make test_setup
gcc -Wall -o bin/test_png_parsed $(LDFLAGS) $(CFLAGS) $(SRC_FILES) test/test_png_parsed.c
test_png_decoded: $(SRC_FILES) test/test_png_decoded.c
make test_setup
gcc -Wall -o bin/test_png_decoded $(LDFLAGS) $(CFLAGS) $(ADDCFLAGS) \
$(SRC_FILES) test/test_png_decoded.c $(IMAGE_VIEWER_TARGET)
test_png_image: $(SRC_FILES) test/test_png_image.c
make test_setup
gcc -Wall -o bin/test_png_image $(LDFLAGS) $(CFLAGS) $(ADDCFLAGS) \
$(SRC_FILES) test/test_png_image.c $(IMAGE_VIEWER_TARGET)
test_image_viewer: $(SRC_FILES) test/test_image_viewer.c
make test_setup
gcc -Wall -o bin/test_image_viewer $(LDFLAGS) $(CFLAGS) $(ADDCFLAGS) \
$(SRC_FILES) test/test_image_viewer.c $(IMAGE_VIEWER_TARGET)
tests: $(SRC_FILES)
make test_gif_parsed
make test_gif_codes
make test_gif_decoded
make test_gif_image
make test_png_chunks
make test_png_parsed
make test_png_decoded
make test_png_image
make test_image_viewer