Permalink
Browse files

Lots of cleanup, new makefile

  • Loading branch information...
Nick Markwell
Nick Markwell committed Nov 16, 2011
1 parent e68245a commit b13a098d43da54089550d4a6efff61665f21756a
View
@@ -1 +1,4 @@
possum
+*.o
+*.d
+include/_*.h
View
@@ -1,16 +1,92 @@
-CC=clang
-PREFIX?=/usr
-CFLAGS?=-std=c99 -Os -pedantic -Wall -g
+# Output executable name
+OUTPUT := possum
-all:
- $(CC) $(CFLAGS) -I$(PREFIX)/include -L$(PREFIX)/lib -lX11 -o possum possum.c core.c keys.c
+# Target to build (debug or release)
+TARGET := debug
+
+# Libraries to use
+LIBS := x11
+
+# Compiler options
+CC := clang
+override CFLAGS += -std=c99 -pedantic -Wall -g -D_BSD_SOURCE -MMD $(shell pkg-config --cflags-only-other $(LIBS))
+override INCLUDES += -Iinclude/ $(shell pkg-config --cflags-only-I $(LIBS))
+override WARNINGS += -Wall -Wextra
+override LDFLAGS += $(shell pkg-config --libs $(LIBS))
+
+# Target-specific flags
+ifeq ($(TARGET),debug)
+ override CFLAGS += -ggdb -O0 -DDEBUG
+endif
+ifneq ($(TARGET),release)
+ override CFLAGS += -DDEVELOPMENT
+endif
+
+# Find all sources
+SOURCES := $(shell find src/ -name '*.c')
+OBJECTS := $(SOURCES:%.c=%.o)
+DFILES := $(SOURCES:%.c=%.d)
+
+all: headers $(OUTPUT)
+release: all
+
+headers:
+ $(shell ./generate_headers.sh)
+
+$(OUTPUT): $(OBJECTS)
+ @echo -e " [\033[32;1mLD\033[0m] $@"
+ @$(CC) $(LDFLAGS) $^ -o $@
+
+# Dependency files from -MMD
+-include $(DFILES)
+
+%.o: %.c
+ @echo -e " [\033[34;1mCC\033[0m] $@"
+ @$(CC) $(CFLAGS) $(INCLUDES) $(WARNINGS) -c $< -o $@
+
+clean:
+ @echo -e " [\033[31;1mRM\033[0m] $(OBJECTS)"
+ @rm -f $(OBJECTS)
+ @echo -e " [\033[31;1mRM\033[0m] $(DFILES)"
+ @rm -f $(DFILES)
+ @echo -e " [\033[31;1mRM\033[0m] $(OUTPUT)"
+ @rm -f $(OUTPUT)
+ @echo -e " [\033[31;1mRM\033[0m] $(shell find include/ -name '_*.h')"
+ @rm -f $(shell find include/ -name '_*.h')
+
+flags:
+ @echo "CFLAGS: $(CFLAGS)"
+ @echo "INCLUDES: $(INCLUDES)"
+ @echo "WARNINGS: $(WARNINGS)"
+ @echo "LDFLAGS: $(LDFLAGS)"
test: all
./test.sh
debug: all
./test.sh -v
-clean:
- rm -f possum
+.PHONY: all clean flags test debug headers
+
+#CC=clang
+#PREFIX?=/usr
+#CFLAGS?=-std=c99 -Os -pedantic -Wall -g
+#INCLUDES?=-I$(PREFIX)/include
+#LIBS?=-L$(PREFIX)/lib -lX11
+#SOURCES=$(
+
+#compile:
+# $(CC) $(CFLAGS) $(INCLUDES) $(LIBS) -o possum possum.c core.c keys.c
+
+#compile_debug:
+# $(CC) $(CFLAGS) $(INCLUDES) $(LIBS) -o possum possum.c core.c keys.c
+
+#test: all
+# ./test.sh
+
+#debug: all
+# ./test.sh -v
+
+#clean:
+# rm -f possum
View
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+DIR=$(dirname $(readlink -f $0)) # Directory script is in
+cd $DIR
+
+HEADER=
+
+function header() {
+ HEADER="$1"
+ echo > $HEADER
+}
+
+function write() {
+ echo $@ >> $HEADER
+}
+
+function guard() {
+ echo $HEADER | sed 's/\./_/g' | tr '/[a-z]' '_[A-Z]'
+}
+
+function define() {
+ write "#define $@"
+}
+
+header "./include/_git_info.h"
+write "#ifndef $(guard)"
+write "#define $(guard)"
+define GIT_BRANCH "\"$(git branch | grep -E '^\*' | cut -d' ' -f2)\""
+define GIT_COMMIT "\"$(git show | head -n1 | cut -d' ' -f2)\""
+write "#endif"
File renamed without changes.
File renamed without changes.
@@ -7,8 +7,8 @@
#include <X11/Xlib.h>
-#include "core.h"
-#include "keys.h"
+#include <core.h>
+#include <keys.h>
void PossumExit();
void PossumRestart();
View
@@ -1,4 +1,4 @@
-#include "possum.h"
+#include <possum.h>
XButtonEvent move_start = {0};
XWindowAttributes attr = {0};
@@ -25,9 +25,11 @@ void CoreKeyPress()
XRaiseWindow(event.xkey.display, event.xkey.subwindow);
}
+#ifdef DEVELOPMENT
ON_ALTCTRL(Delete) {
PossumRestart();
}
+#endif
/*ON_ALT(F4) {
XKillClient(event.xkey.display, event.xkey.window);
View
@@ -1,4 +1,4 @@
-#include "possum.h"
+#include <possum.h>
void SetCommonKeys()
{
@@ -1,10 +1,13 @@
-#include "possum.h"
-#include "core.h"
-#include "keys.h"
+#include <possum.h>
+#include <_git_info.h>
int main(int argc, char const* argv[])
{
KeyCodes = malloc(sizeof(KeyCodesCommon));
+
+#ifdef DEVELOPMENT
+ printf("Possum development build. [git %s %s]\n", GIT_COMMIT, GIT_BRANCH);
+#endif
if ((dpy = XOpenDisplay(NULL)) == NULL) {
fprintf(stderr, "Error: Could not open default display.\n");

0 comments on commit b13a098

Please sign in to comment.