-
Notifications
You must be signed in to change notification settings - Fork 162
Reorganize project structure for better maintainability in multi-platform support #246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| # --- Basic Configuration --- | ||
| CC ?= gcc | ||
| CFLAGS += -std=c99 -Wall -Wextra -pedantic -MMD -ggdb | ||
| CFLAGS += -std=c99 -Wall -Wextra -pedantic -ggdb -Iinclude/f3 | ||
|
|
||
| TARGETS = f3write f3read | ||
| EXTRA_TARGETS = f3probe f3brew f3fix | ||
|
|
@@ -9,6 +10,7 @@ INSTALL = install | |
| LN = ln | ||
| UNLINK = unlink | ||
|
|
||
| # --- OS Detection --- | ||
| ifndef OS | ||
| OS = $(shell uname -s) | ||
| endif | ||
|
|
@@ -23,22 +25,56 @@ ifneq ($(OS), Linux) | |
| LDFLAGS += -L$(ARGP)/lib -largp | ||
| endif | ||
|
|
||
| all: $(TARGETS) | ||
| extra: $(EXTRA_TARGETS) | ||
| # --- Output Directory Setup --- | ||
| BUILD_DIR := build | ||
| BIN_DIR := $(BUILD_DIR)/bin | ||
| OBJ_DIR := $(BUILD_DIR)/obj | ||
|
|
||
| BIN_TARGETS := $(addprefix $(BIN_DIR)/,$(TARGETS)) | ||
| BIN_EXTRAS := $(addprefix $(BIN_DIR)/,$(EXTRA_TARGETS)) | ||
|
|
||
| # Source directories and automatic search rules | ||
| SRC_DIRS = src/f3 src/f3-extra | ||
| vpath %.c $(SRC_DIRS) | ||
|
|
||
| # Find source files relative to source root and map them to object paths in OBJ_DIR | ||
| TARGET_SRCS := $(wildcard $(addsuffix /*.c, $(SRC_DIRS))) | ||
| TARGET_OBJS := $(patsubst src/%.c,$(OBJ_DIR)/%.o,$(TARGET_SRCS)) | ||
|
|
||
| # Reusable object lists | ||
| F3_LIB_OBJS := $(patsubst src/%.c,$(OBJ_DIR)/%.o,$(wildcard src/f3/lib/*.c)) | ||
| F3_EXTRA_LIB_OBJS := $(patsubst src/%.c,$(OBJ_DIR)/%.o,$(wildcard src/f3-extra/lib/*.c)) | ||
|
|
||
| ALL_OBJS := $(TARGET_OBJS) $(F3_LIB_OBJS) $(F3_EXTRA_LIB_OBJS) | ||
|
|
||
| # --- Dependency Inclusion --- | ||
| DEPFLAGS = -MMD -MT $@ -MP -MF $(@:.o=.d) | ||
| ALL_DEPS := $(ALL_OBJS:.o=.d) | ||
| -include $(ALL_DEPS) | ||
|
|
||
| # --- Pattern Rule for Compilation --- | ||
| $(OBJ_DIR)/%.o: src/%.c | $(OBJ_DIR) | ||
| @mkdir -p $(@D) | ||
| $(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@ | ||
|
|
||
| # --- Main Build Targets --- | ||
| all: $(BIN_TARGETS) | ||
| extra: $(BIN_EXTRAS) | ||
|
|
||
| docker: | ||
| docker build -f Dockerfile -t f3:latest . | ||
|
|
||
| # --- Installation Targets --- | ||
| install: all | ||
| $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin | ||
| $(INSTALL) -m755 $(TARGETS) $(DESTDIR)$(PREFIX)/bin | ||
| $(INSTALL) -m755 $(BIN_TARGETS) $(DESTDIR)$(PREFIX)/bin | ||
| $(INSTALL) -d $(DESTDIR)$(PREFIX)/share/man/man1 | ||
| $(INSTALL) -m644 f3read.1 $(DESTDIR)$(PREFIX)/share/man/man1 | ||
| $(LN) -sf f3read.1 $(DESTDIR)$(PREFIX)/share/man/man1/f3write.1 | ||
|
|
||
| install-extra: extra | ||
| $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin | ||
| $(INSTALL) -m755 $(EXTRA_TARGETS) $(DESTDIR)$(PREFIX)/bin | ||
| $(INSTALL) -m755 $(BIN_EXTRAS) $(DESTDIR)$(PREFIX)/bin | ||
|
|
||
| uninstall: uninstall-extra | ||
| cd $(DESTDIR)$(PREFIX)/bin ; rm $(TARGETS) | ||
|
|
@@ -48,27 +84,33 @@ uninstall: uninstall-extra | |
| uninstall-extra: | ||
| cd $(DESTDIR)$(PREFIX)/bin ; rm $(EXTRA_TARGETS) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the changes, have you tested the targets |
||
|
|
||
| f3write: utils.o libflow.o f3write.o | ||
| # --- Directory Targets --- | ||
| $(BUILD_DIR): ; @mkdir -p $@ | ||
| $(BIN_DIR): | $(BUILD_DIR) ; @mkdir -p $@ | ||
| $(OBJ_DIR): | $(BUILD_DIR) ; @mkdir -p $@ | ||
|
|
||
| # --- Binary Linking Rules --- | ||
| $(BIN_DIR)/f3write: $(OBJ_DIR)/f3/f3write.o $(F3_LIB_OBJS) | $(BIN_DIR) | ||
| $(CC) -o $@ $^ $(LDFLAGS) -lm | ||
|
|
||
| f3read: utils.o libflow.o f3read.o | ||
| $(BIN_DIR)/f3read: $(OBJ_DIR)/f3/f3read.o $(F3_LIB_OBJS) | $(BIN_DIR) | ||
| $(CC) -o $@ $^ $(LDFLAGS) -lm | ||
|
|
||
| f3probe: libutils.o libdevs.o libprobe.o f3probe.o | ||
| $(BIN_DIR)/f3probe: $(OBJ_DIR)/f3-extra/f3probe.o $(F3_EXTRA_LIB_OBJS) | $(BIN_DIR) | ||
| $(CC) -o $@ $^ $(LDFLAGS) -lm -ludev | ||
|
|
||
| f3brew: libutils.o libdevs.o f3brew.o | ||
| $(BIN_DIR)/f3brew: $(OBJ_DIR)/f3-extra/f3brew.o $(F3_EXTRA_LIB_OBJS) | $(BIN_DIR) | ||
| $(CC) -o $@ $^ $(LDFLAGS) -lm -ludev | ||
|
|
||
| f3fix: libutils.o f3fix.o | ||
| $(BIN_DIR)/f3fix: $(OBJ_DIR)/f3-extra/f3fix.o $(F3_EXTRA_LIB_OBJS) | $(BIN_DIR) | ||
| $(CC) -o $@ $^ $(LDFLAGS) -lparted | ||
|
|
||
| -include *.d | ||
|
|
||
| .PHONY: cscope clean uninstall uninstall-extra | ||
| # --- Cleanup and Maintenance Targets --- | ||
| .PHONY: all extra docker install install-extra uninstall uninstall-extra cscope clean | ||
|
|
||
| cscope: | ||
| cscope -b *.c *.h | ||
| cscope -b src/**/*.c include/**/*.h | ||
|
|
||
| clean: | ||
| rm -f *.o *.d cscope.out $(TARGETS) $(EXTRA_TARGETS) | ||
| @rm -rf $(BUILD_DIR) | ||
| @rm -f cscope.out | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new binaries' location breaks the GitHub workflow. Please update the workflow file
.github/workflows/test.yml.