From d07fc77f7dd5c33b5e2d4a064ac26195449e929e Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Sun, 18 Aug 2013 22:52:50 +0200 Subject: [PATCH] New makefile + nicer directory structure --- Makefile | 92 ++++++++++++++++++++-------- dirlisting.h => include/dirlisting.h | 0 favicon.h => include/favicon.h | 0 logger.h => include/logger.h | 0 templates.h => include/templates.h | 0 util.h => include/util.h | 0 dirlisting.c => src/dirlisting.c | 0 favicon.c => src/favicon.c | 0 logger.c => src/logger.c | 0 main.c => src/main.c | 0 util.c => src/util.c | 0 11 files changed, 67 insertions(+), 25 deletions(-) rename dirlisting.h => include/dirlisting.h (100%) rename favicon.h => include/favicon.h (100%) rename logger.h => include/logger.h (100%) rename templates.h => include/templates.h (100%) rename util.h => include/util.h (100%) rename dirlisting.c => src/dirlisting.c (100%) rename favicon.c => src/favicon.c (100%) rename logger.c => src/logger.c (100%) rename main.c => src/main.c (100%) rename util.c => src/util.c (100%) diff --git a/Makefile b/Makefile index 4994d0c..0cbd2bd 100644 --- a/Makefile +++ b/Makefile @@ -1,46 +1,88 @@ -BASE_VERSION=0.1.0 -VERSION="\"$(BASE_VERSION)-$(shell git rev-parse --short HEAD)\"" +# --- START OF CONFIG --------------------------------------------------- +# Edit the following variables for your own needs -MAGIC_CFLAGS=-DHAVE_MAGIC -MAGIC_LIBS=-lmagic +# toolchain configuration +CXX=gcc +LD=gcc -CC=gcc -CFLAGS+=-Wall -pedantic -std=c99 -D_POSIX_C_SOURCE=20120607L -D_FILE_OFFSET_BITS=64 -DVERSION=$(VERSION) $(MAGIC_CFLAGS) -LIBS=-lmicrohttpd $(MAGIC_LIBS) +# default build configuration +# "make BUILD=release" does a release build +BUILD:=debug -TARGET=fileshare -SOURCE=main.c logger.c dirlisting.c util.c favicon.c -DEPS=logger.h templates.h dirlisting.h util.h favicon.h +# basic build flags configuration +CFLAGS+=-Wall -Wno-variadic-macros -std=c99 -pedantic -Wno-long-long -D_POSIX_C_SOURCE=20120607L -D_FILE_OFFSET_BITS=64 +LIBS+= -OBJ=$(patsubst %.c, %.o, $(SOURCE)) +# local include directory +CFLAGS+=-I./include -all: debug +# library specific flags +## libmicrohttpd +CFLAGS+=$(shell pkg-config --cflags libmicrohttpd) +LIBS+=$(shell pkg-config --libs libmicrohttpd) +# +# build type specific flags +CFLAGS_debug=-O0 -ggdb -DDEBUG +LIBS_debug= -debug: CFLAGS+=-O0 -ggdb -DDEBUG -debug: show_cflags $(TARGET) - @echo '>>>' DEBUG build complete. +CFLAGS_release=-O3 +LIBS_release= -release: CFLAGS+=-O3 -release: show_cflags $(TARGET) - @echo '>>>' RELEASE build complete. +# target configuration +TARGET := fileshare +VERSION := 0.2.0 +VCSVERSION := $(shell git rev-parse --short HEAD) + +# source files for the project +SOURCE := $(shell find src/ -name '*.c') +INCLUDES := $(shell find include/ -name '*.h') + +# additional dependencies for build (proper targets must be specified by user) +DEPS := + +# default target +all: $(TARGET) + +# user-specific targets + +# --- END OF CONFIG ----------------------------------------------------- + +OBJ1=$(patsubst %.c, %.o, $(SOURCE)) +OBJ=$(patsubst src/%, obj/$(BUILD)/%, $(OBJ1)) + +VERSIONSTR="\"$(VERSION)-$(VCSVERSION)\"" + +CFLAGS+=-DVERSION=$(VERSIONSTR) + +TARGETFILE := bin/$(BUILD)/$(TARGET) + +CFLAGS+=$(CFLAGS_$(BUILD)) +LIBS+=$(LIBS_$(BUILD)) .PHONY show_cflags: @echo --- Build parameters: ------------------------------------------ @echo CFLAGS\=$(CFLAGS) @echo LIBS\=$(LIBS) + @echo SOURCE\=$(SOURCE) @echo ----------------------------------------------------------------- -$(TARGET): $(OBJ) $(DEPS) Makefile - @echo Linking... - @$(CC) -o $(TARGET) $(OBJ) $(LIBS) +$(TARGET): show_cflags $(TARGETFILE) + @echo ">>> $(BUILD) build complete." -%.o: %.c $(DEPS) Makefile - @echo Compiling $< ... - @$(CC) -c $(CFLAGS) -o $@ $< $(INCLUDES) +$(TARGETFILE): $(DEPS) $(OBJ) $(INCLUDES) Makefile + @echo Linking $@ ... + @mkdir -p $(shell dirname $@) + @$(LD) -o $(TARGETFILE) $(OBJ) $(LIBS) + +obj/$(BUILD)/%.o: src/%.c $(INCLUDES) Makefile + @echo "Compiling $< ..." + @mkdir -p $(shell dirname $@) + @$(CXX) -c $(CFLAGS) -o $@ $< doc: doxygen doxygen.conf clean: - rm -f $(TARGET) + rm -f $(TARGETFILE) rm -f $(OBJ) + diff --git a/dirlisting.h b/include/dirlisting.h similarity index 100% rename from dirlisting.h rename to include/dirlisting.h diff --git a/favicon.h b/include/favicon.h similarity index 100% rename from favicon.h rename to include/favicon.h diff --git a/logger.h b/include/logger.h similarity index 100% rename from logger.h rename to include/logger.h diff --git a/templates.h b/include/templates.h similarity index 100% rename from templates.h rename to include/templates.h diff --git a/util.h b/include/util.h similarity index 100% rename from util.h rename to include/util.h diff --git a/dirlisting.c b/src/dirlisting.c similarity index 100% rename from dirlisting.c rename to src/dirlisting.c diff --git a/favicon.c b/src/favicon.c similarity index 100% rename from favicon.c rename to src/favicon.c diff --git a/logger.c b/src/logger.c similarity index 100% rename from logger.c rename to src/logger.c diff --git a/main.c b/src/main.c similarity index 100% rename from main.c rename to src/main.c diff --git a/util.c b/src/util.c similarity index 100% rename from util.c rename to src/util.c