-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
82 lines (61 loc) · 2.05 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
# SPDX-License-Identifier: AGPL-3.0-or-later
# Authors: Ali Aqrabawi, <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public
# License Version 3.0 as published by the Free Software Foundation;
# either version 3.0 of the License, or (at your option) any later
# version.
#
# Copyright (C) 2024 Okda Networks, <[email protected]>
#
INSTALL_DIR = /usr/local/bin
LOG_DIR := /var/log/onmcli
CC ?= gcc
CFLAGS := -Wall
LIB_PATH := -L/usr/local/lib/
INCLUDE_PATH := -I$(CURDIR)
LIBS := -lyang -lsysrepo -lcrypt -lbsd
# Directories
SRC_DIR := src
YCORE_DIR := $(SRC_DIR)/commands/yang_core
LIBCLI_DIR := lib/libcli
# libcli source files
LIBCLI_SRC := $(wildcard $(LIBCLI_DIR)/*.c)
# Source files
YCORE_SRC := $(wildcard $(YCORE_DIR)/*.c)
COMMANDS_SRC := $(SRC_DIR)/commands/default_cmd.c $(SRC_DIR)/commands/sysrepo_cmd.c $(YCORE_SRC) $(LIBCLI_SRC)
UTILS_SRC := $(SRC_DIR)/onm_main.c $(SRC_DIR)/onm_cli.c $(SRC_DIR)/onm_sysrepo.c $(SRC_DIR)/utils.c $(SRC_DIR)/onm_logger.c
# Object files
OBJ := $(COMMANDS_SRC:.c=.o) $(UTILS_SRC:.c=.o)
# Executable
EXEC := onmcli
.PHONY: all clean run debug install uninstall
all: $(EXEC)
debug: CFLAGS += -g --vtv-debug
debug: $(EXEC)
$(EXEC): $(OBJ)
$(CC) $(CFLAGS) $^ -o $@ $(INCLUDE_PATH) $(LIB_PATH) $(LIBS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@ $(INCLUDE_PATH)
run: all
./$(EXEC)
clean:
rm -f $(OBJ) $(EXEC) onmcli.log valgrind-out.txt
install: $(EXEC)
# Create the log directory and set permissions
install -d $(LOG_DIR)
chown $(USER):$(USER) $(LOG_DIR)
chmod 755 $(LOG_DIR)
# Create the log file and set permissions
touch $(LOG_DIR)/onmcli.log
chown $(USER):$(USER) $(LOG_DIR)/onmcli.log
chmod 666 $(LOG_DIR)/onmcli.log
# Copy the binary to /usr/local/bin
install -d $(INSTALL_DIR)
install $(EXEC) $(INSTALL_DIR)
uninstall:
# Remove the binary from /usr/local/bin
rm -f $(INSTALL_DIR)/$(EXEC)
# Remove the log file and directory
rm -rf $(LOG_DIR)