battery_log/Makefile
Sandy Mossgrave 50fdb142dd Initial commit. Works.
Makefile copied from pokemath project

Reads two files from sysfs: charge_now and charge_full under BAT0,
then divides them using float math.

Output is guaranteed to be stable across major versions.

Supported options:
	-v gives verbose output for debugging purposes
	-h shows help text and exits
	-t gives terse output

Known issues:
	The path to charge_now and charge_full is hard-coded. This utility will not work with batteries that do not happen to be named BAT0.
	The float value given by this program is not actually a percentage.

TODO:
	Move help text #defines into a header file
	Add support to traverse /sys/class/power_supply and locate
	batteries
	Possibly add support to store default battery paths in /etc/battery_percent.conf

DISCLAIMER:
	This program is already too overcomplicated and shows no signs of slowing down.
2023-03-14 18:17:58 +00:00

59 lines
1.8 KiB
Makefile

#NEWPROJECT requires refactor.sh main.c
# Taken from https://stackoverflow.com/questions/30573481/how-to-write-a-makefile-with-separate-source-and-header-directories
SRCDIR := sources
MAINDIR := $(SRCDIR)/main
INCDIR := include
OBJDIR := objects
MAINOD := $(OBJDIR)/main
BINDIR := build
REFACTOR := refactor.h
HEADERS := $(wildcard $(INCDIR)/*.h)
MAINS := $(wildcard $(MAINDIR)/*.c)
MAINOBJS := $(patsubst $(MAINDIR)/%.c, $(MAINOD)/%.o, $(MAINS))
TARGETS := $(patsubst $(MAINDIR)/%.c, $(BINDIR)/%, $(MAINS))
SOURCES := $(wildcard $(SRCDIR)/*.c)
OBJECTS := $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, $(SOURCES))
CPPFLAGS := -Iinclude -MMD -MP
CFLAGS := -Wall -Werror -Wpedantic
LDFLAGS := #-Lmath or whatever
LDLIBS := #-lm or whatever
.PHONY: all clean
all: $(TARGETS)
@echo $(TARGETS)
refactor:
./refactor.sh
$(TARGETS): $(OBJECTS) $(MAINOBJS) | $(BINDIR) $(OBJDIR) $(MAINOD)
$(CC) $(LDFLAGS) $(OBJECTS) $(patsubst $(BINDIR)/%, $(MAINOD)/%.o, $@) $(LDLIBS) -o $@
$(BINDIR) $(OBJDIR) $(MAINOD):
mkdir --parents $@
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(HEADERS) | $(OBJDIR)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
$(MAINOD)/%.o: $(MAINDIR)/%.c $(HEADERS) | $(MAINOD)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
clean:
$(RM) -rv $(BINDIR) $(OBJDIR)
# Honestly still not sure what this directive does.
# It's an include directive, which processes all .d files that correspond to members of $(OBJ),
# with the hyphen in front meaning that it suppresses/ignores errors (from nonexistent .d files)
# Seems to be included under the stipulation that GNU make will auto-generate .d files based on
# a given file's #include directives?
# https://stackoverflow.com/questions/19114410/what-is-d-file-after-building-with-make
-include $(OBJ:.o=.d)