A make-file parser for windows user.
Project description
Makefile Parser
makefile-parser is a Python utility designed to parse GNU Makefiles and extract variables, targets, and their associated commands. It processes variable assignments, resolves variable substitutions, and provides a structured representation of the Makefile content. This tool is especially useful for developers who need to analyze or manipulate Makefiles programmatically.
Features:
-
Parse Variable Assignments: Supports both = and := assignment operators.
-
Resolve Variable Substitutions: Handles recursive variable substitution within variable values and command lines.
-
Extract Targets and Commands: Captures all targets (rules) along with their associated commands, including multi-line commands and conditionals.
-
Handle Conditional Statements: Includes non-indented lines like ifeq, else, and endif within targets.
-
Provide Structured Output: Returns a dictionary containing variables and rules for easy programmatic access.
Sample Input and Output:
Example
Makefile
CC = gcc
CFLAGS = -Wall -g
SRC_DIR = src
BUILD_DIR = build
all: build
build:
mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) $(SRC_DIR)/main.c -o $(BUILD_DIR)/main
command
parse_make -f .\Makefile -c build
output
mkdir -p build gcc -Wall -g src/main.c -o build/main
Example:02
Sample Makefile
# Variables
CXX = g++
CXXFLAGS = -Wall -Wextra -std=c++17 -g
SRC_DIR = src
BUILD_DIR = build
INCLUDE_DIR = include
TARGET = $(BUILD_DIR)/complex_program
# Automatic variables
SRCS = $(wildcard $(SRC_DIR)/*.cpp)
OBJS = $(SRCS:$(SRC_DIR)/%.cpp=$(BUILD_DIR)/%.o)
# Phony targets
.PHONY: all clean rebuild run
# Default target
all: $(TARGET)
# Linking the target
$(TARGET): $(OBJS)
@echo "Linking $(TARGET)..."
$(CXX) $(CXXFLAGS) -I$(INCLUDE_DIR) $^ -o $@ \
&& echo "Build successful!" \
|| echo "Build failed!"
# Compiling source files to object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(BUILD_DIR)
@echo "Compiling $<..."
$(CXX) $(CXXFLAGS) -I$(INCLUDE_DIR) -c $< -o $@
# Cleaning build files
clean:
@echo "Cleaning up..."
@rm -rf $(BUILD_DIR) && echo "Clean complete!" || echo "Clean failed!"
# Rebuilding the project
rebuild: clean all
# Running the program
run: all
@echo "Running $(TARGET)..."
@./$(TARGET)
# Catch-all target for invalid targets
%:
@echo "Error: Unknown target '$@'."
@echo "Available targets: all, clean, rebuild, run"
command
- When no target command is given:
parse_make -f .\Makefile
output
Variables:
ROOT_DIR = C:\Users\sponnuru\PycharmProjects\make-parser
CXX = g++
CXXFLAGS = -Wall -Wextra -std=c++17 -g
SRC_DIR = src
BUILD_DIR = build
INCLUDE_DIR = include
TARGET = build/complex_program
SRCS = $(wildcard src/*.cpp)
OBJS = $(SRCS:src/%.cpp=build/%.o)
Rules:
all:
build/complex_program: $(SRCS:src/%.cpp=build/%.o)
@echo "Linking build/complex_program..."
g++ -Wall -Wextra -std=c++17 -g -Iinclude $^ -o $@ && echo "Build successful!" || echo "Build failed!"
build/%.o: src/%.cpp
@mkdir -p build
@echo "Compiling $<..."
g++ -Wall -Wextra -std=c++17 -g -Iinclude -c $< -o $@
clean:
@echo "Cleaning up..."
@rm -rf build && echo "Clean complete!" || echo "Clean failed!"
rebuild:
run:
@echo "Running build/complex_program..."
@./build/complex_program
%:
@echo "Error: Unknown target '$@'."
@echo "Available targets: all, clean, rebuild, run"
- When a wrong target command is given:
parse_make -f .\Makefile -c wrong
output
The command "wrong" does not exist, please re-check the target command.
Requirements:
- Python >= 3.6
Installation:
Pip
pip install make-parser
git repository
https://github.com/pssv7/make-parser.git
Usage
parse_make -d [PATH_TO_MAKEFILE] -c [TARGET_COMMAND](OPTIONAL)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file make_parser-0.1.2.tar.gz.
File metadata
- Download URL: make_parser-0.1.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae3836ca1519f8d20be4d42c13f876adc014bb2d7aadb1aba3601329fb1f486b
|
|
| MD5 |
f79b60c2140aaa0aaabd026bb250fc65
|
|
| BLAKE2b-256 |
d021d8b13cf1c8a5e0700702871f09f2eec254908f54d13a5ca8d7716481eea2
|
File details
Details for the file make_parser-0.1.2-py3-none-any.whl.
File metadata
- Download URL: make_parser-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccc8ee4df0fd05f4132b64f854fa4f09bc9ec9565b4805b55e5bfae76f052498
|
|
| MD5 |
f0cea87bec1d420a0a1be59c24403c37
|
|
| BLAKE2b-256 |
c8d8d72199e114de117f09307e9235acb8b12115f18fa786ccebc3242a76ff43
|