diff options
author | pankunull <panku_null@proton.me> | 2025-09-05 23:27:18 +0200 |
---|---|---|
committer | pankunull <panku_null@proton.me> | 2025-09-05 23:27:18 +0200 |
commit | 1acd14aa77268bd75afd465496bba57d6b1e5436 (patch) | |
tree | 85638a9405aab8fb67e267d699559b5582956493 /Makefile |
Initial commit
Diffstat (limited to 'Makefile')
-rw-r--r-- | Makefile | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5f352d9 --- /dev/null +++ b/Makefile @@ -0,0 +1,67 @@ +# Compiler and flags +CC = gcc +CFLAGS = -Wall -O2 + +# Directories +SRC_DIR = src +BIN_DIR = bin + +# Source and target names +TARGET = iptool +SRC = $(SRC_DIR)/$(TARGET).c +PRE = $(BIN_DIR)/$(TARGET).i +ASM = $(BIN_DIR)/$(TARGET).s +OBJ = $(BIN_DIR)/$(TARGET).o +BIN = $(BIN_DIR)/$(TARGET) + +# Example argument for test +ARG = + +# Default: build executable +all: $(BIN) + +# Ensure bin directory exists +$(BIN_DIR): + mkdir -p $(BIN_DIR) + +# Stage 1: Preprocess +$(PRE): $(SRC) | $(BIN_DIR) + $(CC) -E $(CFLAGS) $< -o $@ + +# Stage 2: Compile to assembly +$(ASM): $(PRE) + $(CC) -S $(CFLAGS) $< -o $@ + +# Stage 3: Assemble to object file +$(OBJ): $(ASM) + $(CC) -c $(CFLAGS) $< -o $@ + +# Stage 4: Link object to executable +$(BIN): $(OBJ) + $(CC) $(CFLAGS) $< -o $@ + +# Run tests +define run_test + @name="$(1) $(2)"; \ + width=40; \ + printf "%s" "$$name"; \ + dots=$$((width - $${#name})); \ + for i in $$(seq 1 $$dots); do printf "."; done; \ + ./$(BIN) $(2) >/dev/null 2>&1; \ + ec=$$?; \ + if [ $$ec -eq 0 ] || [ $$ec -eq 2 ]; then \ + echo " OK"; \ + else \ + echo " FAILED (exit $$ec)"; \ + exit 1; \ + fi +endef + +test: $(BIN) + $(call run_test,$(TARGET),no args) + $(call run_test,$(TARGET),$(ARG)) + +# Clean all generated files +clean: + rm -v -f $(BIN_DIR)/$(TARGET).* $(BIN) + |