-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
77 lines (61 loc) · 2.45 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
BIN := libresplit
INC := `pkg-config --cflags gtk+-3.0 x11 jansson luajit`
CFLAGS := -std=gnu99 -O2 -pthread -Wall -Wno-unused-parameter
LDFLAGS := `pkg-config --libs gtk+-3.0 x11 jansson luajit`
SRC_DIR := ./src
OBJ_DIR := ./obj
# Obtain list of source files and create list of object files
SOURCES := $(wildcard $(SRC_DIR)/*.c)
COMPONENTS := $(wildcard $(SRC_DIR)/component/*.c)
OBJECTS := $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SOURCES)) \
$(patsubst $(SRC_DIR)/component/%.c, $(OBJ_DIR)/%.o, $(COMPONENTS))
DESTDIR :=
PREFIX := /usr/local
APP := libresplit.desktop
ICON := libresplit
SCHEMA := libresplit.gschema.xml
ifdef DESTDIR
update_icon_cache :=
compile_schemas :=
else
update_icon_cache := gtk-update-icon-cache -f -t $(PREFIX)/share/icons/hicolor
compile_schemas := glib-compile-schemas $(PREFIX)/share/glib-2.0/schemas
endif
all: main.h $(BIN)
# Rule to link object files to create executable
$(BIN): $(OBJECTS)
gcc $(CFLAGS) $^ $(LDFLAGS) -o $@
# Rule to compile C source files to object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
gcc $(INC) $(CFLAGS) -c -o $@ $<
# Rule to compile C component source files to object files
$(OBJ_DIR)/%.o: $(SRC_DIR)/component/%.c | $(OBJ_DIR)
gcc $(INC) $(CFLAGS) -c -o $@ $<
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
main.h: $(SRC_DIR)/main.css
xxd --include $(SRC_DIR)/main.css > $(SRC_DIR)/main.h || ($(RM) $(SRC_DIR)/main.h; false)
install: all
install -Dm755 $(BIN) $(DESTDIR)$(PREFIX)/bin/$(BIN)
install -Dm644 $(APP) $(DESTDIR)$(PREFIX)/share/applications/$(APP)
for size in 16 22 24 32 36 48 64 72 96 128 256 512; do \
mkdir -p $(DESTDIR)$(PREFIX)/share/icons/hicolor/"$$size"x"$$size"/apps ; \
rsvg-convert -w "$$size" -h "$$size" -f png -o $(DESTDIR)$(PREFIX)/share/icons/hicolor/"$$size"x"$$size"/apps/$(ICON).png $(ICON).svg ; \
done
$(update_icon_cache)
install -Dm644 $(SCHEMA) $(DESTDIR)$(PREFIX)/share/glib-2.0/schemas/$(SCHEMA)
$(compile_schemas)
uninstall:
$(RM) $(DESTDIR)$(PREFIX)/bin/$(BIN)
$(RM) $(DESTDIR)$(PREFIX)/share/applications/$(APP)
for size in 16 22 24 32 36 48 64 72 96 128 256 512; do \
$(RM) $(DESTDIR)$(PREFIX)/share/icons/hicolor/"$$size"x"$$size"/apps/$(ICON).png ; \
done
remove-schema:
$(RM) $(DESTDIR)$(PREFIX)/share/glib-2.0/schemas/$(SCHEMA)
$(compile_schemas)
clean:
$(RM) -r $(BIN) $(OBJ_DIR) $(SRC_DIR)/main.h
format:
clang-format -i $(SOURCES) $(COMPONENTS) $(SRC_DIR)/*.h $(SRC_DIR)/component/*.h
.PHONY: all main.h install uninstall remove-schema clean