From 8f1d080fff9c920c027efa32dc97babc63ae5ccb Mon Sep 17 00:00:00 2001 From: Rexy712 Date: Tue, 24 Apr 2018 17:19:38 -0700 Subject: [PATCH] Initial commit --- makefile | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 makefile diff --git a/makefile b/makefile new file mode 100644 index 0000000..7fa632b --- /dev/null +++ b/makefile @@ -0,0 +1,85 @@ +#Copyright 2018 Rexy712 of Rexy & Co +#This program is free software: you can redistribute it and/or modify +#it under the terms of the GNU General Public License as published by +#the Free Software Foundation, either version 3 of the License, or +#(at your option) any later version. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU General Public License +#along with this program. If not, see . + +#Makefile for project + +#Project directory and file setup +SOURCE_DIRS:=src +OBJDIR:=obj +DEPDIR:=obj/dep +INCLUDE_DIRS:=include +EXT:=c +MAIN_EXECUTABLE:=rex-edid + +#Compiler/Linker setup +CC:=gcc +CFLAGS:=-x c -g -std=c11 -Wall -pedantic -Wextra +release: CFLAGS+=-O2 +LDFLAGS= +LDLIBS:=-lxcb -lxcb-randr +STRIP:=strip + +#Windows workarounds +ifeq ($(OS),Windows_NT) + mkdir=mkdir $(subst /,\,$(1)) > NUL 2>&1 + rm=del /F $(1) > NUL 2>&1 + rmdir=rd /s /q $(1) > NUL 2>&1 + move=move /y $(subst /,\,$(1)) $(subst /,\,$(2)) > NUL 2>&1 + MAIN_EXECUTABLE:=$(MAIN_EXECUTABLE).exe + LDLIBS:= +else + mkdir=mkdir -p $(1) + rm=rm -f $(1) + rmdir=rm -rf $(1) + move=mv $(1) $(2) +endif + +#Internal management of sources/objects and additional cflags +INTERNAL_CFLAGS=-c $(foreach dir,$(INCLUDE_DIRS),-I"$(dir)") -MMD -MP -MF"$(DEPDIR)/$(notdir $(subst .o,.d,$@))" +SOURCES:=$(foreach source,$(SOURCE_DIRS),$(foreach ext,$(EXT),$(wildcard $(source)/*.$(ext)))) +OBJECTS:=$(addprefix $(OBJDIR)/,$(subst \,.,$(subst /,.,$(addsuffix .o,$(SOURCES))))) + +all: $(MAIN_EXECUTABLE) + +$(MAIN_EXECUTABLE): $(OBJECTS) + $(CC) $(LDFLAGS) $^ -o "$(basename $@)" $(LDLIBS) + +.PHONY: release +release: $(OBJECTS) + $(CC) $(LDFLAGS) $^ -o "$(basename $(MAIN_EXECUTABLE))" $(LDLIBS) + $(STRIP) --strip-all "$(MAIN_EXECUTABLE)" + +define GENERATE_OBJECTS + +$$(OBJDIR)/$(subst \,.,$(subst /,.,$(1))).%.o: $(1)/% + $$(CC) $$(CFLAGS) $$(INTERNAL_CFLAGS) "$$<" -o "$$@" + +endef + +$(foreach dir,$(SOURCE_DIRS),$(eval $(call GENERATE_OBJECTS,$(dir)))) +$(OBJECTS): | $(OBJDIR) $(DEPDIR) + +$(OBJDIR): + $(call mkdir,"$@") +$(DEPDIR): + $(call mkdir,"$@") + +.PHONY: clean +clean: + $(call rmdir,"$(DEPDIR)") + $(call rmdir,"$(OBJDIR)") + $(call rm,"$(MAIN_EXECUTABLE)") + +-include $(wildcard $(DEPDIR)/*.d) +