Imported Upstream version 6.0
[platform/upstream/dos2unix.git] / Makefile
1 # Author: Erwin Waterlander
2 #
3 #   Copyright (C) 2009-2012 Erwin Waterlander
4 #   All rights reserved.
5
6 #   Redistribution and use in source and binary forms, with or without
7 #   modification, are permitted provided that the following conditions
8 #   are met:
9 #   1. Redistributions of source code must retain the above copyright
10 #      notice, this list of conditions and the following disclaimer.
11 #   2. Redistributions in binary form must reproduce the above copyright
12 #      notice in the documentation and/or other materials provided with
13 #      the distribution.
14
15 #   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
16 #   EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
19 #   FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 #   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 #   OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
22 #   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 #   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 #   OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25 #   IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27 #   Description
28 #
29 #       This is a GNU Makefile that uses GNU compilers, linkers and cpp. The
30 #       platform specific issues are determined by the various OS teets that
31 #       rely on the uname(1) command and directory locations.
32 #
33 #       Set additional flags for the build with variables CFLAGS_USER,
34 #       DEFS_USER and LDFLAGS_USER.
35
36 include version.mk
37
38 CC              = gcc
39 CPP             = cpp
40 CPP_FLAGS_POD   = ALL
41 STRIP           = strip
42
43 PACKAGE         = dos2unix
44 UNIX2DOS        = unix2dos
45 MAC2UNIX        = mac2unix
46 UNIX2MAC        = unix2mac
47
48 # Native Language Support (NLS)
49 ENABLE_NLS      = 1
50 # Large File Support (LFS)
51 LFS             = 1
52 DEBUG = 0
53 UCS = 1
54
55 EXE=
56
57 BIN             = $(PACKAGE)$(EXE)
58 UNIX2DOS_BIN    = $(UNIX2DOS)$(EXE)
59 MAC2UNIX_BIN    = $(MAC2UNIX)$(EXE)
60 UNIX2MAC_BIN    = $(UNIX2MAC)$(EXE)
61
62 # DJGPP support linking of .EXEs via 'stubify'.
63 # See djgpp.mak and http://www.delorie.com/djgpp/v2faq/faq22_5.html
64
65 LINK            = ln -sf
66 LINK_MAN        = $(LINK)
67
68 prefix          = /usr
69 exec_prefix     = $(prefix)
70 bindir          = $(exec_prefix)/bin
71 datarootdir     = $(prefix)/share
72 datadir         = $(datarootdir)
73
74 docsubdir       = $(PACKAGE)-$(DOS2UNIX_VERSION)
75 docdir          = $(datarootdir)/doc/$(docsubdir)
76 localedir       = $(datarootdir)/locale
77 mandir          = $(datarootdir)/man
78 man1dir         = $(mandir)/man1
79 manext          = .1
80 man1ext         = .1
81
82 ifdef ENABLE_NLS
83         POT             = po/$(PACKAGE).pot
84         POFILES         = $(wildcard po/??.po)
85         MOFILES         = $(patsubst %.po,%.mo,$(POFILES))
86         EOX_POFILES     = po/eo-x.po
87         NLSSUFFIX       = -nls
88 endif
89
90 HTMLEXT = htm
91 DOCFILES        = $(PACKAGE).txt $(PACKAGE).$(HTMLEXT)
92 INSTALL_OBJS_DOC = README.txt NEWS.txt ChangeLog.txt COPYING.txt TODO.txt BUGS.txt $(DOCFILES)
93
94 #PODFILES       = man/man1/dos2unix.pod $(wildcard man/*/man1/dos2unix.pod)
95 PODFILES        = $(wildcard man/*/man1/dos2unix.pod)
96 MANFILES        = $(patsubst %.pod,%.1,$(PODFILES))
97
98 # On some systems (e.g. FreeBSD 4.10) GNU install is installed as `ginstall'.
99 INSTALL         = install
100
101 # On some systems (e.g. GNU Win32) GNU mkdir is installed as `gmkdir'.
102 MKDIR           = mkdir
103
104 ifdef ENABLE_NLS
105         DOS2UNIX_NLSDEFS = -DENABLE_NLS -DLOCALEDIR=\"$(localedir)\" -DPACKAGE=\"$(PACKAGE)\"
106 endif
107
108 VERSIONSUFFIX   = -bin
109
110 # ......................................................... OS flags ...
111
112 OS =
113
114 ifndef OS
115 ifneq (, $(wildcard /boot/vmlinuz*))
116         OS = linux
117 endif
118 endif
119
120 ifndef OS
121 ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
122         OS = cygwin
123 endif
124 endif
125
126 ifeq (cygwin,$(OS))
127 ifdef ENABLE_NLS
128         LDFLAGS_EXTRA = -lintl -liconv -Wl,--enable-auto-import
129 endif
130         EXE = .exe
131         # allow non-cygwin clients which do not understand cygwin
132         # symbolic links to launch applications...
133         LINK = ln -f
134         # but use symbolic links for man pages, since man client
135         # IS a cygwin app and DOES understand symlinks.
136         LINK_MAN = ln -fs
137         # Cygwin packaging standard avoids version numbers on
138         # documentation directories.
139         docsubdir       = $(PACKAGE)
140         VERSIONSUFFIX   = -cygwin
141 endif
142
143 ifndef OS
144 ifeq ($(findstring MSYS,$(shell uname)),MSYS)
145         OS = msys
146         EXE = .exe
147         VERSIONSUFFIX   = -msys
148         EO_XNOTATION=1
149         UCS =
150 ifdef ENABLE_NLS
151         LDFLAGS_EXTRA = -lintl -liconv
152 endif
153 endif
154 endif
155
156 ifndef OS
157 ifeq ($(findstring MINGW32,$(shell uname)),MINGW32)
158         OS = mingw32
159         prefix=c:/usr/local
160         EXE = .exe
161         VERSIONSUFFIX   = -win32
162         LINK = cp -f
163         EO_XNOTATION=1
164 ifdef ENABLE_NLS
165         LDFLAGS_EXTRA = -lintl -liconv
166         ZIPOBJ_EXTRA = bin/libintl-8.dll bin/libiconv-2.dll
167 endif
168 endif
169 endif
170
171 ifndef OS
172 ifeq ($(shell uname),MS-DOS)
173         OS = msdos
174         prefix=c:/djgpp
175         EXE = .exe
176         VERSIONSUFFIX   = -dos32
177         LINK_MAN = cp -f
178         docsubdir = dos2unix
179         EO_XNOTATION=1
180         UCS =
181         ZIPOBJ_EXTRA = bin/cwsdpmi.exe
182 ifdef ENABLE_NLS
183         LDFLAGS_EXTRA = -lintl -liconv
184 endif
185 endif
186 endif
187
188 ifndef OS
189 ifeq (FreeBSD, $(shell uname -s))
190         OS = freebsd
191 ifdef ENABLE_NLS
192         CFLAGS_OS     = -I/usr/local/include
193         LDFLAGS_EXTRA = -lintl -L/usr/local/lib
194 endif
195 endif
196 endif
197
198 ifeq (Darwin, $(shell uname -s))
199         OS = Darwin
200 ifdef ENABLE_NLS
201         CFLAGS_OS     = -I/usr/local/include
202         LDFLAGS_EXTRA = -lintl -L/usr/local/lib
203 endif
204 endif
205
206
207 ifndef OS
208 ifneq (, $(wildcard /opt/csw))
209         OS = sun
210 endif
211 endif
212
213 ifeq (sun,$(OS))
214         # Running under SunOS/Solaris
215         LDFLAGS_EXTRA = -lintl
216 endif
217
218 ifndef OS
219 ifeq (HP-UX, $(shell uname -s))
220         OS = hpux
221 endif
222 endif
223
224 ifeq (hpux,$(OS))
225         # Running under HP-UX
226         EXTRA_DEFS += -Dhpux -D_HPUX_SOURCE
227 endif
228
229 ifndef OS
230         OS = unknown
231 endif
232
233 # ............................................................ flags ...
234
235 # For systems that don't support Unicode or Latin-3, select
236 # Esperanto in X-notation format: EO_XNOTATION=1
237
238 ifdef EO_XNOTATION
239 EO_NOTATION = -x
240 endif
241
242 CFLAGS_USER     =
243 CFLAGS          = -O2 -Wall $(RPM_OPT_FLAGS) $(CPPFLAGS) $(CFLAGS_USER)
244
245 EXTRA_CFLAGS    = -DVER_REVISION=\"$(DOS2UNIX_VERSION)\" \
246                   -DVER_DATE=\"$(DOS2UNIX_DATE)\" \
247                   -DVER_AUTHOR=\"$(DOS2UNIX_AUTHOR)\" \
248                   -DDEBUG=$(DEBUG) \
249                   $(CFLAGS_OS)
250
251 ifeq ($(DEBUG), 1)
252         EXTRA_CFLAGS += -g
253 endif
254
255 ifdef STATIC
256         EXTRA_CFLAGS += -static
257 endif
258
259 ifdef UCS
260         EXTRA_CFLAGS += -DD2U_UNICODE
261 endif
262
263 ifdef LFS
264         EXTRA_CFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
265 endif
266
267 LDFLAGS_USER    =
268 LDFLAGS = $(RPM_OPT_FLAGS) $(LDFLAGS_EXTRA) $(LDFLAGS_USER)
269
270 DEFS_USER       =
271 DEFS            = $(EXTRA_DEFS) $(DEFS_USER)
272
273 # .......................................................... targets ...
274
275 all: $(BIN) $(MAC2UNIX_BIN) $(UNIX2DOS_BIN) $(UNIX2MAC_BIN) $(DOCFILES) $(MOFILES) $(EOX_POFILES) $(MANFILES) man/man1/dos2unix.1
276
277 common.o : common.c common.h
278         $(CC) $(DEFS) $(EXTRA_CFLAGS) $(DOS2UNIX_NLSDEFS) $(CFLAGS) -c $< -o $@
279
280 querycp.o : querycp.c querycp.h
281         $(CC) $(DEFS) $(EXTRA_CFLAGS) $(DOS2UNIX_NLSDEFS) $(CFLAGS) -c $< -o $@
282
283 dos2unix.o : dos2unix.c dos2unix.h querycp.h common.h
284         $(CC) $(DEFS) $(EXTRA_CFLAGS) $(DOS2UNIX_NLSDEFS) $(CFLAGS) -c $< -o $@
285
286 unix2dos.o : unix2dos.c unix2dos.h querycp.h common.h
287         $(CC) $(DEFS) $(EXTRA_CFLAGS) $(DOS2UNIX_NLSDEFS) $(CFLAGS) -c $< -o $@
288
289 $(BIN): dos2unix.o querycp.o common.o
290         $(CC) $+ $(LDFLAGS) -o $@
291
292 $(UNIX2DOS_BIN): unix2dos.o querycp.o common.o
293         $(CC) $+ $(LDFLAGS) -o $@
294
295 $(MAC2UNIX_BIN) : $(BIN)
296         $(LINK) $< $@
297
298 %.1 : %.pod
299         $(MAKE) -C man/man1
300
301 $(UNIX2MAC_BIN) : $(UNIX2DOS_BIN)
302         $(LINK) $< $@
303
304 mofiles: $(MOFILES)
305
306 html: $(PACKAGE).$(HTMLEXT)
307
308 txt: $(PACKAGE).txt
309
310 ps: $(PACKAGE).ps
311
312 pdf: $(PACKAGE).pdf
313
314 doc: $(DOCFILES) $(MANFILES) man/man1/dos2unix.1
315
316 tags: $(POT)
317
318 merge: $(POFILES) $(EOX_POFILES)
319
320 po/%.po : $(POT)
321         msgmerge -U $@ $(POT) --backup=numbered
322         # change timestamp in case .po file was not updated.
323         touch $@
324
325 %.mo : %.po
326         msgfmt -c $< -o $@
327
328 po/eo.mo : po/eo$(EO_NOTATION).po
329         msgfmt -c $< -o $@
330
331 $(POT) : dos2unix.c unix2dos.c common.c
332         xgettext -C --keyword=_ $+ -o $(POT)
333
334 %.txt : man/man1/%.pod
335         LC_CTYPE=C pod2text $< > $@
336
337 %.ps : man/man1/%.1
338         groff -man $< -T ps > $@
339
340 %.pdf: %.ps
341         ps2pdf $< $@
342
343 %.$(HTMLEXT) : man/man1/%.pod
344         pod2html --title="$(PACKAGE) $(DOS2UNIX_VERSION) - DOS/MAC to UNIX and vice versa text file format converter" $< > $@
345
346 install: all
347         $(MKDIR) -p -m 755 $(DESTDIR)$(bindir)
348         $(INSTALL)  -m 755 $(BIN) $(DESTDIR)$(bindir)
349         $(INSTALL)  -m 755 $(UNIX2DOS_BIN) $(DESTDIR)$(bindir)
350 ifeq ($(LINK),cp -f)
351         $(INSTALL)  -m 755 $(MAC2UNIX_BIN) $(DESTDIR)$(bindir)
352         $(INSTALL)  -m 755 $(UNIX2MAC_BIN) $(DESTDIR)$(bindir)
353 else
354         cd $(DESTDIR)$(bindir); $(LINK) $(BIN) $(MAC2UNIX_BIN)
355         cd $(DESTDIR)$(bindir); $(LINK) $(UNIX2DOS_BIN) $(UNIX2MAC_BIN)
356 endif
357         $(MKDIR) -p -m 755 $(DESTDIR)$(man1dir)
358         $(INSTALL)  -m 644 man/man1/$(PACKAGE).1 $(DESTDIR)$(man1dir)
359 ifeq ($(LINK_MAN),cp -f)
360         $(INSTALL)  -m 644 man/man1/$(PACKAGE).1 $(DESTDIR)$(man1dir)/$(MAC2UNIX).1
361         $(INSTALL)  -m 644 man/man1/$(PACKAGE).1 $(DESTDIR)$(man1dir)/$(UNIX2DOS).1
362         $(INSTALL)  -m 644 man/man1/$(PACKAGE).1 $(DESTDIR)$(man1dir)/$(UNIX2MAC).1
363 else
364         cd $(DESTDIR)$(man1dir); $(LINK_MAN) $(PACKAGE).1 $(MAC2UNIX).1
365         cd $(DESTDIR)$(man1dir); $(LINK_MAN) $(PACKAGE).1 $(UNIX2DOS).1
366         cd $(DESTDIR)$(man1dir); $(LINK_MAN) $(PACKAGE).1 $(UNIX2MAC).1
367 endif
368         $(foreach manfile, $(MANFILES), $(MKDIR) -p -m 755 $(DESTDIR)$(datarootdir)/$(dir $(manfile)) ;)
369         $(foreach manfile, $(MANFILES), $(INSTALL) -m 644 $(manfile) $(DESTDIR)$(datarootdir)/$(dir $(manfile)) ;)
370         $(foreach manfile, $(MANFILES), cd $(DESTDIR)$(datarootdir)/$(dir $(manfile)) ; $(LINK_MAN) $(PACKAGE).1 $(MAC2UNIX).1 ;)
371         $(foreach manfile, $(MANFILES), cd $(DESTDIR)$(datarootdir)/$(dir $(manfile)) ; $(LINK_MAN) $(PACKAGE).1 $(UNIX2DOS).1 ;)
372         $(foreach manfile, $(MANFILES), cd $(DESTDIR)$(datarootdir)/$(dir $(manfile)) ; $(LINK_MAN) $(PACKAGE).1 $(UNIX2MAC).1 ;)
373 ifdef ENABLE_NLS
374         @echo "-- install-mo"
375         $(foreach mofile, $(MOFILES), $(MKDIR) -p -m 755 $(DESTDIR)$(localedir)/$(basename $(notdir $(mofile)))/LC_MESSAGES ;)
376         $(foreach mofile, $(MOFILES), $(INSTALL) -m 644 $(mofile) $(DESTDIR)$(localedir)/$(basename $(notdir $(mofile)))/LC_MESSAGES/$(PACKAGE).mo ;)
377 endif
378         @echo "-- install-doc"
379         $(MKDIR) -p -m 755 $(DESTDIR)$(docdir)
380         $(INSTALL) -m 644 $(INSTALL_OBJS_DOC) $(wildcard $(PACKAGE).ps) $(wildcard $(PACKAGE).pdf) $(DESTDIR)$(docdir)
381
382 uninstall:
383         @echo "-- target: uninstall"
384         -rm -f $(DESTDIR)$(bindir)/$(BIN)
385         -rm -f $(DESTDIR)$(bindir)/$(MAC2UNIX_BIN)
386         -rm -f $(DESTDIR)$(bindir)/$(UNIX2DOS_BIN)
387         -rm -f $(DESTDIR)$(bindir)/$(UNIX2MAC_BIN)
388 ifdef ENABLE_NLS
389         $(foreach mofile, $(MOFILES), rm -f $(DESTDIR)$(localedir)/$(basename $(notdir $(mofile)))/LC_MESSAGES/$(PACKAGE).mo ;)
390 endif
391         -rm -f $(DESTDIR)$(mandir)/man1/$(PACKAGE).1
392         -rm -f $(DESTDIR)$(mandir)/man1/$(MAC2UNIX).1
393         -rm -f $(DESTDIR)$(mandir)/man1/$(UNIX2DOS).1
394         -rm -f $(DESTDIR)$(mandir)/man1/$(UNIX2MAC).1
395         $(foreach manfile, $(MANFILES), rm -f $(DESTDIR)$(datarootdir)/$(manfile) ;)
396         -rm -rf $(DESTDIR)$(docdir)
397
398 mostlyclean:
399         rm -f *.o
400         rm -f $(BIN) $(UNIX2DOS_BIN) $(MAC2UNIX_BIN) $(UNIX2MAC_BIN)
401         rm -f *.bak *~
402         rm -f *.tmp
403         rm -f man/man1/*.bak man/man1/*~
404         rm -f man/*/man1/*.bak man/*/man1/*~
405         rm -f po/*.bak po/*~
406         rm -f po/*.mo
407
408 clean: mostlyclean
409         rm -f $(DOCFILES) $(PACKAGE).ps $(PACKAGE).pdf
410         rm -f man/man1/*.1
411         rm -f man/*/man1/*.1
412
413 distclean: clean
414
415 maintainer-clean: distclean
416
417 realclean: maintainer-clean
418
419
420 ZIPOBJ  = bin/$(BIN) \
421           bin/$(MAC2UNIX_BIN) \
422           bin/$(UNIX2DOS_BIN) \
423           bin/$(UNIX2MAC_BIN) \
424           share/man/man1/$(PACKAGE).1 \
425           share/man/man1/$(MAC2UNIX).1 \
426           share/man/man1/$(UNIX2DOS).1 \
427           share/man/man1/$(UNIX2MAC).1 \
428           share/man/*/man1/$(PACKAGE).1 \
429           share/man/*/man1/$(MAC2UNIX).1 \
430           share/man/*/man1/$(UNIX2DOS).1 \
431           share/man/*/man1/$(UNIX2MAC).1 \
432           share/doc/$(docsubdir) \
433           $(ZIPOBJ_EXTRA)
434
435 ifdef ENABLE_NLS
436 ZIPOBJ += share/locale/*/LC_MESSAGES/$(PACKAGE).mo
437 endif
438
439 ZIPFILE = $(PACKAGE)-$(DOS2UNIX_VERSION)$(VERSIONSUFFIX)$(NLSSUFFIX).zip
440 TGZFILE = $(PACKAGE)-$(DOS2UNIX_VERSION)$(VERSIONSUFFIX)$(NLSSUFFIX).tar.gz
441 TBZFILE = $(PACKAGE)-$(DOS2UNIX_VERSION)$(VERSIONSUFFIX)$(NLSSUFFIX).tar.bz2
442
443 dist-zip:
444         rm -f $(prefix)/$(ZIPFILE)
445         cd $(prefix) ; unix2dos share/doc/$(docsubdir)/*.txt share/man/man1/$(PACKAGE).1 share/man/man1/$(MAC2UNIX).1 share/man/man1/$(UNIX2DOS).1 share/man/man1/$(UNIX2MAC).1
446         cd $(prefix) ; unix2dos share/doc/$(docsubdir)/*.$(HTMLEXT)
447         cd $(prefix) ; unix2dos share/man/*/man1/$(PACKAGE).1 share/man/*/man1/$(MAC2UNIX).1 share/man/*/man1/$(UNIX2DOS).1 share/man/*/man1/$(UNIX2MAC).1
448         cd $(prefix) ; zip -r $(ZIPFILE) $(ZIPOBJ)
449         mv -f $(prefix)/$(ZIPFILE) ..
450
451 dist-tgz:
452         cd $(prefix) ; dos2unix share/doc/$(docsubdir)/*.txt share/man/man1/$(PACKAGE).1 share/man/man1/$(MAC2UNIX).1 share/man/man1/$(UNIX2DOS).1 share/man/man1/$(UNIX2MAC).1
453         cd $(prefix) ; dos2unix share/man/*/man1/$(PACKAGE).1 share/man/*/man1/$(MAC2UNIX).1 share/man/*/man1/$(UNIX2DOS).1 share/man/*/man1/$(UNIX2MAC).1
454         cd $(prefix) ; tar cvzf $(TGZFILE) $(ZIPOBJ)
455         mv $(prefix)/$(TGZFILE) ..
456
457 dist-tbz:
458         cd $(prefix) ; dos2unix share/doc/$(docsubdir)/*.txt share/man/man1/$(PACKAGE).1 share/man/man1/$(MAC2UNIX).1 share/man/man1/$(UNIX2DOS).1 share/man/man1/$(UNIX2MAC).1
459         cd $(prefix) ; dos2unix share/man/*/man1/$(PACKAGE).1 share/man/*/man1/$(MAC2UNIX).1 share/man/*/man1/$(UNIX2DOS).1 share/man/*/man1/$(UNIX2MAC).1
460         cd $(prefix) ; tar cvjf $(TBZFILE) $(ZIPOBJ)
461         mv $(prefix)/$(TBZFILE) ..
462
463 dist: dist-tgz
464
465 strip:
466         $(STRIP) $(BIN)
467         $(STRIP) $(UNIX2DOS_BIN)
468 ifeq ($(LINK),cp -f)
469         $(STRIP) $(MAC2UNIX_BIN)
470         $(STRIP) $(UNIX2MAC_BIN)
471 endif
472
473 # End of file