Skip to content

Commit

Permalink
Redesign planning and setup refactor (#3)
Browse files Browse the repository at this point in the history
* Set version mechanism to config.mk

* Refactor Makefile, add CPPLINT

* First iteration of CI github Action

* Rollback action cpplint version to 1.6.1

* Add bagde of action to readme

* Superficial requirement analysis

* Refactor dist to be placed within build folder

* Remove clean dep in Makefile from dist

* Add dist step to CI

* Normalise paranthesization in Makefile

* Adopt Google Styleguide

* Add cppcheck to linting

* Add to wishlist of new version of egc
  • Loading branch information
cpmachado authored Oct 20, 2024
1 parent 828663a commit 2f6c923
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 251 deletions.
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2

[Makefile]
indent_style = tab
indent_size = 4
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'
- run: pip install cpplint===1.6.1
- run: sudo apt install cppcheck -y
- run: make lint
dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make dist
14 changes: 2 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
# Tarballs
*.zip
*.tar.gz

# binaries
*.o
*.a
*.d
egc

# user config.h
config.h
# build folder
build

# tags
tags
1 change: 1 addition & 0 deletions CPPLINT.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set noparent
85 changes: 49 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,77 @@

include config.mk

# Files for distribution
PKGFILES = \
CPPLINT.cfg\
LICENSE\
Makefile\
README.md\
config.mk\
doc\
egc.c\
man
man\
src

SRC = egc.c
OBJ = ${SRC:.c=.o}
BIN = egc
SRC_DIR = src
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
BIN_DIR = $(BUILD_DIR)/bin
DIST_DIR = $(BUILD_DIR)/dist
DIST_BASE_DIR = $(DIST_DIR)/egc-$(VERSION)

SRC = $(wildcard $(SRC_DIR)/*.c)
OBJ = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o, $(SRC))
BIN = $(BIN_DIR)/egc

all: ${BIN}
@echo "egc built"

all: $(BIN)
@echo "egc built"

clean:
@echo cleaning
@rm -rf ${OBJ} ${DEP} ${BIN} *.tar.gz *.zip
@rm -rf $(BUILD_DIR)

lint:
cpplint egc.c
@cppcheck $(SRC_DIR)
@cpplint --recursive $(SRC_DIR)

options:
@echo "egc compilation flags"
@echo "VERSION = ${VERSION}"
@echo "CC = ${CC}"
@echo "CFLAGS = ${CFLAGS}"
@echo "CPPFLAGS = ${CPPFLAGS}"
@echo "LDFLAGS = ${LDFLAGS}"
@echo "SRC = ${SRC}"
@echo "OBJ = ${OBJ}"
@echo "BIN = ${BIN}"


dist: clean
mkdir -p egc-${VERSION}
cp -r ${PKGFILES} egc-${VERSION}
tar -cz -f egc-${VERSION}.tar.gz egc-${VERSION}
zip -r egc-${VERSION}.zip egc-${VERSION}
rm -r egc-${VERSION}
@echo "VERSION = $(VERSION)"
@echo "CC = $(CC)"
@echo "CFLAGS = $(CFLAGS)"
@echo "CPPFLAGS = $(CPPFLAGS)"
@echo "LDFLAGS = $(LDFLAGS)"
@echo "SRC = $(SRC)"
@echo "OBJ = $(OBJ)"
@echo "BIN = $(BIN)"


dist:
mkdir -p $(DIST_BASE_DIR)
cp -r $(PKGFILES) $(DIST_BASE_DIR)
tar -cz -f $(DIST_BASE_DIR).tar.gz $(DIST_BASE_DIR)
zip -r $(DIST_BASE_DIR).zip $(DIST_BASE_DIR)

install: egc
@echo installing executable file to ${PREFIX}/bin
@mkdir -p ${PREFIX}/bin
@cp -f ${BIN} ${PREFIX}/bin
@chmod 755 ${PREFIX}/bin/egc
@echo installing executable file to $(PREFIX)/bin
@mkdir -p $(PREFIX)/bin
@cp -f $(BIN) $(PREFIX)/bin
@chmod 755 $(PREFIX)/bin/egc

uninstall:
@echo removing executable file from ${PREFIX}/bin
@rm -f ${PREFIX}/bin/egc
@echo removing executable file from $(PREFIX)/bin
@rm -f $(PREFIX)/bin/egc

$(OBJ_DIR):
mkdir -p $(OBJ_DIR)

$(BIN_DIR):
mkdir -p $(BIN_DIR)

${BIN}: ${OBJ}
${CC} -o $@ $^ ${LDFLAGS}
$(BIN): $(OBJ) | $(BIN_DIR)
$(CC) -o $@ $^ $(LDFLAGS)

egc.o: egc.c
egc: ${OBJ}
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(OBJ_DIR)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

$(OBJ_DIR)/egc.o: $(SRC_DIR)/egc.c
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# egc

[![CI](https://github.com/cpmachado/egc/actions/workflows/ci.yml/badge.svg)](https://github.com/cpmachado/egc/actions/workflows/ci.yml)

A simple program to compute an unitary fraction expansion of a given fraction.

It's output is in a csv in a different line.
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

4 changes: 2 additions & 2 deletions config.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# configuration of system

VERSION = $(shell cat VERSION)
VERSION = 0.0.1

# installation
PREFIX ?= /usr/local
Expand All @@ -14,4 +14,4 @@ CPPFLAGS =\
-D_BSD_SOURCE\
-D_DEFAULT_SOURCE\
-D_POSIX_C_SOURCE=200809L
LDFLAGS =
LDFLAGS = -lc
Empty file removed doc/.gitkeep
Empty file.
24 changes: 24 additions & 0 deletions doc/requirement-analysis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Requirement analysis

## What is egc?

egc is defined as a program and library that supports mathematical methods
associated with egyptian mathematics.

The source of these is a course I took in university:
- Estrada et al., "História da matemática"
+ URI: <http://hdl.handle.net/10400.2/10668>

## Components
- egc: cli interface
+ shell to perform operations
+ enable scripting
+ options to redirect output
- libegc: library to leverage this methods
+ table structure
+ multiplication method
+ division method
+ unit fraction type
+ egyptian fraction type and computation
+ false position method
+ TBD
Loading

0 comments on commit 2f6c923

Please sign in to comment.