New makefile + nicer directory structure

This commit is contained in:
Thomas Kolb 2013-08-18 22:52:50 +02:00
parent fa98c1e089
commit d07fc77f7d
11 changed files with 67 additions and 25 deletions

View File

@ -1,46 +1,88 @@
BASE_VERSION=0.1.0 # --- START OF CONFIG ---------------------------------------------------
VERSION="\"$(BASE_VERSION)-$(shell git rev-parse --short HEAD)\"" # Edit the following variables for your own needs
MAGIC_CFLAGS=-DHAVE_MAGIC # toolchain configuration
MAGIC_LIBS=-lmagic CXX=gcc
LD=gcc
CC=gcc # default build configuration
CFLAGS+=-Wall -pedantic -std=c99 -D_POSIX_C_SOURCE=20120607L -D_FILE_OFFSET_BITS=64 -DVERSION=$(VERSION) $(MAGIC_CFLAGS) # "make BUILD=release" does a release build
LIBS=-lmicrohttpd $(MAGIC_LIBS) BUILD:=debug
TARGET=fileshare # basic build flags configuration
SOURCE=main.c logger.c dirlisting.c util.c favicon.c CFLAGS+=-Wall -Wno-variadic-macros -std=c99 -pedantic -Wno-long-long -D_POSIX_C_SOURCE=20120607L -D_FILE_OFFSET_BITS=64
DEPS=logger.h templates.h dirlisting.h util.h favicon.h 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 CFLAGS_release=-O3
debug: show_cflags $(TARGET) LIBS_release=
@echo '>>>' DEBUG build complete.
release: CFLAGS+=-O3 # target configuration
release: show_cflags $(TARGET) TARGET := fileshare
@echo '>>>' RELEASE build complete. 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: .PHONY show_cflags:
@echo --- Build parameters: ------------------------------------------ @echo --- Build parameters: ------------------------------------------
@echo CFLAGS\=$(CFLAGS) @echo CFLAGS\=$(CFLAGS)
@echo LIBS\=$(LIBS) @echo LIBS\=$(LIBS)
@echo SOURCE\=$(SOURCE)
@echo ----------------------------------------------------------------- @echo -----------------------------------------------------------------
$(TARGET): $(OBJ) $(DEPS) Makefile $(TARGET): show_cflags $(TARGETFILE)
@echo Linking... @echo ">>> $(BUILD) build complete."
@$(CC) -o $(TARGET) $(OBJ) $(LIBS)
%.o: %.c $(DEPS) Makefile $(TARGETFILE): $(DEPS) $(OBJ) $(INCLUDES) Makefile
@echo Compiling $< ... @echo Linking $@ ...
@$(CC) -c $(CFLAGS) -o $@ $< $(INCLUDES) @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: doc:
doxygen doxygen.conf doxygen doxygen.conf
clean: clean:
rm -f $(TARGET) rm -f $(TARGETFILE)
rm -f $(OBJ) rm -f $(OBJ)

View File

View File