switching to config build sys

lunix is why we can't have nice things
This commit is contained in:
Kyle Isom 2020-02-13 16:02:53 +00:00
parent 8ed46b1087
commit e999245c8e
3 changed files with 127 additions and 58 deletions

View File

@ -1,50 +1,57 @@
BIN := ke
OBJS := main.o
INSTROOT := $(HOME)
VERSION := 0.9.2
CC ?= gcc
TARGET := ke
OBJS := main.o
LIBS := -lefence
LDFLAGS :=
CFLAGS := -pedantic -Wall -Werror -Wextra -O2 -std=c99 -g
CFLAGS += -fno-builtin-memmove -DKE_VERSION="\"$(VERSION)\""
PREFIX ?= /usr/local
MANDIR ?= /usr/local/man
.PHONY: all
all: build
CFLAGS += -Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g
CFLAGS += -DKE_VERSION="\"$(TARGET) version $(VERSION)\""
CFLAGS += -D_DEFAULT_SOURCE -D_POSIX_SOURCE -D_XOPEN_SOURCE
all: $(TARGET)
.PHONY: build
build: $(BIN)
$(BIN): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS)
$(BIN).1.txt: $(BIN).1
mandoc -Tutf8 $(BIN).1 > $@
.PHONY: clean
clean:
rm -f $(BIN) $(OBJS) *.core keypress
-rm -f .?*.* *.core *.o *.html tags $(TARGET) $(OBJS)
-rm -rf security
-rm -rf $(TARGET)-$(VERSION)
-rm -f $(TARGET)-$(VERSION).tgz
.PHONY: run
run: $(BIN)
reset
./$(BIN) hello.txt
$(TARGET): $(OBJS)
${CC} -o $(TARGET) ${CFLAGS} ${LDFLAGS} $(LIBS) $(OBJS)
keypress: keypress.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ keypress.c
install: $(TARGET)
install -m 0755 $(TARGET) $(PREFIX)/bin/$(TARGET)
install -m 0755 -d $(MANDIR)/man1
install -m 0444 $(TARGET).1 $(MANDIR)/man1/$(TARGET).1
.PHONY: install
install: $(BIN) $(BIN).1
install -d $(INSTROOT)/bin/
install -d $(INSTROOT)/share/man/man1
install -C $(BIN) $(INSTROOT)/bin/
install -C $(BIN).1 $(INSTROOT)/share/man/man1/$(BIN).1
uninstall:
-rm -f $(PREFIX)/bin/$(TARGET)
-rm -f $(MANDIR)/man1/$(TARGET).1
.PHONY: upload
upload: $(BIN).1.txt
scp main.c p.kyleisom.net:/var/www/sites/p/ke/$(BIN)_$(VERSION).c.txt
scp $(BIN).1.txt p.kyleisom.net:/var/www/sites/p/ke/$(BIN).1.txt
lint:
-mkdir security
-rats -w 3 $(TARGET).[ch] > security/rats.out
-lint -fhrs $(TARGET).c > security/lint.out
-splint +posixlib $(TARGET).[ch] > security/splint.out
.PHONY: cloc
cloc:
cloc main.c
dist: clean
-mkdir $(TARGET)-$(VERSION)
-cp * $(TARGET)-$(VERSION)
-cd $(TARGET)-$(VERSION) && make distclean && cd ..
-tar czf $(TARGET)-$(VERSION).tgz $(TARGET)-$(VERSION)
%.o: %.c
distclean: clean
-rm -f Makefile
htmldoc:
-mandoc -Thtml $(TARGET).1 > $(TARGET).1.html
tags:
ctags *.[ch]
.c.o:
$(CC) -c ${CFLAGS} $?
.PHONY: clean all install lint uninstall dist distclean htmldoc tags

57
ke/Makefile.in Normal file
View File

@ -0,0 +1,57 @@
VERSION := 0.9.2
CC ?= gcc
TARGET := ke
OBJS := main.o
LIBS :=
PREFIX ?= $PREFIX
MANDIR ?= $MANDIR
CFLAGS += -Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g
CFLAGS += -DKE_VERSION="\"$(TARGET) version $(VERSION)\""
CFLAGS += OS_CFLAGS
all: $(TARGET)
clean:
-rm -f .?*.* *.core *.o *.html tags $(TARGET) $(OBJS)
-rm -rf security
-rm -rf $(TARGET)-$(VERSION)
-rm -f $(TARGET)-$(VERSION).tgz
$(TARGET): $(OBJS)
${CC} -o $(TARGET) ${CFLAGS} ${LDFLAGS} $(LIBS) $(OBJS)
install: $(TARGET)
install -m 0755 $(TARGET) $(PREFIX)/bin/$(TARGET)
install -m 0755 -d $(MANDIR)/man1
install -m 0444 $(TARGET).1 $(MANDIR)/man1/$(TARGET).1
uninstall:
-rm -f $(PREFIX)/bin/$(TARGET)
-rm -f $(MANDIR)/man1/$(TARGET).1
lint:
-mkdir security
-rats -w 3 $(TARGET).[ch] > security/rats.out
-lint -fhrs $(TARGET).c > security/lint.out
-splint +posixlib $(TARGET).[ch] > security/splint.out
dist: clean
-mkdir $(TARGET)-$(VERSION)
-cp * $(TARGET)-$(VERSION)
-cd $(TARGET)-$(VERSION) && make distclean && cd ..
-tar czf $(TARGET)-$(VERSION).tgz $(TARGET)-$(VERSION)
distclean: clean
-rm -f Makefile
htmldoc:
-mandoc -Thtml $(TARGET).1 > $(TARGET).1.html
tags:
ctags *.[ch]
.c.o:
$(CC) -c ${CFLAGS} $?
.PHONY: clean all install lint uninstall dist distclean htmldoc tags

View File

@ -15,6 +15,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -77,44 +78,43 @@ void editor_set_status(const char *fmt, ...);
/* miscellaneous */
void die(const char *s);
int get_winsz(int *rows, int *cols);
void goto_line();
void goto_line(void);
void delete_row(int at);
void row_append_row(struct erow *row, char *s, int len);
void row_insert_ch(struct erow *row, int at, int16_t c);
void row_delete_ch(struct erow *row, int at);
void insertch(int16_t c);
void deletech();
void deletech(void);
void open_file(const char *filename);
char *rows_to_buffer(int *buflen);
int save_file();
int save_file(void);
uint16_t is_arrow_key(int16_t c);
int16_t get_keypress();
void display_refresh();
int16_t get_keypress(void);
void display_refresh(void);
void editor_find_callback(char *query, int16_t c);
void editor_find();
void editor_find(void);
char *editor_prompt(char *, void (*cb)(char *, int16_t));
void editor_openfile();
void editor_openfile(void);
void move_cursor(int16_t c);
void newline();
void newline(void);
void process_kcommand(int16_t c);
void process_normal(int16_t c);
void process_escape(int16_t c);
int process_keypress();
void enable_termraw();
int process_keypress(void);
void enable_termraw(void);
void display_clear(struct abuf *ab);
void disable_termraw();
void setup_terminal();
void disable_termraw(void);
void setup_terminal(void);
void draw_rows(struct abuf *ab);
char status_mode_char();
char status_mode_char(void);
void draw_status_bar(struct abuf *ab);
void draw_message_line(struct abuf *ab);
void scroll();
void display_refresh();
void scroll(void);
void display_refresh(void);
void editor_set_status(const char *fmt, ...);
void loop();
void init_editor();
void loop(void);
void init_editor(void);
void process_normal(int16_t c);
void disable_termraw();
enum KeyPress {
@ -133,6 +133,10 @@ enum KeyPress {
};
/*
* editor is the global editor state; it should be broken out
* to buffers and screen state, probably.
*/
struct editor_t {
struct termios entry_term;
int rows, cols;
@ -172,7 +176,6 @@ ab_free(struct abuf *buf)
buf->b = NULL;
}
char
nibble_to_hex(char c)
{
@ -899,6 +902,8 @@ move_cursor(int16_t c)
while (--reps) {
move_cursor(c == PG_UP ? ARROW_UP : ARROW_DOWN);
}
break;
}
case HOME_KEY: