-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
73 lines (57 loc) · 1.82 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
TARGET := xbright
OBJDIR := obj
SRC := $(wildcard *.c)
OBJ := $(addprefix $(OBJDIR)/,$(notdir $(SRC:.c=.o)))
CC ?= cc
INSTALL := install
INSTALL_ARGS := -o root -g root -m 4755 # Installs with SUID set
INSTALL_DIR := /usr/local/bin/
BUILD_HOST := build_host.h
CFLAGS := -Wall
LFLAGS :=
ifeq ($(CC), $(filter $(CC), clang gcc cc))
CFLAGS += -std=c99 -pedantic
endif
# Auto-configuration
BRIGHTNESSFILE=$(shell find /sys/class/backlight/*/brightness | head -1)
MAXVALUE=$(shell find /sys/class/backlight/*/max_brightness | head -1 | xargs cat)
# version info from git
REVCNT := $(shell git rev-list --count master 2>/dev/null)
ifeq ($(REVCNT),)
VERSION := devel
else
REVHASH := $(shell git log -1 --format="%h" 2>/dev/null)
VERSION := "$(REVCNT).$(REVHASH)"
endif
all: debug
debug: CFLAGS += -g -DDEBUG
debug: LFLAGS += -g
debug: build
release: CFLAGS +=-Os
release: clean build
strip $(TARGET)
build: $(OBJDIR) $(BUILD_HOST) $(TARGET)
# now the program gets autoconfigured in Makefile via $(BUILD_HOST)
$(BUILD_HOST):
@echo "#define BUILD_HOST \"`hostname -f`\"" > $(BUILD_HOST)
@echo "#define BRIGHTNESSFILE \"$(BRIGHTNESSFILE)\"" >> $(BUILD_HOST)
@echo "#define MAXVALUE $(MAXVALUE)" >> $(BUILD_HOST)
@echo "#define VERSION \"$(VERSION)\"" >> $(BUILD_HOST)
$(TARGET): $(BUILD_HOST) $(OBJ)
$(CC) $(LFLAGS) -o $@ $(OBJ)
$(OBJDIR)/%.o : %.c
$(CC) $(CFLAGS) -o $@ -c $?
$(OBJDIR):
@mkdir -p $(OBJDIR)
clean:
-rm -f *.core
-rm -f $(BUILD_HOST)
-rm -f $(TARGET)
-rm -rf ./$(OBJDIR)
install:
$(INSTALL) $(INSTALL_ARGS) $(TARGET) $(INSTALL_DIR)
@echo "DONE"
uninstall: clean
-rm -f $(INSTALL_DIR)$(TARGET)
@echo "DONE"
.PHONY : all debug release build clean objdir install uninstall