-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
77 lines (61 loc) · 1.64 KB
/
Copy pathMakefile
File metadata and controls
77 lines (61 loc) · 1.64 KB
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
#* ********************************************
#*
#*
#* Makefile
#*
#* By: ChK <chk@chkg2a.com}>
#*
#* Created: 2024-10-17 19:08 by ChK
#* Updated: 2024-10-18 20:45 by ChK #*
#* ********************************************
# Compiler
CC = g++
# Compiler flags
CFLAGS = -Wall -Wextra -Werror -I./includes
# Static library name
NAME = libfn.a
OUTNAME = a.out
TESTDIR = test
TESTFILE = test.cpp
INCLUDESDIR = /usr/local/include/chkg2a
# Source files
SRC = $(wildcard src/fn_char/*.c src/fn_str/*.c src/fn_dsa/*.cpp src/fn_utility/*.cpp src/fn_algorithms/*.cpp)
# Object files (generated from source files)
OBJ = $(SRC:.c=.o)
OBJ := $(OBJ:.cpp=.o)
# Default target
all: $(NAME)
# Rule to create the static library
$(NAME): $(OBJ)
@ar -rcs $@ $^
# Rule to compile source files into object files
%.o: %.c
@$(CC) $(CFLAGS) -c $< -o $@
%.o: %.cpp
@$(CC) $(CFLAGS) -c $< -o $@
# Rule to build and run the test file
run:
@$(CC) $(CFLAGS) -o ${OUTNAME} ${TESTDIR}/${TESTFILE} -L. -lfn
@./${OUTNAME}
# Install target to place the library and header files
install: all
@install -m 644 $(NAME) /usr/local/lib/
@echo "Library installed to /usr/local/lib/"
@mkdir -p $(INCLUDESDIR)
@cp -r ./includes/* $(INCLUDESDIR)
@echo "Header files installed to $(INCLUDESDIR)"
# Uninstall the library and header files
uninstall:
@rm -f /usr/local/lib/$(NAME)
@echo "Library removed from /usr/local/lib/"
@rm -rf $(INCLUDESDIR)
@echo "Header files removed from $(INCLUDESDIR)"
# Clean up object files and the library
clean: uninstall
@rm -f $(OBJ)
fclean:
@rm -f $(OBJ)
@rm -f $(NAME)
@rm -f ${OUTNAME}
re: fclean all run
.PHONY: all clean fclean re install