-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
236 lines (202 loc) · 6.33 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
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
##
# A GNU make (gmake) Makefile for building today tools for Unix
#
# Authors:
# NC [email protected]
# JFL [email protected]
#
# Changes:
# 2003-06-01 NC Published at http://www.linuxha.com/common/wea_tools.html
# 2018-12-26 JFL Output files into the bin/$(uname -s).$(uname -p)[/Debug] subdirectory.
# 2019-01-18 JFL Use variable PROGRAMS from Files.mak, instead of ALL.
# 2022-06-22 JFL Fixed the installation, broken on 2019-01-18.
# Added a make uninstall target.
# 2022-06-24 JFL Fixed the processor detection on a Raspberry Pi.
# 2023-11-22 JFL Added NMaker/include to the CC include directories.
#
# Standard installation directory macros, based on
# https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
ifeq "$(prefix)" ""
ifeq "$(bindir)" ""
ifneq "$(findstring :/usr/local/bin:,:$(PATH):)" ""
prefix := /usr/local # If /usr/local/bin is in the PATH, use it
else
prefix := /usr # Else use /usr/bin
endif
else # Extract the prefix from the bindir provided
prefix := $(dir $(bindir))
endif
endif
# Remove the trailing / from prefix, if any
prefix := $(patsubst %/,%,$(strip $(prefix)))
datarootdir = $(prefix)/share
datadir = $(datarootdir)
exec_prefix = $(prefix)
# Where to put the executables.
bindir = $(exec_prefix)/bin
# Where to put the libraries.
libdir = $(exec_prefix)/lib
# Where to put the info files.
infodir = $(datarootdir)/info
# Identify the OS and processor, and generate an output base directory name from that
ifeq "$(OS)" "" # If $(OS) is undefined or empty
OS := $(shell uname -s)
PROC := $(shell uname -p)
MACHINE := $(shell uname -m)
ifeq "$(OS)" "OSF1"
ifeq "$(MACHINE)" "alpha"
OS := Tru64
endif
endif
ifeq "$(OS)" "WindowsNT"
OS := WIN32
endif
ifeq "$(PROC)" "unknown" # On a Raspberry Pi, it's unknown, and MACHINE = armv7
PROC := $(MACHINE)
endif
# Define the output base directory
OSP := $(OS).$(PROC)
# Now handle the special case of Unix-compatible shells for Windows
ifneq "$(findstring MINGW32, $(OS))" "" # Ex: "MINGW32_NT-6.1"
# MigGW shell if NOT case sensitive, so use a well readable camelcase spelling
OSP := MinGW32
# 2013-12-16 Actually, the 64-bits tool chain also reports MINGW32_NT-6.1
# So distinguish the two by whether /mingw is mounted on C:\MinGW or C:\MinGW64
ifneq "$(shell mount | grep -i /mingw64)" ""
# MigGW shell if NOT case sensitive, so use a well readable camelcase spelling
OSP := MinGW64
endif
endif
ifneq "$(findstring MINGW64,$(OS))" "" # Ex: ?
OSP := MinGW64
endif
ifneq "$(findstring CYGWIN,$(OS))" "" # Ex: "CYGWIN_NT-6.1-WOW64"
# Cygwin shell if case sensitive, so use lower case
OSP := cygwin
endif
endif
# Output in the bin subdirectory, unless overridden by OUTDIR
ifdef OUTDIR
ifneq "$(OUTDIR)" "."
OD := $(OUTDIR)/
else
OD :=
endif
else
OD := bin/
endif
# Distinguish the output directory bases for normal and debug output
# Normal output base directory
OSPN := $(OD)$(OSP)
# Debug output base directory
OSPD := $(OD)$(OSP)/debug
# Finally define the output directories for the current debug mode
ifdef _DEBUG
OSP := $(OSPD)
else
OSP := $(OSPN)
endif
# Sources path
SP = .
# Objects path
OP = $(OSP)/OBJ
OPN = $(OSPN)/OBJ
OPD = $(OSPD)/OBJ
# Listings path
LP = $(OSP)/LIST
LPN = $(OSPN)/LIST
LPD = $(OSPD)/LIST
# Executables path
XP = $(OSP)
XPN = $(OSPN)
XPD = $(OSPD)
# Build options
CFLAGS = -O -Wall -I NMaker/include
CLIBS = -lm
LDLIBS = /usr/lib/crt1.o /usr/lib/crti.o # /lib/ld-linux.so.2
# Make file messages control
TRACE_MSGS = $(or $(filter-out 0, $(VERBOSE)), $(filter-out 0, $(DEBUG)))
REPORT_FAILURE = (ERR=$$? ; echo " ... FAILED" ; exit $$ERR)
# Pattern rules for compiling any standalone C or C++ source.
$(OPN)/%.o: %.c
$(MAKE) -$(MAKEFLAGS) dirs
$(info Compiling $<)
$(CC) $(CFLAGS) $(CPPFLAGS) -U_DEBUG -o $@ -c $< || $(REPORT_FAILURE)
#(info ... done)
$(OPD)/%.o: %.c
$(MAKE) -$(MAKEFLAGS) ddirs
$(info Compiling $<)
$(CC) $(CFLAGS) $(CPPFLAGS) -D_DEBUG -o $@ -c $< || $(REPORT_FAILURE)
#(info ... done)
$(XPN)/%: $(OPN)/%.o
$(MAKE) -$(MAKEFLAGS) dirs
$(info Linking $@)
$(CC) -o $@ $^ $(CLIBS) || $(REPORT_FAILURE)
#(info ... done)
$(XPD)/%: $(OPD)/%.o
$(MAKE) -$(MAKEFLAGS) dirs
$(info Linking $@)
$(CC) -o $@ $^ $(CLIBS) || $(REPORT_FAILURE)
#(info ... done)
.SILENT:
# Default rule.
.PHONY: default all
default: all
include Files.mak
all: dirs $(PROGRAMS)
.PHONY: dirs ddirs
dirs: $(XPN) $(OPN) $(LPN)
ddirs: $(XPD) $(OPD) $(LPD)
$(XPN) $(OPN) $(LPN) $(XPD) $(OPD) $(LPD):
$(info Creating directory $@)
mkdir -p $@
# The local target programs are actually to be built in the $(XP) subdirectory
%: dirs $(XP)/%
true
# List of object files for each program
$(XP)/localtime: $(OP)/localtime.o $(OP)/parsetime.o
$(XP)/potm: $(OP)/potm.o $(OP)/moontx.o $(OP)/parsetime.o
$(XP)/today: $(OP)/today.o $(OP)/datetx.o $(OP)/moontx.o $(OP)/nbrtxt.o $(OP)/timetx.o $(OP)/sun.o $(OP)/parsetime.o
$(XP)/sunrise: $(OP)/sunrise.o $(OP)/moontx.o $(OP)/sun.o $(OP)/parsetime.o
$(XP)/sunset: $(OP)/sunset.o $(OP)/moontx.o $(OP)/sun.o $(OP)/parsetime.o
.PHONY: install
install: all
cd $(XP) && install -p $(PROGRAMS) $(bindir)
.PHONY: uninstall
uninstall:
cd $(bindir) && rm -f $(PROGRAMS)
.PHONY: clean
clean:
-$(RM) $(OPD)/* >/dev/null 2>&1
-rmdir $(OPD) >/dev/null 2>&1
-$(RM) $(LPD)/* >/dev/null 2>&1
-rmdir $(LPD) >/dev/null 2>&1
-$(RM) $(XPD)/* >/dev/null 2>&1
-rmdir $(XPD) >/dev/null 2>&1
-$(RM) $(OPN)/* >/dev/null 2>&1
-rmdir $(OPN) >/dev/null 2>&1
-$(RM) $(LPN)/* >/dev/null 2>&1
-rmdir $(LPN) >/dev/null 2>&1
-$(RM) $(XPN)/* >/dev/null 2>&1
-rmdir $(XPN) >/dev/null 2>&1
-$(RM) *.log >/dev/null 2>&1
define HELP
Usage: make [MAKEOPTS] [MAKEDEFS] [TARGETS]
Targets:
all Build all programs defined in Files.mak. Default.
clean Delete all files generated by this Makefile
help Display this help message
install Install the programs into $$bindir. (Use make -n to dry-run it)
localtime Build $(XP)/localtime
potm Build $(XP)/potm
today Build $(XP)/today
sunrise Build $(XP)/sunrise
sunset Build $(XP)/sunset
uninstall Uninstall the programs from $$bindir.
Default: $$bindir = $(bindir)
endef
# Makedefs:
# _DEBUG=1 Build the debug version of the programs
export HELP
help:
@echo "$$HELP"