Skip to content

Commit c92a005

Browse files
committed
Refactor Makefile for readability and maintainability
- Removed redundant expressions and manual header dependencies - Reordered variable definitions for clearer logical flow - Introduced .PHONY for pseudo-targets (all, clean, install) - Centralized configuration via variables (PROG_NAMES, EXEEXT, flags) - Simplified build rules with pattern rules (%.o, %_console.o, %_window.o) - Eliminated duplication in CLI/GUI object generation
1 parent bf0b68e commit c92a005

File tree

1 file changed

+38
-54
lines changed

1 file changed

+38
-54
lines changed

src/Makefile

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,54 @@
1-
SRCS = lzma/LzmaDec.c
2-
OBJS = $(SRCS:.c=.o) stub.res
3-
CONSOLE_OBJS = error_console.o filesystem_utils_console.o inst_dir_console.o script_info_console.o unpack_console.o
4-
WINDOW_OBJS = error_window.o filesystem_utils_window.o inst_dir_window.o script_info_window.o unpack_window.o
5-
CC = gcc
6-
BINDIR = $(CURDIR)/../share/ocran
1+
CC := gcc
2+
EXEEXT := .exe
73

8-
CFLAGS = -Wall -O2 -DWITH_LZMA -Ilzma -s
9-
STUB_CFLAGS = -D_CONSOLE $(CFLAGS)
10-
STUBW_CFLAGS = -mwindows $(CFLAGS)
11-
# -D_MBCS
4+
CFLAGS := -Wall -O2 -DWITH_LZMA -Ilzma
5+
STUB_CFLAGS := $(CFLAGS) -D_CONSOLE
6+
STUBW_CFLAGS := $(CFLAGS)
7+
LDFLAGS := -s
8+
GUI_LDFLAGS := -mwindows
129

13-
all: stub.exe stubw.exe edicon.exe
10+
BINDIR := $(CURDIR)/../share/ocran
11+
PROG_NAMES := stub stubw edicon
12+
BINARIES := $(addsuffix $(EXEEXT), $(PROG_NAMES))
1413

15-
stub.res: stub.rc
16-
windres -i stub.rc -O coff -o stub.res
17-
18-
stub.exe: $(OBJS) stub.o $(CONSOLE_OBJS)
19-
$(CC) $(STUB_CFLAGS) $(OBJS) stub.o $(CONSOLE_OBJS) -o $@
20-
21-
stubw.exe: $(OBJS) stubw.o $(WINDOW_OBJS)
22-
$(CC) $(STUBW_CFLAGS) $(OBJS) stubw.o $(WINDOW_OBJS) -o $@
23-
24-
edicon.exe: edicon.o
25-
$(CC) $(CFLAGS) edicon.o -o edicon
14+
LZMA_SRCS := lzma/LzmaDec.c
15+
LZMA_OBJS := $(LZMA_SRCS:.c=.o)
2616

27-
error_console.o: error.c error.h
28-
$(CC) $(STUB_CFLAGS) -o $@ -c $<
17+
COMMON_SRCS := filesystem_utils.c inst_dir.c script_info.c unpack.c
18+
COMMON_OBJS := $(COMMON_SRCS:.c=.o) $(LZMA_OBJS) stub.res
2919

30-
error_window.o: error.c error.h
31-
$(CC) $(STUBW_CFLAGS) -o $@ -c $<
20+
VARIANT_SRCS := stub.c error.c
21+
CONSOLE_OBJS := $(VARIANT_SRCS:.c=_console.o)
22+
WINDOW_OBJS := $(VARIANT_SRCS:.c=_window.o)
3223

33-
stub.o: stub.c stub.h
34-
$(CC) $(STUB_CFLAGS) -o $@ -c $<
24+
.PHONY: all clean install
25+
all: $(BINARIES)
3526

36-
stubw.o: stub.c stub.h
37-
$(CC) $(STUBW_CFLAGS) -o $@ -c $<
27+
%.o: %.c
28+
$(CC) $(CFLAGS) -c $< -o $@
3829

39-
unpack_console.o: unpack.c unpack.h
40-
$(CC) $(STUB_CFLAGS) -o $@ -c $<
30+
%_console.o: %.c
31+
$(CC) $(STUB_CFLAGS) -c $< -o $@
4132

42-
unpack_window.o: unpack.c unpack.h
43-
$(CC) $(STUBW_CFLAGS) -o $@ -c $<
33+
%_window.o: %.c
34+
$(CC) $(STUBW_CFLAGS) -c $< -o $@
4435

45-
filesystem_utils_console.o: filesystem_utils.c filesystem_utils.h
46-
$(CC) $(STUB_CFLAGS) -o $@ -c $<
47-
48-
filesystem_utils_window.o: filesystem_utils.c filesystem_utils.h
49-
$(CC) $(STUBW_CFLAGS) -o $@ -c $<
50-
51-
inst_dir_console.o: inst_dir.c inst_dir.h
52-
$(CC) $(STUB_CFLAGS) -o $@ -c $<
36+
stub.res: stub.rc
37+
windres -i stub.rc -O coff -o stub.res
5338

54-
inst_dir_window.o: inst_dir.c inst_dir.h
55-
$(CC) $(STUBW_CFLAGS) -o $@ -c $<
39+
stub$(EXEEXT): $(COMMON_OBJS) $(CONSOLE_OBJS)
40+
$(CC) $(LDFLAGS) $^ -o $@
5641

57-
script_info_console.o: script_info.c script_info.h
58-
$(CC) $(STUB_CFLAGS) -o $@ -c $<
42+
stubw$(EXEEXT): $(COMMON_OBJS) $(WINDOW_OBJS)
43+
$(CC) $(LDFLAGS) $(GUI_LDFLAGS) $^ -o $@
5944

60-
script_info_window.o: script_info.c script_info.h
61-
$(CC) $(STUBW_CFLAGS) -o $@ -c $<
45+
edicon$(EXEEXT): edicon.o
46+
$(CC) $(LDFLAGS) $^ -o $@
6247

6348
clean:
64-
rm -f $(OBJS) stub.exe stubw.exe edicon.exe edicon.o stubw.o stub.o \
65-
$(CONSOLE_OBJS) $(WINDOW_OBJS)
49+
rm -f $(BINARIES) $(COMMON_OBJS) $(CONSOLE_OBJS) $(WINDOW_OBJS) \
50+
edicon.o
6651

67-
install: stub.exe stubw.exe edicon.exe
68-
cp -f stub.exe $(BINDIR)/stub.exe
69-
cp -f stubw.exe $(BINDIR)/stubw.exe
70-
cp -f edicon.exe $(BINDIR)/edicon.exe
52+
install: $(BINARIES)
53+
mkdir -p $(BINDIR)
54+
cp -f $(BINARIES) $(BINDIR)/

0 commit comments

Comments
 (0)