]> git.tdb.fi Git - ext/subsurface.git/blob - Makefile
Split reading/writing preferences into OS specific files
[ext/subsurface.git] / Makefile
1 VERSION=1.1
2
3 CC=gcc
4 CFLAGS=-Wall -Wno-pointer-sign -g
5 INSTALL=install
6 PKGCONFIG=pkg-config
7 XML2CONFIG=xml2-config
8 XSLCONFIG=xslt-config
9
10 # these locations seem to work for SuSE and Fedora
11 # prefix = $(HOME)
12 prefix = $(DESTDIR)/usr
13 BINDIR = $(prefix)/bin
14 DATADIR = $(prefix)/share
15 DESKTOPDIR = $(DATADIR)/applications
16 ICONPATH = $(DATADIR)/icons/hicolor
17 ICONDIR = $(ICONPATH)/scalable/apps
18 MANDIR = $(DATADIR)/man/man1
19 XSLTDIR = $(DATADIR)/subsurface/xslt
20 gtk_update_icon_cache = gtk-update-icon-cache -f -t $(ICONPATH)
21
22 NAME = subsurface
23 ICONFILE = $(NAME).svg
24 DESKTOPFILE = $(NAME).desktop
25 MANFILES = $(NAME).1
26 XSLTFILES = xslt/*.xslt
27
28 MACOSXINSTALL = /Applications/Subsurface.app
29 MACOSXFILES = packaging/macosx
30
31 # find libdivecomputer
32 # First deal with the cross compile environment.
33 # For the native case, Linus doesn't want to trust pkg-config given
34 # how young libdivecomputer still is - so we check the typical
35 # subdirectories of /usr/local and /usr and then we give up. You can
36 # override by simply setting it here
37 #
38 ifeq ($(CC), i686-w64-mingw32-gcc)
39 # ok, we are cross building for Windows
40         LIBDIVECOMPUTERDIR = /usr/i686-w64-mingw32/sys-root/mingw/include/libdivecomputer
41         LIBDIVECOMPUTERINCLUDES = `$(PKGCONFIG) --cflags libdivecomputer`
42         LIBDIVECOMPUTERARCHIVE = `$(PKGCONFIG) --libs libdivecomputer`
43         RESFILE = packaging/windows/subsurface.res
44         LDFLAGS += -Wl,-subsystem,windows
45 else
46
47 libdc-local := $(wildcard /usr/local/lib/libdivecomputer.a)
48 libdc-local64 := $(wildcard /usr/local/lib64/libdivecomputer.a)
49 libdc-usr := $(wildcard /usr/lib/libdivecomputer.a)
50 libdc-usr64 := $(wildcard /usr/lib64/libdivecomputer.a)
51
52 ifneq ($(strip $(libdc-local)),)
53         LIBDIVECOMPUTERDIR = /usr/local
54         LIBDIVECOMPUTERINCLUDES = -I$(LIBDIVECOMPUTERDIR)/include/libdivecomputer
55         LIBDIVECOMPUTERARCHIVE = $(LIBDIVECOMPUTERDIR)/lib/libdivecomputer.a
56 else ifneq ($(strip $(libdc-local64)),)
57         LIBDIVECOMPUTERDIR = /usr/local
58         LIBDIVECOMPUTERINCLUDES = -I$(LIBDIVECOMPUTERDIR)/include/libdivecomputer
59         LIBDIVECOMPUTERARCHIVE = $(LIBDIVECOMPUTERDIR)/lib64/libdivecomputer.a
60 else ifneq ($(strip $(libdc-usr)),)
61         LIBDIVECOMPUTERDIR = /usr
62         LIBDIVECOMPUTERINCLUDES = -I$(LIBDIVECOMPUTERDIR)/include/libdivecomputer
63         LIBDIVECOMPUTERARCHIVE = $(LIBDIVECOMPUTERDIR)/lib/libdivecomputer.a
64 else ifneq ($(strip $(libdc-usr64)),)
65         LIBDIVECOMPUTERDIR = /usr
66         LIBDIVECOMPUTERINCLUDES = -I$(LIBDIVECOMPUTERDIR)/include/libdivecomputer
67         LIBDIVECOMPUTERARCHIVE = $(LIBDIVECOMPUTERDIR)/lib64/libdivecomputer.a
68 else
69 $(error Cannot find libdivecomputer - please edit Makefile)
70 endif
71 endif
72
73 # Libusb-1.0 is only required if libdivecomputer was built with it.
74 # And libdivecomputer is only built with it if libusb-1.0 is
75 # installed. So get libusb if it exists, but don't complain
76 # about it if it doesn't.
77 LIBUSB = $(shell $(PKGCONFIG) --libs libusb-1.0 2> /dev/null)
78
79 LIBGTK = $(shell $(PKGCONFIG) --libs gtk+-2.0 glib-2.0 gconf-2.0)
80 LIBDIVECOMPUTERCFLAGS = $(LIBDIVECOMPUTERINCLUDES)
81 LIBDIVECOMPUTER = $(LIBDIVECOMPUTERARCHIVE) $(LIBUSB)
82
83 LIBXML2 = $(shell $(XML2CONFIG) --libs)
84 LIBXSLT = $(shell $(XSLCONFIG) --libs)
85 XML2CFLAGS = $(shell $(XML2CONFIG) --cflags)
86 GLIB2CFLAGS = $(shell $(PKGCONFIG) --cflags glib-2.0)
87 GCONF2CFLAGS =  $(shell $(PKGCONFIG) --cflags gconf-2.0)
88 GTK2CFLAGS = $(shell $(PKGCONFIG) --cflags gtk+-2.0)
89 CFLAGS += $(shell $(XSLCONFIG) --cflags)
90
91 UNAME := $(shell uname)
92
93 ifeq ($(UNAME), Linux)
94         OSSUPPORT = linux
95         OSSUPPORT_CFLAGS = $(GTK2CFLAGS) $(GCONF2CFLAGS)
96 else ifeq ($(UNAME), Darwin)
97         OSSUPPORT = macos
98         OSSUPPORT_CFLAGS = $(GTK2CFLAGS)
99 else
100         OSSUPPORT = windows
101         OSSUPPORT_CFLAGS = $(GTK2CFLAGS)
102 endif
103
104 ifneq ($(strip $(LIBXSLT)),)
105         # We still need proper paths and install options for OSX and Windows
106         ifeq ($(shell sh -c 'uname -s 2>/dev/null || echo not'),Linux)
107                 XSLT=-DXSLT='"$(XSLTDIR)"'
108         endif
109 endif
110
111 LIBS = $(LIBXML2) $(LIBXSLT) $(LIBGTK) $(LIBDIVECOMPUTER) -lpthread
112
113 OBJS =  main.o dive.o profile.o info.o equipment.o divelist.o \
114         parse-xml.o save-xml.o libdivecomputer.o print.o uemis.o \
115         gtk-gui.o statistics.o $(OSSUPPORT).o $(RESFILE)
116
117 $(NAME): $(OBJS)
118         $(CC) $(LDFLAGS) -o $(NAME) $(OBJS) $(LIBS)
119
120 install: $(NAME)
121         $(INSTALL) -d -m 755 $(BINDIR)
122         $(INSTALL) $(NAME) $(BINDIR)
123         $(INSTALL) -d -m 755 $(DESKTOPDIR)
124         $(INSTALL) $(DESKTOPFILE) $(DESKTOPDIR)
125         $(INSTALL) -d -m 755 $(ICONDIR)
126         $(INSTALL) $(ICONFILE) $(ICONDIR)
127         @-if test -z "$(DESTDIR)"; then \
128                 $(gtk_update_icon_cache); \
129         fi
130         $(INSTALL) -d -m 755 $(MANDIR)
131         $(INSTALL) -m 644 $(MANFILES) $(MANDIR)
132         @-if test ! -z "$(XSLT)"; then \
133                 $(INSTALL) -d -m 755 $(DATADIR)/subsurface; \
134                 $(INSTALL) -d -m 755 $(XSLTDIR); \
135                 $(INSTALL) -m 644 $(XSLTFILES) $(XSLTDIR); \
136         fi
137
138 install-macosx: $(NAME)
139         $(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/Resources
140         $(INSTALL) -d -m 755 $(MACOSXINSTALL)/Contents/MacOS
141         $(INSTALL) $(NAME) $(MACOSXINSTALL)/Contents/MacOS/
142         $(INSTALL) $(MACOSXFILES)/subsurface.sh $(MACOSXINSTALL)/Contents/MacOS/
143         $(INSTALL) $(MACOSXFILES)/PkgInfo $(MACOSXINSTALL)/Contents/
144         $(INSTALL) $(MACOSXFILES)/Info.plist $(MACOSXINSTALL)/Contents/
145         $(INSTALL) $(ICONFILE) $(MACOSXINSTALL)/Contents/Resources/
146         $(INSTALL) $(MACOSXFILES)/Subsurface.icns $(MACOSXINSTALL)/Contents/Resources/
147
148 parse-xml.o: parse-xml.c dive.h
149         $(CC) $(CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) $(XSLT) -c parse-xml.c
150
151 save-xml.o: save-xml.c dive.h
152         $(CC) $(CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c save-xml.c
153
154 dive.o: dive.c dive.h
155         $(CC) $(CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c dive.c
156
157 main.o: main.c dive.h display.h divelist.h
158         $(CC) $(CFLAGS) $(GLIB2CFLAGS) $(GCONF2CFLAGS) $(XML2CFLAGS) -c main.c
159
160 profile.o: profile.c dive.h display.h divelist.h
161         $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c profile.c
162
163 info.o: info.c dive.h display.h display-gtk.h divelist.h
164         $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c info.c
165
166 equipment.o: equipment.c dive.h display.h divelist.h
167         $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c equipment.c
168
169 statistics.o: statistics.c dive.h display.h divelist.h
170         $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c statistics.c
171
172 divelist.o: divelist.c dive.h display.h divelist.h
173         $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c divelist.c
174
175 print.o: print.c dive.h display.h display-gtk.h
176         $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c print.c
177
178 libdivecomputer.o: libdivecomputer.c dive.h display.h display-gtk.h libdivecomputer.h
179         $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) \
180                         $(LIBDIVECOMPUTERCFLAGS) \
181                         -c libdivecomputer.c
182
183 gtk-gui.o: gtk-gui.c dive.h display.h divelist.h display-gtk.h libdivecomputer.h Makefile
184         $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(GCONF2CFLAGS) $(XML2CFLAGS) \
185                         $(LIBDIVECOMPUTERCFLAGS) \
186                         -DVERSION_STRING='"v$(VERSION)"' \
187                         -c gtk-gui.c
188
189 uemis.o: uemis.c dive.h uemis.h
190         $(CC) $(CFLAGS) $(GTK2CFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) -c uemis.c
191
192 $(OSSUPPORT).o: $(OSSUPPORT).c display-gtk.h
193         $(CC) $(CFLAGS) $(OSSUPPORT_CFLAGS) -c $(OSSUPPORT).c
194
195 clean:
196         rm -f $(OBJS) *~ $(NAME)