85 lines
2.1 KiB
Makefile
85 lines
2.1 KiB
Makefile
#Copyright 2018 rexy712 of Rexy & Co
|
|
#Makefile for project 'rexbacklight'
|
|
|
|
#Project directory and file setup
|
|
SOURCE_DIRS:=src
|
|
OBJDIR:=obj
|
|
DEPDIR:=obj/dep
|
|
INCLUDE_DIRS:=include
|
|
EXT:=c
|
|
MAIN_EXECUTABLE:=rexbacklight
|
|
|
|
#Compiler/Linker setup
|
|
CC:=gcc
|
|
CFLAGS:=-g -std=c11 -Wall -pedantic -Wextra
|
|
release: CFLAGS:=-std=c11 -Wall -pedantic -Wextra -O2
|
|
LDFLAGS=
|
|
LDLIBS:=
|
|
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)/$*.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)"
|
|
|
|
.PHONY: install
|
|
install: $(MAIN_EXECUTABLE)
|
|
install -m755 -o root -g root -s "$(MAIN_EXECUTABLE)" /usr/bin/rexbacklight
|
|
install -m600 -o root -g root rules/91-backlight.rules /etc/udev/rules.d/91-backlight.rules
|
|
install -m755 -o root -g root rules/rexbacklight.init /etc/init.d/rexbacklight
|
|
|
|
.PHONY: uninstall
|
|
uninstall:
|
|
rm /usr/bin/rexbacklight
|
|
rm /etc/udev/rules.d/91-backlight-conf
|
|
rm /etc/init.d/rexbacklight.init
|
|
|
|
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)
|
|
|
|
|