Skip to content

Commit 2a4c1aa

Browse files
committed
build: improve Makefile builds
1 parent fdfdfa0 commit 2a4c1aa

2 files changed

Lines changed: 41 additions & 37 deletions

File tree

Makefile

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -64,62 +64,62 @@ NAME = oshot
6464
TARGET ?= $(NAME)
6565
OLDVERSION = 0.4.2
6666
VERSION = 0.4.3
67-
SRC = $(wildcard src/*.cpp)
68-
OBJ = $(SRC:.cpp=.o)
67+
SRC = $(wildcard src/*.cpp)
68+
OBJ = $(patsubst src/%.cpp,$(BUILDDIR)/%.o,$(SRC))
6969
LDFLAGS += -L$(BUILDDIR) $(LTO_FLAGS)
70-
LDLIBS += $(wildcard $(BUILDDIR)/*.a) `pkg-config --static --libs glfw3 tesseract zbar`
70+
LDLIBS += $(LIBS) `pkg-config --static --libs glfw3 tesseract zbar`
7171
CXXFLAGS += $(LTO_FLAGS) -fvisibility-inlines-hidden -fvisibility=hidden -Iinclude -Iinclude/libs -std=$(CXXSTD) $(VARS) -DVERSION=\"$(VERSION)\"
7272

73-
all: imgui fmt tfd tpl clip tray getopt-port toml $(TARGET)
73+
LIBS = \
74+
$(BUILDDIR)/libimgui.a \
75+
$(BUILDDIR)/libfmt.a \
76+
$(BUILDDIR)/libclip.a \
77+
$(BUILDDIR)/libtray.a \
78+
$(BUILDDIR)/libtiny-process-library.a
7479

75-
imgui:
76-
ifeq ($(wildcard $(BUILDDIR)/libimgui.a),)
80+
OBJ += \
81+
$(BUILDDIR)/toml.o \
82+
$(BUILDDIR)/tinyfiledialogs.o \
83+
$(BUILDDIR)/getopt.o
84+
85+
all: $(BUILDDIR)/$(TARGET)
86+
87+
$(BUILDDIR):
7788
mkdir -p $(BUILDDIR)
89+
90+
$(BUILDDIR)/%.o: src/%.cpp
91+
@mkdir -p $(dir $@)
92+
$(CXX) $(CXXFLAGS) -c $< -o $@
93+
94+
$(BUILDDIR)/libimgui.a: | $(BUILDDIR)
7895
$(MAKE) -C src/libs/imgui BUILDDIR=$(BUILDDIR) CXXSTD=$(CXXSTD) DEBUG=$(DEBUG)
79-
endif
8096

81-
fmt:
82-
ifeq ($(wildcard $(BUILDDIR)/libfmt.a),)
83-
mkdir -p $(BUILDDIR)
97+
$(BUILDDIR)/libfmt.a: | $(BUILDDIR)
8498
$(MAKE) -C src/libs/fmt BUILDDIR=$(BUILDDIR) CXXSTD=$(CXXSTD) DEBUG=$(DEBUG)
85-
endif
8699

87-
toml:
88-
ifeq ($(wildcard $(BUILDDIR)/toml.o),)
100+
$(BUILDDIR)/toml.o:
89101
$(MAKE) -C src/libs/toml++ BUILDDIR=$(BUILDDIR) CXXSTD=$(CXXSTD) DEBUG=$(DEBUG)
90-
endif
91102

92-
clip:
93-
ifeq ($(wildcard $(BUILDDIR)/libclip.a),)
103+
$(BUILDDIR)/libclip.a:
94104
$(MAKE) -C src/libs/clip BUILDDIR=$(BUILDDIR) CXXSTD=$(CXXSTD) DEBUG=$(DEBUG)
95-
endif
96105

97-
tray:
98-
ifeq ($(wildcard $(BUILDDIR)/libtray.a),)
106+
$(BUILDDIR)/libtray.a:
99107
$(MAKE) -C src/libs/tray BUILDDIR=$(BUILDDIR) CXXSTD=$(CXXSTD) DEBUG=$(DEBUG)
100-
endif
101108

102-
tfd:
103-
ifeq ($(wildcard $(BUILDDIR)/tinyfiledialogs.o),)
109+
$(BUILDDIR)/tinyfiledialogs.o:
104110
$(MAKE) -C src/libs/tinyfiledialogs BUILDDIR=$(BUILDDIR)
105-
endif
106111

107-
tpl:
108-
ifeq ($(wildcard $(BUILDDIR)/libtiny-process-library.a),)
112+
$(BUILDDIR)/libtiny-process-library.a:
109113
$(MAKE) -C src/libs/tiny-process-library BUILDDIR=$(BUILDDIR) CXXSTD=$(CXXSTD) DEBUG=$(DEBUG)
110-
endif
111114

112-
getopt-port:
113-
ifeq ($(wildcard $(BUILDDIR)/getopt.o),)
115+
$(BUILDDIR)/getopt.o:
114116
$(MAKE) -C src/libs/getopt_port BUILDDIR=$(BUILDDIR)
115-
endif
116117

117-
genver: ./scripts/generateVersion.sh
118+
genver:
118119
./scripts/generateVersion.sh
119120

120-
$(TARGET): genver fmt toml tfd tpl clip tray getopt-port $(OBJ)
121-
mkdir -p $(BUILDDIR)
122-
$(CXX) -o $(BUILDDIR)/$(TARGET) $(OBJ) $(BUILDDIR)/*.o $(LDFLAGS) $(LDLIBS)
121+
$(BUILDDIR)/$(TARGET): genver $(OBJ) $(LIBS)
122+
$(CXX) -o $@ $(OBJ) $(LDFLAGS) $(LDLIBS)
123123

124124
dist: $(TARGET)
125125
zip -j $(NAME)-v$(VERSION).zip LICENSE README.md $(BUILDDIR)/$(TARGET)

src/libs/fmt/Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ CXXSTD ?= c++20
77
# CXX_DEFINES = -DFMT_LIB_EXPORT -Dfmt_EXPORTS
88
CXXFLAGS = -I../../../include/libs -std=$(CXXSTD) $(LTO_FLAGS) -fvisibility=hidden -fvisibility-inlines-hidden -fPIC
99

10+
OBJ = format.cc.o os.cc.o
11+
1012
ifeq ($(DEBUG),1)
1113
CXXFLAGS := -ggdb3 -Wall -Wextra -pedantic -Wno-unused-parameter \
1214
-DDEBUG=1 -fno-omit-frame-pointer $(DEBUG_CXXFLAGS) $(CXXFLAGS)
@@ -16,13 +18,15 @@ endif
1618

1719
all: fmt
1820

19-
fmt: format.cc os.cc
20-
$(CXX) $(CXX_DEFINES) $(CXXFLAGS) -c format.cc -o format.cc.o
21-
$(CXX) $(CXX_DEFINES) $(CXXFLAGS) -c os.cc -o os.cc.o
22-
ar qc libfmt.a os.cc.o format.cc.o
21+
fmt: $(OBJ)
22+
ar qc libfmt.a $(OBJ)
2323
ranlib libfmt.a
24+
mkdir -p ../../../$(BUILDDIR)
2425
mv -f libfmt.a ../../../$(BUILDDIR)/libfmt.a
2526

27+
%.cc.o: %.cc
28+
$(CXX) $(CXX_DEFINES) $(CXXFLAGS) -c $< -o $@
29+
2630
clean:
2731
rm -f *.o *.so *.a ../../../$(BUILDDIR)/fmt/.*a
2832

0 commit comments

Comments
 (0)