-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
178 lines (141 loc) · 3.62 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
# vim: set noet ts=8 sw=8 sts=8:
VPATH=src
CC=gcc
LD=$(CC)
# Program (Msys2 automagically adds .exe)
TARGET=t64fix
# Version (used for `t64fix --help` and `make dist`)
VERSION=0.4.x
# Installation prefix for `make install`
PREFIX ?= /usr/local
# Installation path for the man page
MAN_PATH = $(PREFIX)/share/man/man1
# Check for GCC
ifneq (,$(findstring gcc,$(CC)))
warn_qualifiers := -Wdiscarded-qualifiers
endif
# Check for clang
ifneq (,$(findstring clang,$(CC)))
warn_qualifiers := -Wignored-qualifiers
endif
# These flags are know to work with GCC >= 8.3.0 and clang-14
CFLAGS=-W -Wall -Wextra -pedantic -std=c99 -Wshadow -Wpointer-arith \
-Wcast-qual -Wcast-align -Wstrict-prototypes -Wmissing-prototypes \
-Wswitch-default -Wswitch-enum -Wuninitialized -Wconversion \
-Wredundant-decls -Wnested-externs -Wunreachable-code -Wuninitialized \
$(warn_qualifiers) -Wsign-compare -DVERSION=\"$(VERSION)\" -g -O3
# Object files
OBJS = main.o base.o cbmdos.o d64.o optparse.o petasc.o prg.o t64.o
# Files for `make dist`
DIST_FILES = \
CHANGES.md \
COPYING \
Doxyfile \
Makefile \
README.md \
doc/man/t64fix.1 \
scripts/verify_multi.sh \
src/base.c \
src/base.h \
src/cbmdos.c \
src/cbmdos.h \
src/d64.c \
src/d64.h \
src/main.c \
src/optparse.c \
src/optparse.h \
src/petasc.c \
src/petasc.h \
src/prg.c \
src/prg.h \
src/t64.c \
src/t64.h \
src/t64types.h \
# Files for `make windist` (excluding the executable)
WINDIST_FILES = \
CHANGES.md \
COPYING \
README.md
# Distribution temp directory
DIST_DIR=t64fix-$(VERSION)
# Distrubition tarball
DIST_TGZ=$(DIST_DIR).tar.gz
# Windows distribution temp directory
ifeq ($(MSYSTEM_CARCH),x86_64)
WINDIST_DIR := t64fix-win64-$(VERSION)
endif
ifeq ($(MSYSTEM_CARCH),i686)
WINDIST_DIR := t64fix-win32-$(VERSION)
endif
WINDIST_ZIP := $(WINDIST_DIR).zip
# Target for `make [all]`
all: $(TARGET)
# dependencies of objects
base.o:
cbmdos.o:
d64.o: base.o
main.o: base.o optparse.o prg.o t64.o t64types.h
optparse.o:
petasc.o:
prg.o: base.o petasc.o t64types.h
t64.o: base.o cbmdos.o petasc.o
debug: CPPFLAGS=-DDEBUG
debug: $(TARGET)
.PHONY: doc
doc:
doxygen 1>/dev/null
.PHONY: clean
clean:
rm -f $(OBJS) $(TARGET) $(TARGET).exe
rm -rfd doc/html/*
rm -f *.html
if [ -d $(DIST_DIR) ]; then \
rm -rd $(DIST_DIR); \
fi
if [ -f $(DIST_TGZ) ]; then \
rm $(DIST_TGZ); \
fi
if [ "x$(WINDIST_DIR)" != "x" -a -d $(WINDIST_DIR) ]; then \
rm -rd $(WINDIST_DIR); \
fi
if [ "x$(WINDIST_DIR)" != "x" -a -f $(WINDIST_ZIP) ]; then \
rm $(WINDIST_ZIP); \
fi
install-bin: $(TARGET)
install -s -m 755 -g root -o root $(TARGET) $(PREFIX)/bin
install-man: doc/man/t64fix.1
install -g root -o root -d $(MAN_PATH)
install -m 755 -g root -o root doc/man/t64fix.1 $(MAN_PATH)
gzip -f $(MAN_PATH)/t64fix.1
install: install-bin install-man
# Create source distribution tarball
dist: $(DIST_FILES)
if [ -d $(DIST_DIR) ]; \
then rm -rd $(DIST_DIR); \
fi
if [ -f $(DIST_TGZ) ]; then \
rm $(DIST_TGZ); \
fi
mkdir $(DIST_DIR)
cp -a --parents $(DIST_FILES) $(DIST_DIR)
tar -czf $(DIST_TGZ) $(DIST_DIR)
rm -rd $(DIST_DIR)
# Create Windows distribution zipfile
windist: $(TARGET) $(DIST_FILES)
if [ -d $(WINDIST_DIR) ]; then \
rm -rd $(WINDIST_DIR); \
fi
if [ -f $(WINDIST_ZIP) ]; then \
rm $(WINDIST_ZIP); \
fi
mkdir $(WINDIST_DIR)
cp -a --parents $(WINDIST_FILES) $(WINDIST_DIR)
cp -a $(TARGET).exe $(WINDIST_DIR)
strip $(WINDIST_DIR)/$(TARGET).exe
zip $(WINDIST_ZIP) $(WINDIST_DIR)/*
rm -rd $(WINDIST_DIR)
# generic rule to build objects from source files
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
$(TARGET): $(OBJS)
$(LD) -o $(TARGET) $(OBJS)