-SHELL = /bin/bash
PROG = base
-PREFIX = /usr
-DESTDIR = /bin
+VERSION ?= 0.0.1
+
+SHELL = /bin/bash
+
+DESTDIR ?=
+PREFIX ?= $(DESTDIR)/usr
+BINDIR ?= $(PREFIX)/bin
+LIBDIR ?= $(PREFIX)/lib
+MANDIR ?= $(PREFIX)/share/man/man1
+
+FILES ?= $(wildcard *.c)
+HEADERS ?= $(wildcard *.h)
+OBJECTS ?= $(wildcard *.o)
+
+CC ?= gcc
+CFLAGS += -O2 -std=c17 -pipe
+WARNINGS ?= -Werror -Wall -Wextra -Wpedantic -Wno-unused
+CPPFLAGS += -I .
+LDFLAGS += -L .
+LDLIBS += -lm
+ALL_FLAGS = $(CPPFLAGS) $(CFLAGS) $(WARNINGS) $(LDFLAGS) $(LDLIBS)
+
+.PHONY: all
+all: $(FILES) $(HEADERS)
+ $(CC) $(FILES) $(ALL_FLAGS) -o $(PROG)
+
+.PHONY: install
+install: $(PROG) $(PROG).1
+ install -CDTm 755 $(PROG) $(BINDIR)/$(PROG)
+ [[ -e $(PROG).1]] && gzip -fc $(PROG).1 > $(MANDIR)/$(PROG).1.gz
+
+.PHONY: tar
+tar: $(FILES) $(HEADERS) $(PROG).1 Makefile README LICENSE
+ tar -g gzip -cf $(PROG)-$(VERSION).tar.gz $(FILES) $(HEADERS) $(PROG).1 Makefile README LICENSE
+
+.PHONY: compile
+compile: $(FILES)
+ $(CC) $(FILES) $(ALL_FLAGS) -c
-CFILE = main.c function.c
-HEADER = base.h
+.PHONY: link
+link: $(OBJECTS)
+ $(CC) $(OBJECTS) $(ALL_FLAGS) -o $(PROG)
-header: ${HEADER}
- gcc ${CFILE} ${HEADER} -lm -Wall -o ${PROG}
+.PHONY: assemble
+assemble: $(FILES)
+ $(CC) $(FILES) $(ALL_FLAGS) -S
-install: ${CFILE} ${HEADER}
- gcc ${CFILE} ${HEADER} -lm -Wall -o ${PREFIX}${DESTDIR}/${PROG}
+.PHONY: debug
+debug: $(FILES)
+ $(CC) $(FILES) $(ALL_FLAGS) -ggdb3 -Og -o $(PROG)
-debug: ${CFILE}
- gcc ${CFILE} -lm -Wall -g -o ${PROG}
+.PHONY: clean
+clean:
+ [[ -f $(BINDIR)/$(PROG) ]] && rm $(BINDIR)/$(PROG)
+ [[ -f $(PROG) ]] && rm $(PROG)
-clean:
- rm ${PREFIX}${DESTDIR}/${PROG}
+++ /dev/null
-# base
-CLI utility to convert numbers between arbitrary bases.
-
-base converts from base 10 to binary if called with no options. Input and output base can be specified with -i and -o respectively, ranging from 2-62. If no number is given, base will prompt for a number, or convert stdin if given.
-If not specified, base will print binary numbers as unsigned longs with 64 bits, hexadecimal numbers with a leading 0x, octal and any other number with no leading zeroes.
-
-## Usage:
-Print binary representation:
- $ base 555
- 00000000 00000000 00000000 00000000 00000000 00000000 00000010 00101011
-
-Print a number in hexadecimal:
- $ base -o 16 1234
- 0x4d2
-
-Print an octal representation of a base 12 number
- $ base -o 8 -i 12 5a
- 106
-
- Convert stdin to base 8
- $ echo "123456" | base -o 8
- 361100
-
-## Installation :
-Download .tar.gz and decompress
- $ curl "https://download.huck.website/base-[VERSION].tar.gz"
- $ tar -xzvf base-[VERSION].tar.gz
-
-Build base from source
- $ cd base-[VERSION]
- $ sudo make install
-