-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.mk.in
More file actions
141 lines (101 loc) · 3.45 KB
/
base.mk.in
File metadata and controls
141 lines (101 loc) · 3.45 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
# Configuration Base Makefile Fragment
########################################
# Version
VERSION_MAJOR := @VERSION_MAJOR@
VERSION_MINOR := @VERSION_MINOR@
VERSION_PATCH := @VERSION_PATCH@
VERSION_PRERELEASE := @VERSION_PRERELEASE@
VERSION := @VERSION@
########################################
# Project
PROJECT := @PROJECT@
########################################
# Targets
TARGETS := @TARGETS@
TARGETS_INSTALL = $(foreach var, ${TARGETS}, ${var}-install)
TARGETS_UNINSTALL = $(foreach var, ${TARGETS}, ${var}-uninstall)
########################################
# Root Path
ROOT_DIR := @ROOT_DIR@
########################################
# Miscellaneous
MKDIR_P := mkdir -p
SHELL := /bin/bash
########################################
# Prefix - Used For Installation Directory
PREFIX := $(if ${PREFIX},${PREFIX},$(if ${DESTDIR},/usr,/usr/local))
########################################
# Directories
HDR_DIR := ${ROOT_DIR}/include
BUILD_DIR := ${ROOT_DIR}/build
BUILD_OBJ_DIR = ${BUILD_DIR}/obj
BUILD_BIN_DIR := ${BUILD_DIR}/bin
BUILD_LIB_DIR := ${BUILD_DIR}/lib
BUILD_PKG_DIR := ${BUILD_DIR}/pkg
########################################
# Logging
BUILD_LOG_FILE = ${BUILD_DIR}/build.log
########################################
# Superuser
IS_SUPERUSER = $(shell [ `id -u` -eq 0 ] && echo 1 || echo 0)
########################################
# Compiler, Preprocessor, Linker
CC := @CC@
CXX := @CXX@
CFLAGS := @CFLAGS@
CXXFLAGS := @CXXFLAGS@
CPPFLAGS := @CPPFLAGS@
LDFLAGS := @LDFLAGS@
########################################
# Definitions
define build_log
@echo "$(shell date "+%d/%m/%Y %X.%06N") $(1)"
@echo "$(shell date "+%d/%m/%Y %X.%06N") $(1)" >> ${BUILD_LOG_FILE}
endef
########################################
# Generic Targets
.PHONY: all install uninstall superuser no-superuser clean
all: ${TARGETS}
-include ${BUILD_DIR}/sources.mk
-include ${BUILD_DIR}/configs.mk
install: ${TARGETS_INSTALL}
uninstall: ${TARGETS_UNINSTALL}
${BUILD_OBJ_DIR}/%.o: ${ROOT_DIR}/%.c
@${MKDIR_P} $(dir $@)
@$(call build_log, ${CC} ${CPPFLAGS} ${CFLAGS} -c $< -o $@)
@${CC} ${CPPFLAGS} ${CFLAGS} -c $< -o $@ >> ${BUILD_LOG_FILE} 2>&1 || (echo "Error(s) detected! Please refer to '${BUILD_LOG_FILE}'"; exit 1)
${BUILD_OBJ_DIR}/%.o: ${ROOT_DIR}/%.cpp
@${MKDIR_P} $(dir $@)
@$(call build_log, ${CXX} ${CPPFLAGS} ${CXXFLAGS} -c $< -o $@)
@${CXX} ${CPPFLAGS} ${CXXFLAGS} -c $< -o $@ >> ${BUILD_LOG_FILE} 2>&1 || (echo "Error(s) detected! Please refer to '${BUILD_LOG_FILE}'"; exit 1)
superuser:
ifneq ($(IS_SUPERUSER),1)
@echo "Superuser privileges needed to proceed!"
@exit 1
endif
no-superuser:
ifneq ($(IS_SUPERUSER),0)
@echo "Do not use superuser privileges here!"
@exit 1
endif
clean:
@rm -rf ${BUILD_OBJ_DIR}/*
@rm -f ${BUILD_LOG_FILE}
########################################
# User-Defined Targets (MODIFY HERE)
nocterm: ${BUILD_LIB_DIR}/libnocterm.a no-superuser
${BUILD_LIB_DIR}/libnocterm.a: ${NOCTERM_OBJ}
@$(call build_log, ${CC} <objects> -o $@)
@ar rcs $@ $^
@echo Build Successful
nocterm-install: superuser
@$(call build_log, "Installing...")
@install --target-directory ${DESTDIR}${PREFIX}/lib ${BUILD_LIB_DIR}/libnocterm.a
@cp -r ${HDR_DIR}/nocterm ${DESTDIR}${PREFIX}/include
nocterm-uninstall: superuser
@$(call build_log, "Uninstalling...")
@rm -f ${DESTDIR}${PREFIX}/lib/libnocterm.a
@rm -rf ${DESTDIR}${PREFIX}/include/nocterm
nocterm-update: superuser
@${MAKE} --no-print-directory nocterm-uninstall
@${MAKE} --no-print-directory nocterm-install