-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
102 lines (82 loc) · 2.42 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# Created by WestleyR <[email protected]> in 2019
# Source code: https://github.com/WestleyR/list-files
#
# Copyright (c) 2019-2022 WestleyR. All rights reserved.
# This software is licensed under a BSD 3-Clause Clear License.
# Consult the LICENSE file that came with this software regarding
# your rights to distribute this software.
#
CC = gcc
CFLAGS = -Wall -Ideps
TARGET = lf
PREFIX = /usr/local
MODDED = $(shell if command -v git > /dev/null ; then (git diff --exit-code --quiet && echo \"[No changes]\") || echo \"[With uncommited changes]\" ; else echo \"[unknown]\" ; fi)
COMMIT = "$(shell git log -1 --oneline --decorate=short --no-color || ( echo 'ERROR: unable to get commit hash' >&2 ; echo unknown ) )"
CFLAGS += -DCOMMIT_HASH=\"$(COMMIT)\"
CFLAGS += -DUNCOMMITED_CHANGES=\"$(MODDED)\"
ifeq ($(DEBUG), true)
CFLAGS += -DDEBUG
endif
ifeq ($(STATIC), true)
CFLAGS += -static -DWITHOUT_NAME_GROUP_OUTPUT
endif
ifeq ($(WITHOUT_ID), true)
CFLAGS += -DWITHOUT_NAME_GROUP_OUTPUT
endif
SRC = $(wildcard src/*.c)
OBJS = $(SRC:.c=.o)
test_files = $(wildcard utests/*.c)
test_files += $(wildcard src/*.c)
TEST_SRC = $(filter-out src/main-lf.c,$(test_files))
TEST_OBJS = $(TEST_SRC:.c=.o)
.PHONY:
all: $(TARGET)
.PHONY:
options:
@echo "Make options:"
@echo ""
@echo "$$ make [option]"
@echo ""
@echo " [no-option], all compile the project"
@echo " STATIC=true compile the static project"
@echo " WITHOUT_ID=true dont print the user/group names,"
@echo " DEBUG=true compile target as debug"
@echo " instead print the uid/gid."
@echo " install install the binary to the PREFIX,"
@echo " (dafault '/usr/local/bin')"
@echo " clean clean the binary"
@echo " uninstall uninstall the binary from PREFIX"
@echo ""
.PHONY:
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(OBJS)
.PHONY:
%.o: %.c
$(CC) $(DEP_FLAG) $(CFLAGS) $(LDFLAGS) -o $@ -c $<
.PHONY:
test: $(TARGET) unit-test
@echo "Running end-to-end tests..."
@bash ./run-tests
.PHONY:
unit-test: $(TEST_OBJS)
@echo "Running unit tests..."
@echo $(TEST_OBJS)
$(CC) $(CFLAGS) -o testball $(TEST_OBJS)
./testball
.PHONY:
install: $(TARGET)
mkdir -p $(PREFIX)/bin
cp -f $(TARGET) $(PREFIX)/bin
.PHONY:
clean:
rm -f $(OBJS) $(TEST_OBJS) || true
.PHONY:
cleanall: clean
rm -f $(TARGET)
rm -rf ./pkg
.PHONY:
uninstall: $(PREFIX)/$(TARGET)
rm -f $(PREFIX)/$(TARGET)
#
# End Makefile
#