-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
177 lines (150 loc) · 4.8 KB
/
Copy pathMakefile
File metadata and controls
177 lines (150 loc) · 4.8 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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
.DEFAULT_GOAL := all
# Compiler and flags
CC := gcc
CFLAGS := -Wall -Wextra -Werror -MD -MP -I./inc
LDFLAGS:= -L ./
LDLIBS := -lopt_select_ncurses -lncurses
LIB := libopt_select_ncurses.a
# Output binary
APP := ./opt_select_ncurses
TEST_APP := ./test_app
.PRECIOUS: $(APP)
# Output directory
OUT := out
# Lib Source files
LIB_SRCS := src/udp_dbg_client.c src/opt_select_ncurses_lib.c
# Lib obj files
LIB_OBJS := $(addprefix $(OUT)/,$(LIB_SRCS:.c=.o))
# APP Source files
APP_SRCS := src/main.c
# Object files and dependency files
APP_OBJS := $(addprefix $(OUT)/,$(APP_SRCS:.c=.o))
TEST_SRCS := src/test_app.c
TEST_OBJS := $(addprefix $(OUT)/,$(TEST_SRCS:.c=.o))
DEPS := $(APP_OBJS:.o=.d) $(LIB_OBJS:.o=.d) $(TEST_OBJS:.o=.d)
# Install locations
PREFIX ?= /usr
SHARE_DIR = $(PREFIX)/share/opt_select_ncurses
INCLUDE_DIR = $(PREFIX)/include/opt_select_ncurses
BIN_DIR = $(PREFIX)/bin
LIB_DIR = $(PREFIX)/lib
# Compile source files into objects
$(OUT)/%.o: %.c Makefile
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
# Default target
all: $(LIB) $(APP) $(TEST_APP)
$(LIB): $(LIB_OBJS)
ar -rcs $@ $^
# create the app
$(APP): $(APP_OBJS) $(LIB)
$(CC) $(LDFLAGS) -o $@ $(filter-out %.a, $^) $(LDLIBS)
# create the test_app
$(TEST_APP): $(TEST_OBJS) $(LIB)
$(CC) $(LDFLAGS) -o $@ $(filter-out %.a, $^) $(LDLIBS)
# Cleanup
clean:
rm -rf $(OUT) $(APP) $(TEST_APP)
# Install rule
install:
@echo "Installing binary to $(BIN_DIR)"
install -Dm755 $(APP) $(BIN_DIR)/opt_select_ncurses
@echo "Installing header to $(INCLUDE_DIR)"
install -Dm644 inc/opt_select_ncurses_lib.h $(INCLUDE_DIR)/opt_select_ncurses_lib.h
@echo "Installing static library to $(LIB_DIR)"
install -Dm644 $(LIB) $(LIB_DIR)/libopt_select_ncurses.a
@echo "Checking whether to copy full project tree..."
@if [ "$$(realpath .)" = "$$(realpath $(SHARE_DIR))" ]; then \
echo "⚠️ Skipping project tree copy (already inside $(SHARE_DIR))"; \
else \
echo "Installing full project tree to $(SHARE_DIR)"; \
mkdir -p $(SHARE_DIR); \
cp -r inc src scripts Makefile README.md options.txt $(LIB) $(SHARE_DIR)/ ; \
fi
@echo "Installation completed."
# Include dependency files
-include $(DEPS)
.PHONY: all clean test test_single_opt test_multi_opt
test: test_single_opt test_multi_opt
test_single_opt:
@echo
@read -p "test single select opt. Press enter to start" var
@echo "Creating options file..."
@rm -fv ./options.txt
@echo "Please choose an option" >> ./options.txt
@echo "abcd" >> ./options.txt
@echo "efgh" >> ./options.txt
@echo "ijkl" >> ./options.txt
@echo "mnop" >> ./options.txt
@echo "qrst" >> ./options.txt
@echo "uvw" >> ./options.txt
@echo "xyz" >> ./options.txt
@echo "qwer" >> ./options.txt
@echo "asdf" >> ./options.txt
@echo "zxcv" >> ./options.txt
@echo "option1" >> ./options.txt
@echo "option2" >> ./options.txt
@echo "option3" >> ./options.txt
@echo "option4" >> ./options.txt
@echo "option5" >> ./options.txt
@echo "new option6" >> ./options.txt
@echo "new new option7" >> ./options.txt
@echo "again new option8" >> ./options.txt
$(APP) in_file=./options.txt out_file=./options.txt udp_dbg_port=8050
@echo "Selected option is"
@cat options.txt
@echo
test_multi_opt:
@echo
@read -p "test multi select opt. Press enter to start" var
@echo "Creating options file..."
@rm -fv ./options.txt
@echo "Please choose an option" >> ./options.txt
@echo "option1" >> ./options.txt
@echo "option2" >> ./options.txt
@echo "option3" >> ./options.txt
@echo "option4" >> ./options.txt
@echo "option5" >> ./options.txt
@echo "new option6" >> ./options.txt
@echo "new new option7" >> ./options.txt
@echo "again new option8" >> ./options.txt
$(APP) in_file=./options.txt out_file=./options.txt multi_select=yes #udp_dbg_port=8050
@echo "Selected option is"
@cat options.txt
@echo
test_single_opt2:
@echo
@read -p "test single select opt. Press enter to start" var
@echo "Creating options file..."
@rm -fv ./options.txt
@echo "Please choose an option" >> ./options.txt
@echo "1" >> ./options.txt
@echo "2" >> ./options.txt
@echo "3" >> ./options.txt
@echo "4" >> ./options.txt
@echo "5" >> ./options.txt
@echo "6" >> ./options.txt
@echo "7" >> ./options.txt
@echo "8" >> ./options.txt
@echo "9" >> ./options.txt
@echo "10" >> ./options.txt
@echo "11" >> ./options.txt
@echo "12" >> ./options.txt
@echo "13" >> ./options.txt
@echo "14" >> ./options.txt
@echo "15" >> ./options.txt
@echo "16" >> ./options.txt
@echo "17" >> ./options.txt
@echo "18" >> ./options.txt
@echo "19" >> ./options.txt
@echo "20" >> ./options.txt
@echo "21" >> ./options.txt
@echo "22" >> ./options.txt
@echo "23" >> ./options.txt
@echo "24" >> ./options.txt
@echo "25" >> ./options.txt
@echo "26" >> ./options.txt
$(APP) in_file=./options.txt out_file=./options.txt udp_dbg_port=8050 multi_select=yes
@echo "Selected option is"
@cat options.txt
@echo