summaryrefslogtreecommitdiffstats
path: root/wlite/GNUmakefile.fpic
blob: 420ef0c7c367f085777f4b371650362b14a2cca7 (plain)
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
PACKAGE = wlite
VERSION = 0.8.1

prefix      := /usr/local
exec_prefix := $(prefix)
libdir      := $(exec_prefix)/lib
includedir  := $(prefix)/include

.PHONY: all
.PHONY: check
.PHONY: install installdirs install-strip uninstall
.PHONY: clean distclean maintainer-clean mostlyclean
.PHONY: dist

###############################################################################

ifdef SMALL
   CDFLAGS += -DWLITE_EXTENSIONS=0
   CDFLAGS += -DWLITE_AMBI_LOCALE=0
   CDFLAGS += -DWLITE_ENVIRONMENT=0
endif

ifndef LARGE
   CDFLAGS += -DWLITE_XBMP_CHAR=0
endif

ifdef DEBUG
   CFLAGS   = -O0 -g -Wall
   ifeq "dmalloc" "$(DEBUG)"
      CDFLAGS += -DDMALLOC_FUNC_CHECK=1
      LDFLAGS  = -ldmalloc
   endif
   ifeq "efence" "$(DEBUG)"
      LDFLAGS  = -lefence
   endif
else
   CFLAGS   = -Os -Wall
   CDFLAGS += -DNDEBUG
endif

ifeq "diet" "$(basename $(firstword $(CC)))"
   FATCC = $(wordlist 2,$(words $(CC)),$(CC))
   FATCFLAGS = $(CFLAGS) -std=gnu99
else
   override CFLAGS += -std=gnu99
   FATCC = $(CC)
   FATCFLAGS = $(CFLAGS)
endif

override CFLAGS += $(CDFLAGS)

libraries  = libwlite.a
unicodeorg = CaseFolding.txt EastAsianWidth.txt UnicodeData.txt
tests      = test-wcwidth test-string test-stdlib
includes   = wlite_config.h wlite_wchar.h wlite_wctype.h wlite_stdlib.h
functions  = $(wildcard wlite_*.c)
sources    = to_c.c to_c.h $(functions) $(addsuffix .c,$(tests) $(to_c))
members    = wcmp.o $(patsubst %.c,%.o,$(functions) $(c_unidata))
objects    = to_c.o wcmp.o $(to_c) $(tests)
archives   = $(PACKAGE)-$(VERSION).tar.gz
makefiles  = $(wildcard *[mM]akefile)
unidata    = $(addsuffix .dat,$(unicodeorg))
c_unidata  = $(patsubst %.txt.dat,%.dat.c,$(unidata))
to_c       = $(patsubst %.txt.dat,to_c-%,$(unidata))
charset_in = $(wildcard test.*.txt)
utf8_out   = $(patsubst test.%.txt,%.utf-8.txt,$(charset_in))

.INTERMEDIATE: $(c_unidata)

libwlite.a: libwlite.a($(members))
libwlite.a(wcmp.o): wcmp.c $(includes)
libwlite.a(wlite_%.o): wlite_%.c $(includes)
libwlite.a(CaseFolding.dat.o): CaseFolding.dat.c $(includes)
libwlite.a(EastAsianWidth.dat.o): EastAsianWidth.dat.c $(includes)
CaseFolding.dat.c: to_c-CaseFolding CaseFolding.txt.dat $(includes)
EastAsianWidth.dat.c: to_c-EastAsianWidth EastAsianWidth.txt.dat $(includes)
UnicodeData.dat.c: to_c-UnicodeData UnicodeData.txt.dat $(includes)
to_c-CaseFolding: to_c-CaseFolding.c wcmp.o to_c.o $(includes)
to_c-EastAsianWidth: to_c-EastAsianWidth.c wcmp.o to_c.o $(includes)
to_c-UnicodeData: to_c-UnicodeData.c wcmp.o to_c.o $(includes)
to_c.o: to_c.c to_c.h $(includes)
	$(FATCC) $(FATCFLAGS) -c -o $@ $<
$(archives):  $(unidata) $(sources) $(charset_in) $(includes)
$(includes): $(makefiles)

test-wcwidth: test-wcwidth.c $(libraries)
test-string: test-string.c $(libraries)
test-stdlib: test-stdlib.c $(libraries)

TAGS tags: $(sources)
	-etags $(filter %.c,$^)
	-ctags $(filter %.c,$^)

%.h: $(makefiles)
	sed -e "s/\(\$$package\>\)[^$$]*/\1: $(PACKAGE) /gI" \
	    -e "s/\(\$$version\>\)[^$$]*/\1: $(VERSION) /gI" $@ > $@.tmp
	mv $@.tmp $@
%: %.c
	$(FATCC) $(FATCFLAGS) $(LDFLAGS) -o $@ $(filter %.c %.o %.a,$^)
%.dat.c: %.txt.dat
	cat $(filter %.txt.dat,$^) | \
	$(CURDIR)/$(patsubst %.dat.c,to_c-%,$@) > $@ 2> /dev/null
%.utf-8.txt: test.%.txt
	iconv -f $* -t $(subst .,,$(suffix $(basename $@))) < $< > $@
%.exclude:
	echo $(notdir $(CURDIR))/$@ > $@
	for x in $(wildcard $@ RCS .[^.]* *.tar.*); \
	do echo $(notdir $(CURDIR))/$${x} >> $@; \
	done
	echo $(notdir $(CURDIR))/$(basename $@).tar >> $@
%.tar: %.exclude
	tar cv -C .. -X $< -f $@ $(notdir $(CURDIR))
%.tar.bz2: %.tar
	bzip2 -9 -c $< > $@
%.tar.gz: %.tar
	gzip -9 -c $< > $@

all: $(libraries)
check: $(tests) $(utf8_out)
	for test in $(filter $(tests),$+); \
	do cat $(filter $(utf8_out),$+) | ./$${test}; \
	done
clean: mostlyclean
	$(RM) $(libraries) $(utf8_out)
dist: maintainer-clean
	$(MAKE) $(archives)
distclean: clean
	$(RM) $(members) $(c_unidata)
maintainer-clean: distclean
	$(RM) $(archives) TAGS tags $(wildcard core core.*) $(wildcard *.tmp)
mostlyclean:
	$(RM) $(objects)
install: installdirs $(includes) $(libraries)
	install $(filter $(libraries),$^) $(libdir)
	install -m 644 $(filter $(includes),$^) $(includedir)
installdirs: $(libdir) $(includedir)
	install -d $^
install-strip: install
	for symbols in $(libraries); do strip -x -g $(libdir)/$${symbols}; done
uninstall:
	for installed in $(libraries); do $(RM) $(libdir)/$${installed}; done
	for installed in $(includes); do $(RM) $(includedir)/$${installed}; done