Skip to content

Commit

Permalink
feat: Create Makefile and Update README (#41)
Browse files Browse the repository at this point in the history
* create makefile

* update cfg section
  • Loading branch information
notJoon authored Jul 31, 2024
1 parent 305fd15 commit 99fa317
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Makefile for tlin

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOCLEAN=$(GOCMD) clean
GOGET=$(GOCMD) get
BINARY_NAME=tlin
BINARY_UNIX=$(BINARY_NAME)_unix
BINARY_WINDOWS=$(BINARY_NAME).exe
BINARY_MAC=$(BINARY_NAME)_mac

# Main package path
MAIN_PACKAGE=./cmd/tlin

# Build the project
all: test build

build:
$(GOBUILD) -o $(BINARY_NAME) -v $(MAIN_PACKAGE)

# Cross compilation
build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_UNIX) -v $(MAIN_PACKAGE)

build-windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BINARY_WINDOWS) -v $(MAIN_PACKAGE)

build-mac:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BINARY_MAC) -v $(MAIN_PACKAGE)

test:
$(GOTEST) -v ./...

clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f $(BINARY_UNIX)
rm -f $(BINARY_WINDOWS)
rm -f $(BINARY_MAC)

run:
$(GOBUILD) -o $(BINARY_NAME) -v $(MAIN_PACKAGE)
./$(BINARY_NAME)

# Cross compilation
build-all: build-linux build-windows build-mac

# Dependencies
deps:
$(GOGET) -v ./...

# Install golangci-lint
install-linter:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin

# Run golangci-lint
lint:
golangci-lint run

.PHONY: all build test clean run deps build-linux build-windows build-mac build-all install-linter lint
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,34 @@ The output will show:

Use this feature to identify complex parts of your codebase that might benefit from refactoring.

## Control Flow Graph (CFG) [Experimental]

tlin supports generating control flow graphs (CFG) for functions, A CFG is a representation of all paths that might be traversed through a program during its execution.

### What is CFG?

A Control Flow Graph (CFG) is a graphical representation of the flow of control in a program. It shows:

- All possible execution paths in a function
- Basic blocks of code (sequences of instructions with no branches except at the end)
- Branching points (if statements, loops, etc.)
- Function entry and exit points

### How to Generate CFG?

To generate a CFG for a specific function, use the follow command:

```bash
tlin -cfg -func <function_name> <path>
```

Where:

- `<function_name>` is the name of the function you want to analyze
- `<file_or_directory_path>` is the path to the file or directory containing the function

When you run this command, it outputs a string in DOT format. However, exporting to a file after rendering is not yet supported.

## Contributing

We welcome all forms of contributions, including bug reports, feature requests, and pull requests. Please feel free to open an issue or submit a pull request.
Expand Down

0 comments on commit 99fa317

Please sign in to comment.