-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
211 lines (180 loc) · 5.38 KB
/
Makefile
File metadata and controls
211 lines (180 loc) · 5.38 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
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
# vim:ts=8:sw=8:noexpandtab:
# Makefile copied from libcmini - THANKS!
#
# disable verbose builds by default
# If you want to see all the gory details of the build process,
# run "VERBOSE=yes make <target>"
ifndef VERBOSE
VERBOSE=no
endif
ifeq (,$(filter $(VERBOSE),Y yes))
Q=@
v=
else
Q=
v=v
endif
all:$(patsubst %,%/$(APP),$(TRGTDIRS))
#
# ONLY_68K: for faster developing; set to Y to build only the 68000 library
# BUILD_CF: Build ColdFire binaries.
#
ONLY_68K=N
BUILD_CF=Y
BUILD_FAST=$(shell if $(CC) -mfastcall -E - < /dev/null >/dev/null 2>&1; then echo Y; else echo N; fi)
BUILD_SOFT_FLOAT=Y
BUILD_SHORT=Y
COMPILE_ELF=Y
-include Make.config
-include Make.config.local
ifneq (,$(filter $(COMPILE_ELF),Y yes))
CROSSPREFIX=m68k-atari-mintelf-
else
CROSSPREFIX=m68k-atari-mint-
endif
CFLAGS+=\
-Os \
-fomit-frame-pointer \
-lxyzst
CC=$(CROSSPREFIX)gcc
LD=$(CROSSPREFIX)ld
CPP=$(CROSSPREFIX)cpp
OBJCOPY=$(CROSSPREFIX)objcopy
AR=$(CROSSPREFIX)ar
RANLIB=$(CROSSPREFIX)ranlib
INCLUDE=-Iinclude -I. -I/opt/m68k-atari-mintelf/include
SRCDIR=src
CSRCS= $(wildcard $(SRCDIR)/*.c)
ASRCS= $(wildcard $(SRCDIR)/*.S)
BUILDDIR=build
ifneq (,$(filter $(ONLY_68K),Y yes))
# asume a multi-lib without flags ar m68000
# NOTE \s?$ is important - gcc on Windows outputs \r\n-lineendings but MSYS's grep only accept \n -> \s eats \r
MULTILIBDIRS := $(shell $(CC) -print-multi-lib | grep -E ';\s?$$' | sed -e "s/;.*//")
else
MULTILIBDIRS := $(shell $(CC) -print-multi-lib | sed -e "s/;.*//")
ifeq (,$(filter $(BUILD_FAST),Y yes))
MULTILIBDIRS := $(shell echo $(MULTILIBDIRS) | sed -e 's/\S*fastcall\S*/ /g')
endif
ifeq (,$(filter $(BUILD_CF),Y yes))
MULTILIBDIRS := $(shell echo $(MULTILIBDIRS) | sed -e 's/\S*m5475\S*/ /g')
endif
ifeq (,$(filter $(BUILD_SOFT_FLOAT),Y yes))
MULTILIBDIRS := $(shell echo $(MULTILIBDIRS) | sed -e 's/\S*soft-float\S*/ /g')
endif
ifeq (,$(filter $(BUILD_SHORT),Y yes))
MULTILIBDIRS := $(shell echo $(MULTILIBDIRS) | sed -e 's/\S*short\S*/ /g')
endif
endif
MULTILIBFLAGS = $(shell $(CC) -print-multi-lib | grep '^$(1);' | sed -e 's/^.*;//' -e 's/@/ -/g')
LIBDIRS=$(patsubst %,$(BUILDDIR)/%,$(MULTILIBDIRS))
OBJDIRS=$(patsubst %,%/objs,$(LIBDIRS))
COBJS=$(patsubst $(SRCDIR)/%.o,%.o,$(patsubst %.c,%.o,$(CSRCS)))
AOBJS=$(patsubst $(SRCDIR)/%.o,%.o,$(patsubst %.S,%.o,$(ASRCS)))
OBJS=$(COBJS) $(AOBJS)
LIBC=libtoscurses.a
LIBS=$(patsubst %,%/$(LIBC),$(LIBDIRS))
all: dirs libs
libs: $(LIBS)
dirs::
$(Q)mkdir -p $(LIBDIRS) $(OBJDIRS)
clean:
@rm -r$(v) $(patsubst %,$(BUILDDIR)/%,$(shell ls $(BUILDDIR)))
all:$(patsubst %,%/$(APP),$(TRGTDIRS))
#
# multilib flags
#
define MULTILIBFLAGS_TEMPLATE
$(BUILDDIR)/$(1)/%: CFLAGS += $(call MULTILIBFLAGS,$(1)) -L/opt/m68k-atari-mintelf/lib/$(1)
endef
$(foreach DIR,$(MULTILIBDIRS),$(eval $(call MULTILIBFLAGS_TEMPLATE,$(DIR))))
#
# generate pattern rules for multilib object files
#
define CC_TEMPLATE
$(1)/objs/%.o:$(SRCDIR)/%.c
$(Q)echo "CC $$(@)"
$(Q)$(CC) -MMD -MP -MF $$(@:.o=.d) $$(CFLAGS) $(INCLUDE) -c $$< -o $$@
$(1)/objs/%.o:$(SRCDIR)/%.S
$(Q)echo "CC $$(@)"
$(Q)$(CC) -MMD -MP -MF $$(@:.o=.d) $$(CFLAGS) $(INCLUDE) -c $$< -o $$@
$(1)/%.o:$(SRCDIR)/%.S
$(Q)echo "CC $$(@)"
$(Q)$(CC) -MMD -MP -MF $$(@:.o=.d) $$(CFLAGS) $(INCLUDE) -c $$< -o $$@
endef
$(foreach DIR,$(LIBDIRS),$(eval $(call CC_TEMPLATE,$(DIR))))
#
# generate pattern rules for multilib archive
#
define ARC_TEMPLATE
$(1)_OBJS=$(patsubst %,$(1)/objs/%,$(OBJS))
$(1)/$(LIBC): $$($(1)_OBJS)
$(Q)echo "AR $$@"
$(Q)$(AR) cr $$@ $$?
$(Q)$(RANLIB) $$@
LIBDEPEND+=$$($1_OBJS)
LIBSE+=$(1)/$(LIBC)
endef
$(foreach DIR,$(LIBDIRS),$(eval $(call ARC_TEMPLATE,$(DIR))))
.PHONY: release
release: all
RELEASETAG=$$(git tag --contains | sed -e 's/v//' | sed -e 's/ //g') ;\
RELEASEDIR=libcmini-$$RELEASETAG ;\
if [ "x$$RELEASETAG" != "x" ] ; then\
mkdir -p $$RELEASEDIR/lib ;\
cp -r include $$RELEASEDIR ;\
for i in $(MULTILIBDIRS); do \
mkdir -p $$RELEASEDIR/lib/$$i ;\
cp $(BUILDDIR)/$$i/libcmini.a $$RELEASEDIR/lib/$$i ;\
cp $(BUILDDIR)/$$i/crt0.o $$RELEASEDIR/lib/$$i ;\
done ;\
chown -R 0:0 $$RELEASEDIR/* ;\
tar -C $$RELEASEDIR -cvzf $$RELEASEDIR.tar.gz . ;\
chmod 644 $$RELEASEDIR.tar.gz ;\
fi ;\
ls -l
.PHONY: printvars
printvars:
@$(foreach V,$(.VARIABLES), $(if $(filter-out environment% default automatic, $(origin $V)),$(warning $V=$($V))))
install: all
ifeq (,$(PREFIX))
PREFIX = /opt/libtoscurses
endif
ifeq (,$(PREFIX_FOR_INCLUDE))
PREFIX_FOR_INCLUDE =
endif
ifeq (,$(PREFIX_FOR_LIB))
PREFIX_FOR_LIB =
endif
ifneq (,$(PREFIX)$(PREFIX_FOR_INCLUDE)$(PREFIX_FOR_LIB))
ifneq (,$(DESTDIR))
ERR := $(error Options DESTDIR and PREFIX[_FOR_(INCLUDE|LIB)] are mutually incompatible. Use either DESTDIR or PREFIX...)
endif
ifneq (,$(PREFIX))
ifeq (,$(PREFIX_FOR_INCLUDE))
PREFIX_FOR_INCLUDE = $(PREFIX)/include
endif
ifeq (,$(PREFIX_FOR_LIB))
PREFIX_FOR_LIB = $(PREFIX)/lib
endif
endif
else
PREFIX_FOR_INCLUDE = $(DESTDIR)/usr/include
PREFIX_FOR_LIB = $(DESTDIR)/usr/lib
endif
ifneq (,$(PREFIX_FOR_INCLUDE))
install : install-include
install-include:
@mkdir -pv $(PREFIX_FOR_INCLUDE)/toscurses
@cp -arv include/* $(PREFIX_FOR_INCLUDE)
endif
ifneq (,$(PREFIX_FOR_LIB))
install : install-libs
install-libs:
@for i in $(MULTILIBDIRS); do \
mkdir -pv $(PREFIX_FOR_LIB)/$$i; \
cp -av $(BUILDDIR)/$$i/$(LIBC) $(PREFIX_FOR_LIB)/$$i; \
done
endif
lint:
cppcheck -q --std=c99 --enable=performance --language=c --template=gcc src/*.c