Various changes to preferences object, file loading, and error logging.
[jben.git] / Makefile
blob8ec0de9e17903e7a18a022fc4a24fcdfdaec70b6
1 # J-Ben Makefile for Linux and Windows
2 # Note: Windows builds expect MinGW, GNUWin32 CoreUtils, and NSIS
3 # binaries in your path!
5 ### User-editable options ###
6 # PLATFORM: either windows or gtk20
7 PLATFORM = gtk20
8 # BUILD: either release, debug, or profile
9 BUILD = release
10 # JBEN_VERSION: Used for labeling release packages
11 JBEN_VERSION = 1.1.3
13 # WINDOWS-SPECIFIC
14 ifeq ($(PLATFORM),windows)
15 # CHANGE THESE 4 VARIABLES
16 MAKE = mingw32-make
17 mingwbase = C:/MinGW
18 boostbase = C:/dev/boost_1_34_1
19 wxbase = C:/dev/wxMSW-2.8.7
20 wxbuildflags = -DWXUSINGDLL -DwxUSE_UNICODE
21 stlportbase = C:/dev/STLport-5.1.5
22 iconvbase = C:/dev/libiconv
23 mkdircmd = C:/progra~1/gnuwin32/bin/mkdir -p
24 # NOTE: wxWidgets is assumed to be built with wxUSINGDLL and wxUSE_UNICODE.
25 # Also, I'm currently using a release build of wxWidgets regardless of
26 # whether a debug or release build is chosen. I may change this later.
28 # The following variables probably should NOT be changed.
29 wxplatformflags = -D__GNUWIN32__ -D__WXMSW__
30 # STLPort specifies -pthreads - does -mthreads work fine for this???
31 wincxxflags = -pipe -mthreads
32 winlinkflags = -mwindows
34 wxinclude = $(wxbase)/include
35 wxcontribinc = $(wxbase)/contrib/include
36 wxlibinc = $(wxbase)/lib/gcc_dll/mswu
38 wxliblink = $(wxbase)/lib/gcc_dll
39 SharedCXXFLAGS = $(wincxxflags)
41 ifeq ($(BUILD),release)
42 winextraflags = -s
43 else
44 winextraflags =
45 endif
47 SharedCPPFLAGS = $(winextraflags) -I$(stlportbase)/stlport $(wxbuildflags) \
48 $(wxplatformflags) -I$(wxinclude) -I$(wxcontribinc) -I$(wxlibinc) \
49 -I$(boostbase) -I$(mingwbase)/include -I$(iconvbase)/include
50 libs = -L$(stlportbase)/lib -L$(wxliblink) -L$(mingwbase)/lib \
51 -L$(iconvbase)/lib -lwxmsw28u_html -lwxmsw28u_core -lwxbase28u \
52 $(winlinkflags) -liconv -lstlport.5.1.dll
53 endif
55 ##################################
56 # DO NOT EDIT BEYOND THIS POINT! #
57 ##################################
59 # make options
60 SHELL = /bin/sh
61 INSTALL = install
62 INSTALL_PROGRAM = $(INSTALL)
63 INSTALL_DATA = $(INSTALL) -m 644
64 # From GNU Make manual, section 14.4: Variables for Installation Directories
65 prefix = /usr/local
66 exec_prefix = $(prefix)
67 bindir = $(exec_prefix)/bin
68 datarootdir = $(prefix)/share
69 datadir = $(datarootdir)
70 docdir = $(datarootdir)/doc/jben
71 # I don't have a man page written yet, but I'll define the vars anyway.
72 mandir = $(datarootdir)/man
73 man1dir = $(mandir)/man1
75 # build dirs
76 build_depdir = dep/$(PLATFORM)/$(BUILD)
77 build_objdir = obj/$(PLATFORM)/$(BUILD)
78 build_bindir = bin/$(PLATFORM)/$(BUILD)
81 # Get flags/libs for GTK builds
82 ifeq ($(PLATFORM),gtk20)
83 MAKE = make
84 SharedCXXFLAGS = `wx-config --cxxflags` `pkg-config --cflags gtk+-2.0 libxml-2.0`
85 SharedCPPFLAGS = `wx-config --cppflags` -DJB_DATADIR=\"$(datadir)/jben\" \
86 -DDOCDIR=\"$(docdir)/doc\" -DLICENSEDIR=\"$(docdir)/license\"
87 libs = `wx-config --libs` `pkg-config --libs gtk+-2.0 libxml-2.0`
88 mkdircmd = mkdir -p
89 endif
91 # C++ options
92 CXX = g++
93 ifeq ($(BUILD),release)
94 CXXFLAGS = -Wall -O2 $(SharedCXXFLAGS)
95 CPPFLAGS = $(SharedCPPFLAGS)
96 endif
97 ifeq ($(BUILD),debug)
98 CXXFLAGS = -Wall -g $(SharedCXXFLAGS)
99 CPPFLAGS = -DDEBUG $(SharedCPPFLAGS)
100 endif
101 ifeq ($(BUILD),profile)
102 # Profiling mode: DEBUG flags, plus -pg, but without -DDEBUG
103 CXXFLAGS = -Wall -g $(SharedCXXFLAGS) -pg
104 CPPFLAGS = $(SharedCPPFLAGS)
105 endif
107 sources = $(shell ls -t *.cpp) # Compile most recently edited files first.
109 # Build object configuration
110 ifeq ($(PLATFORM),windows)
111 objects = $(sources:%.cpp=$(build_objdir)/%.o) $(build_objdir)/jben.res
112 target = jben.exe
113 else
114 objects = $(sources:%.cpp=$(build_objdir)/%.o)
115 target = jben
116 endif
118 # Select build environment type
119 ifeq ($(CANUCK),1)
120 buildenv = posix
121 else
123 ifeq ($(PLATFORM),windows)
124 buildenv = windows
125 else
126 buildenv = posix
127 endif
129 endif
131 ### Targets ###
133 all: $(build_bindir)/$(target) kpengine
134 ifeq ($(PLATFORM),windows)
135 @echo J-Ben was built successfully.
136 else
137 @echo
138 @echo "J-Ben was built successfully."
139 @echo "To install, use \"make install\" with the same options used to compile the"
140 @echo "program."
141 endif
143 .PHONY : kpengine clean cleandep cleanall install uninstall
145 $(build_bindir)/$(target) : $(objects)
146 $(mkdircmd) $(build_bindir)
147 $(CXX) -o $(build_bindir)/$(target) $(objects) $(libs) $(CXXFLAGS)
150 $(build_objdir)/jben.res:
151 $(mkdircmd) $(build_objdir)
152 windres.exe -i jben.rc -J rc -o $(build_objdir)/jben.res -O coff -I$(wxinclude) -I$(wxlibinc) -I$(mingwbase)/include
154 kpengine:
155 cd kanjipad && $(MAKE) BUILD=$(BUILD) PLATFORM=$(PLATFORM) && cd ..
157 clean:
158 cd kanjipad && make clean && cd ..
159 rm -rfv bin obj jben.res
161 cleandep:
162 rm -rfv dep
164 cleanall : clean cleandep
166 $(build_objdir)/%.o : %.cpp
167 $(mkdircmd) $(build_objdir)
168 # Working Linux build command
169 # $(CXX) $(CPPFLAGS) -c -o $@ $(@F:%.o=%.cpp) $(CXXFLAGS)
170 # Testing Windows build command
171 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $(@F:%.o=%.cpp)
173 # Object dependency tracking
174 include $(sources:%.cpp=$(build_depdir)/%.d)
175 $(build_depdir)/%.d : %.cpp
176 @echo Recreating $@...
177 @$(mkdircmd) $(build_depdir)
178 @$(CXX) -MM $(CPPFLAGS) $< > $@.mktmp
179 ifeq ($(buildenv),windows)
180 @sed "s,\($*\)\.o[ :]*,$(build_objdir)/\1.o $@ : ,g" < $@.mktmp > $@
181 else
182 @sed 's,\($*\)\.o[ :]*,$(build_objdir)/\1.o $@ : ,g' < $@.mktmp > $@
183 endif
184 @rm $@.mktmp
186 install:
187 ifeq ($(PLATFORM),windows)
188 # On Windows, "make install" makes the J-Ben NSIS installer.
189 # Step 1: Prep the output directory
190 $(mkdircmd) J-Ben
191 cp "$(stlportbase)/bin/libstlport.5.1.dll" J-Ben
192 cp "$(mingwbase)/bin/mingwm10.dll" J-Ben
193 cp "$(wxliblink)/wxbase28u_gcc_vultaire.net.dll" J-Ben
194 cp "$(wxliblink)/wxmsw28u_core_gcc_vultaire.net.dll" J-Ben
195 cp "$(wxliblink)/wxmsw28u_html_gcc_vultaire.net.dll" J-Ben
196 cp "$(iconvbase)/bin/libcharset1.dll" J-Ben
197 cp "$(iconvbase)/bin/libiconv2.dll" J-Ben
198 cp README.txt J-Ben
199 cp CHANGELOG.txt J-Ben
200 cp "$(build_bindir)/$(target)" J-Ben
201 cp "kanjipad/$(build_bindir)/jben_kpengine.exe" J-Ben
202 cp -R license J-Ben
203 $(mkdircmd) J-Ben/kpengine_data J-Ben/dicts J-Ben/sods
204 cp kanjipad/*.unistrok J-Ben/kpengine_data
205 cp dicts/edict2 dicts/kanjidic dicts/radkfile \
206 dicts/kradfile dicts/README.txt J-Ben/dicts
207 cp sods/README.txt J-Ben/sods
208 @echo J-Ben distribution created in .\J-Ben.
209 # Step 2: Run NSIS script
210 makensis /Dversion=$(JBEN_VERSION) installer.nsi
211 # Step 3: Zip the output folder into 7z and zip archives
212 7z a -tzip jben-$(JBEN_VERSION)-win-binary.zip J-Ben
213 7z a -t7z jben-$(JBEN_VERSION)-win-binary.7z J-Ben
214 # Step 4: Remove the output folder
215 rm -rf J-Ben
216 else
217 $(INSTALL) -d $(bindir) $(datadir)/jben/dicts $(datadir)/jben/sods \
218 $(docdir)/license
219 $(INSTALL_PROGRAM) $(build_bindir)/$(target) $(bindir)
220 $(INSTALL_DATA) dicts/* $(datadir)/jben/dicts
221 $(INSTALL_DATA) sods/README.txt $(datadir)/jben/sods
222 $(INSTALL_DATA) license/* $(docdir)/license
223 # Install man page: $(INSTALL_DATA) <manpage> $(man1dir)
224 cd kanjipad \
225 && $(MAKE) BUILD=$(BUILD) PLATFORM=$(PLATFORM) install \
226 && cd ..
227 @echo
228 @echo "J-Ben was installed successfully."
229 endif
231 uninstall:
232 ifeq ($(PLATFORM),windows)
233 @echo "make uninstall" is not supported on Windows.
234 else
235 cd kanjipad \
236 && $(MAKE) BUILD=$(BUILD) PLATFORM=$(PLATFORM) uninstall \
237 && cd ..
238 rm -fv $(bindir)/$(target)
239 rm -fv $(datadir)/jben/dicts/*
240 rm -fv $(datadir)/jben/sods/README.txt
241 rm -fv $(docdir)/license/*
242 # rm -fv $(man1dir)/<manpage>
243 rmdir -p $(datadir)/jben/dicts || true
244 rmdir -p $(datadir)/jben/sods || true
245 rmdir -p $(docdir)/license || true
246 @echo
247 @echo "J-Ben was uninstalled successfully."
248 endif