diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..3cca2b70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +build/ diff --git a/Makefile b/Makefile index a8946f2f..cc723c12 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,25 @@ CFLAGS?=-Wall -Wextra -O3 + +PROGRAM=simpleswitcher + + PREFIX?=$(DESTDIR)/usr BINDIR?=$(PREFIX)/bin MANDIR?=$(PREFIX)/share/man/man1 -SOURCES=$(wildcard *.c) -OBJECTS=$(SOURCES:%.c=%.o) +BUILD_DIR=build +SOURCE_DIR=source +DOC_DIR=doc + +SOURCES=$(wildcard $(SOURCE_DIR)/*.c) +OBJECTS=$(SOURCES:$(SOURCE_DIR)/%.c=$(BUILD_DIR)/%.o) +HEADERS=$(wildcard include/*.h) MANPAGE_PATH=$(MANDIR)/simpleswitcher.1.gz CFLAGS+=-DMANPAGE_PATH="\"$(MANPAGE_PATH)\"" CFLAGS+=-std=c99 +CFLAGS+=-Iinclude/ # Check deps. ifeq (${DEBUG},1) @@ -43,22 +53,28 @@ $(info I3 mode is enabled) CFLAGS+=-DI3 -I${PREFIX}/include/ endif -all: normal +all: $(BUILD_DIR)/$(PROGRAM) +$(BUILD_DIR): + mkdir -p $@ +# Objects depend on header files and makefile too. -normal: $(OBJECTS) | Makefile - $(CC) -o simpleswitcher $^ $(LDADD) $(LDFLAGS) +$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c | Makefile $(HEADERS) $(BUILD_DIR) + $(CC) $(CFLAGS) -c -o $@ $^ -install: normal install-man - install -Dm 755 simpleswitcher $(BINDIR)/simpleswitcher +$(BUILD_DIR)/$(PROGRAM): $(OBJECTS) + $(CC) -o $@ $^ $(LDADD) $(LDFLAGS) + +install: $(BUILD_DIR)/$(PROGRAM) install-man + install -Dm 755 $(BUILD_DIR)/$(PROGRAM) $(BINDIR)/$(PROGRAM) install-man: - install -Dm 644 simpleswitcher.1 $(MANDIR)/simpleswitcher.1 + install -Dm 644 $(DOC_DIR)/simpleswitcher.1 $(MANDIR)/simpleswitcher.1 gzip -f $(MANDIR)/simpleswitcher.1 clean: - rm -f simpleswitcher $(OBJECTS) + rm -rf $(BUILD_DIR) indent: - @astyle --style=linux -S -C -D -N -H -L -W3 -f simpleswitcher.c textbox.c + @astyle --style=linux -S -C -D -N -H -L -W3 -f $(SOURCES) $(HEADERS) diff --git a/simpleswitcher.1 b/doc/simpleswitcher.1 similarity index 100% rename from simpleswitcher.1 rename to doc/simpleswitcher.1 diff --git a/textbox.h b/include/textbox.h similarity index 79% rename from textbox.h rename to include/textbox.h index 237190be..4e4061b1 100644 --- a/textbox.h +++ b/include/textbox.h @@ -28,10 +28,10 @@ typedef enum { textbox* textbox_create( Window parent, - TextboxFlags flags, - short x, short y, short w, short h, - char *font, char *fg, char *bg, - char *text, char *prompt ); + TextboxFlags flags, + short x, short y, short w, short h, + char *font, char *fg, char *bg, + char *text, char *prompt ); void textbox_free( textbox *tb ); diff --git a/simpleswitcher.c b/source/simpleswitcher.c similarity index 100% rename from simpleswitcher.c rename to source/simpleswitcher.c diff --git a/textbox.c b/source/textbox.c similarity index 98% rename from textbox.c rename to source/textbox.c index 669c6fda..5d968b81 100644 --- a/textbox.c +++ b/source/textbox.c @@ -49,10 +49,10 @@ void textbox_moveresize( textbox *tb, int x, int y, int w, int h ); // Xft text box, optionally editable textbox* textbox_create( Window parent, - TextboxFlags flags, - short x, short y, short w, short h, - char *font, char *fg, char *bg, - char *text, char *prompt ) + TextboxFlags flags, + short x, short y, short w, short h, + char *font, char *fg, char *bg, + char *text, char *prompt ) { textbox *tb = calloc( 1, sizeof( textbox ) );