Skip to content

Commit 403a23c

Browse files
committed
Makefile: isolate build artifacts and use build dir
Previously, object files, binaries, and generated headers like .version.h were created directly in the project root. This cluttered the source tree and made it difficult to maintain separate debug and release builds. It also risked file collisions when switching build types or performing parallel builds. * Introduced a unified build directory structure: build/ release/ bin/ - final executables obj/ - object files gen/ - generated headers (e.g., version.h) debug/ ... * Added BUILD_TYPE variable (defaults to "debug") with make debug and make release targets. Signed-off-by: Igor Opaniuk <[email protected]>
1 parent 8c0fd74 commit 403a23c

File tree

4 files changed

+54
-28
lines changed

4 files changed

+54
-28
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
sudo apt-get install -y libxml2-dev libusb-1.0-0-dev
2626
2727
- name: Build
28-
run: make
28+
run: make all
2929

3030
- name: Run tests
3131
run: make tests
@@ -35,7 +35,7 @@ jobs:
3535
mkdir dist
3636
cp `pkg-config --variable=libdir libusb-1.0`/libusb-1.0.so.0 dist
3737
chmod 0644 dist/*
38-
cp qdl dist
38+
cp ./build/release/qdl dist
3939
patchelf --set-rpath '$ORIGIN' dist/qdl
4040
4141
- name: Upload artifact
@@ -63,7 +63,7 @@ jobs:
6363
brew install libxml2
6464
6565
- name: Build
66-
run: make
66+
run: make all
6767

6868
- name: Run tests
6969
run: make tests
@@ -75,7 +75,7 @@ jobs:
7575
cp `pkg-config --variable=libdir libusb-1.0`/libusb-1.0.0.dylib dist
7676
cp `pkg-config --variable=libdir liblzma`/liblzma.5.dylib dist
7777
chmod 0644 dist/*
78-
cp qdl dist
78+
cp ./build/release/bin/qdl dist
7979
8080
if uname -a | grep -q arm64; then
8181
LIBUSB_DIR=/opt/homebrew/opt/libusb/lib
@@ -124,7 +124,7 @@ jobs:
124124
mingw-w64-x86_64-libusb
125125
126126
- name: Build
127-
run: make
127+
run: make all
128128
shell: msys2 {0}
129129

130130
- name: Run tests
@@ -145,7 +145,7 @@ jobs:
145145
Copy-Item (Join-Path $BIN_DIR "liblzma-5.dll") $DistDir
146146
Copy-Item (Join-Path $BIN_DIR "libiconv-2.dll") $DistDir
147147
148-
Copy-Item "qdl.exe" $DistDir
148+
Copy-Item "./build/release/bin/qdl.exe" $DistDir
149149
150150
- name: Upload artifact
151151
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/build/
2+
/tests/data/*.elf
3+
/tests/data/*.bin
4+
/tests/data/*.img
15
*.o
26
qdl
37
qdl-ramdump
@@ -7,5 +11,5 @@ compile_commands.json
711
.cache
812
.version.h
913
version.h
10-
scripts
14+
.scripts
1115
.checkpatch-camelcase.git.

Makefile

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
QDL := qdl
2-
RAMDUMP := qdl-ramdump
31
VERSION := $(or $(VERSION), $(shell git describe --dirty --always --tags 2>/dev/null), "unknown-version")
42

5-
CFLAGS += -O2 -Wall -g `pkg-config --cflags libxml-2.0 libusb-1.0`
3+
CFLAGS += -Wall `pkg-config --cflags libxml-2.0 libusb-1.0`
64
LDFLAGS += `pkg-config --libs libxml-2.0 libusb-1.0`
75
ifeq ($(OS),Windows_NT)
86
LDFLAGS += -lws2_32
97
endif
108
prefix := /usr/local
119

10+
# Default build type
11+
BUILD_TYPE ?= debug
12+
BUILD_DIR = build/$(BUILD_TYPE)
13+
OBJ_DIR = $(BUILD_DIR)/obj
14+
BIN_DIR = $(BUILD_DIR)/bin
15+
GEN_DIR = $(BUILD_DIR)/gen
16+
17+
QDL := qdl
1218
QDL_SRCS := firehose.c io.c qdl.c sahara.c util.c patch.c program.c read.c sha2.c sim.c ufs.c usb.c ux.c oscompat.c vip.c sparse.c gpt.c
13-
QDL_OBJS := $(QDL_SRCS:.c=.o)
19+
QDL_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(QDL_SRCS:.c=.o)))
1420

21+
RAMDUMP := qdl-ramdump
1522
RAMDUMP_SRCS := ramdump.c sahara.c io.c sim.c usb.c util.c ux.c oscompat.c
16-
RAMDUMP_OBJS := $(RAMDUMP_SRCS:.c=.o)
23+
RAMDUMP_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(RAMDUMP_SRCS:.c=.o)))
1724

1825
KS_OUT := ks
1926
KS_SRCS := ks.c sahara.c util.c ux.c oscompat.c
20-
KS_OBJS := $(KS_SRCS:.c=.o)
27+
KS_OBJS = $(addprefix $(OBJ_DIR)/, $(notdir $(KS_SRCS:.c=.o)))
2128

2229
CHECKPATCH_SOURCES := $(shell find . -type f \( -name "*.c" -o -name "*.h" -o -name "*.sh" \) ! -name "sha2.c" ! -name "sha2.h" ! -name "*version.h" ! -name "list.h")
2330
CHECKPATCH_ROOT := https://raw.githubusercontent.com/torvalds/linux/v6.15/scripts
@@ -26,41 +33,55 @@ CHECKPATCH_SP_URL := $(CHECKPATCH_ROOT)/spelling.txt
2633
CHECKPATCH := ./.scripts/checkpatch.pl
2734
CHECKPATCH_SP := ./.scripts/spelling.txt
2835

29-
default: $(QDL) $(RAMDUMP) $(KS_OUT)
36+
default: debug
37+
all: debug release
38+
39+
release:
40+
$(MAKE) BUILD_TYPE=release CFLAGS='$(CFLAGS) -O2 -Ibuild/release/gen' _all_internal
41+
42+
debug:
43+
$(MAKE) BUILD_TYPE=debug CFLAGS='$(CFLAGS) -O0 -g -Ibuild/debug/gen' _all_internal
44+
45+
# Inner target that actually builds things with the chosen BUILD_TYPE
46+
_all_internal: dirs $(BIN_DIR)/$(QDL) $(BIN_DIR)/$(RAMDUMP) $(BIN_DIR)/$(KS_OUT)
47+
48+
dirs:
49+
@mkdir -p $(OBJ_DIR) $(BIN_DIR) $(GEN_DIR)
50+
51+
$(OBJ_DIR)/%.o: %.c
52+
$(CC) $(CFLAGS) -c $< -o $@
3053

31-
$(QDL): $(QDL_OBJS)
54+
$(BIN_DIR)/$(QDL): $(QDL_OBJS)
3255
$(CC) -o $@ $^ $(LDFLAGS)
3356

34-
$(RAMDUMP): $(RAMDUMP_OBJS)
57+
$(BIN_DIR)/$(RAMDUMP): $(RAMDUMP_OBJS)
3558
$(CC) -o $@ $^ $(LDFLAGS)
3659

37-
$(KS_OUT): $(KS_OBJS)
60+
$(BIN_DIR)/$(KS_OUT): $(KS_OBJS)
3861
$(CC) -o $@ $^ $(LDFLAGS)
3962

4063
compile_commands.json: $(QDL_SRCS) $(KS_SRCS)
4164
@echo -n $^ | jq -snR "[inputs|split(\" \")[]|{directory:\"$(PWD)\", command: \"$(CC) $(CFLAGS) -c \(.)\", file:.}]" > $@
4265

43-
version.h::
44-
@echo "#define VERSION \"$(VERSION)\"" > .version.h
45-
@cmp -s .version.h version.h || cp .version.h version.h
66+
$(GEN_DIR)/version.h:
67+
@echo "#define VERSION \"$(VERSION)\"" > $(GEN_DIR)/.version.h
68+
@cmp -s $(GEN_DIR)/.version.h $(GEN_DIR)/version.h || cp $(GEN_DIR)/.version.h $(GEN_DIR)/version.h
4669

47-
util.o: version.h
70+
$(OBJ_DIR)/util.o: $(GEN_DIR)/version.h
4871

4972
clean:
50-
rm -f $(QDL) $(QDL_OBJS)
51-
rm -f $(RAMDUMP) $(RAMDUMP_OBJS)
52-
rm -f $(KS_OUT) $(KS_OBJS)
73+
rm -rf build
5374
rm -f compile_commands.json
5475
rm -f version.h .version.h
5576
rm -f $(CHECKPATCH)
5677
rm -f $(CHECKPATCH_SP)
5778
if [ -d .scripts ]; then rmdir .scripts; fi
5879

59-
install: $(QDL) $(RAMDUMP) $(KS_OUT)
80+
install: release
6081
install -d $(DESTDIR)$(prefix)/bin
61-
install -m 755 $^ $(DESTDIR)$(prefix)/bin
82+
install -m 755 $(BIN_DIR)/$(QDL) $(BIN_DIR)/$(RAMDUMP) $(BIN_DIR)/$(KS_OUT) $(DESTDIR)$(prefix)/bin
6283

63-
tests: default
84+
tests: debug
6485
tests:
6586
@./tests/run_tests.sh
6687

tests/test_vip_generation.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
88
FLAT_BUILD=${SCRIPT_PATH}/data
99

1010
REP_ROOT=${SCRIPT_PATH}/..
11+
QDL_PATH=${REP_ROOT}/build/debug/bin
1112
VIP_PATH=${FLAT_BUILD}/vip
1213
EXPECTED_DIGEST="a05e1124edbe34dc504a327544fb66572591353dc3fa25e6e7eafbe4803e63e0"
1314
VIP_TABLE_FILE=${VIP_PATH}/DigestsToSign.bin
1415

1516
mkdir -p $VIP_PATH
1617

1718
cd $FLAT_BUILD
18-
${REP_ROOT}/qdl --dry-run --create-digests=${VIP_PATH} \
19+
${QDL_PATH}/qdl --dry-run --create-digests=${VIP_PATH} \
1920
prog_firehose_ddr.elf rawprogram*.xml patch*.xml
2021

2122
if command -v sha256sum >/dev/null 2>&1; then

0 commit comments

Comments
 (0)