summaryrefslogtreecommitdiff
path: root/config.mk
blob: d269b15325d9817885a1c7cc1a7c3df3381b444c (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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# LeoCAD configuration file
#
include version.mk

ERROR_SETTING=2> /dev/null

default: all

CC	:= gcc
CXX	:= g++

# (Add a -g for debugging)
CPPFLAGS += -O2 -Wall

# Add compile options, such as -I option to include jpeglib's headers
# CPPFLAGS += -I/home/fred/jpeglib

# Add linker options, such as -L option to include jpeglib's libraries
# LDFLAGS += -L/home/fred/jpeglib

### Linux configuration

ifeq ($(shell uname), Linux)

OS 	   := -DLC_LINUX
OSDIR 	   := linux
TEST_GTK   := 1

endif

### FreeBSD configuration

ifeq ($(shell uname), FreeBSD)

OS 	   := -DLC_LINUX
OSDIR 	   := linux
TEST_GTK   := 1
CPPFLAGS   += -L/usr/local/lib

endif

### Macintosh configuration

ifeq ($(shell uname), Darwin)

OS         := -DLC_MACOSX
OSDIR      := macosx
TEST_GTK   := 0
CPPFLAGS   += -funsigned-char -I/Developer/Headers/FlatCarbon/
LDFLAGS    += -framework AGL -framework Carbon

# The directory tree for the generated bundle
BUNDLEDIR  = bin/LeoCAD.app
CONTDIR    = $(BUNDLEDIR)/Contents
BINDIR     = $(CONTDIR)/MacOS
RSRCDIR    = $(CONTDIR)/Resources
EN_RSRCDIR = $(RSRCDIR)/English.lproj

NIBS = main.nib

all: bundletree exec bnibs pkginfo infoplist infopliststr

bundletree: $(BINDIR) $(BUNDLEDIR) $(CONTDIR) $(RSRCDIR) $(EN_RSRCDIR)

$(BUNDLEDIR):
	mkdir bin
	mkdir $(BUNDLEDIR)

$(CONTDIR): $(BUNDLEDIR)
	mkdir $(CONTDIR)

$(BINDIR): $(CONTDIR)
	mkdir $(BINDIR)

$(RSRCDIR): $(CONTDIR)
	mkdir $(RSRCDIR)

$(EN_RSRCDIR): $(RSRCDIR)
	mkdir $(EN_RSRCDIR)

# The binary executable
exec: $(BINDIR)/leocad

$(BINDIR)/leocad: bin/leocad
	cp bin/leocad $(BINDIR)

# The nib's
BNIBS = $(NIBS:%=$(EN_RSRCDIR)/%)

bnibs: $(BNIBS)

$(BNIBS) : $(EN_RSRCDIR)/%: macosx/English.lproj/%
	rm -rf $@
	cp -R $< $@
	touch $@

# Info.plist
infoplist : $(CONTDIR)/Info.plist

$(CONTDIR)/Info.plist : macosx/Info.plist
	cp macosx/Info.plist $@

# PkgInfo
pkginfo : $(CONTDIR)/PkgInfo

$(CONTDIR)/PkgInfo : macosx/PkgInfo
	cp macosx/PkgInfo $@

# InfoPlist.strings - this goes inside English.lproj
infopliststr : $(EN_RSRCDIR)/InfoPlist.strings

$(EN_RSRCDIR)/InfoPlist.strings: macosx/English.lproj/InfoPlist.strings
	cp $< $@

endif

### Default directory

ifeq ($(PREFIX), )
PREFIX := /usr/local
endif

.PHONY: config config-help

config-help:
	@echo "This target attempts to detect your system settings,"
	@echo "it will create $(OSDIR)/config.mk and $(OSDIR)/config.h"
	@echo "Valid parameters and their default values are:"
	@echo "  PREFIX=/usr/local"
	@echo "  DESTDIR="

### Automatic configuration

#USE this with printf and a primitive type - printf "WIDTHTEST" "char" >conftest.c
CONFTEST="\#include <stdio.h>\nint main() { FILE *f=fopen(\"conftestval\", \"w\");\n\
	if (!f) return 1; fprintf(f, \"%%d\\\n\", (int)sizeof(%s)); return 0; }\n"

config:
	@echo "Automatic configuration"

	@echo "### LeoCAD configuration" > $(OSDIR)/config.mk
	@echo "### Auto-generated file, DO NOT EDIT" >> $(OSDIR)/config.mk
	@echo "" >> $(OSDIR)/config.mk
	@echo "PREFIX := $(PREFIX)" >> $(OSDIR)/config.mk;
	@echo "DESTDIR := $(DESTDIR)" >> $(OSDIR)/config.mk;
	@echo "" >> $(OSDIR)/config.mk

	@echo "//" > $(OSDIR)/config.h
	@echo "// LeoCAD configuration" >> $(OSDIR)/config.h
	@echo "//" >> $(OSDIR)/config.h
	@echo "// Auto-generated file, DO NOT EDIT" >> $(OSDIR)/config.h
	@echo "//" >> $(OSDIR)/config.h
	@echo "" >> $(OSDIR)/config.h
	@echo "#ifndef _CONFIG_H_" >> $(OSDIR)/config.h
	@echo "#define _CONFIG_H_" >> $(OSDIR)/config.h
	@echo "" >> $(OSDIR)/config.h

### Version information
	@echo "#define LC_VERSION_MAJOR $(MAJOR)" >> $(OSDIR)/config.h
	@echo "#define LC_VERSION_MINOR $(MINOR)" >> $(OSDIR)/config.h
	@echo "#define LC_VERSION_PATCH $(PATCHLVL)" >> $(OSDIR)/config.h
	@echo "#define LC_VERSION_OSNAME \"$(shell uname)\"" >> $(OSDIR)/config.h
	@echo "#define LC_VERSION_TEXT \"$(MAJOR).$(MINOR).$(PATCHLVL)\"" >> $(OSDIR)/config.h
	@echo "#define LC_VERSION_TAG \"$(VERSIONTAG)\"" >> $(OSDIR)/config.h
	@echo "#define LC_INSTALL_PREFIX \"$(PREFIX)\"" >> $(OSDIR)/config.h
	@echo "" >> $(OSDIR)/config.h

### Determine variable sizes
	@echo -n "checking size of char... "; \
	printf ${CONFTEST} "char" > conftest.c; \
	if { (eval $(CC) conftest.c -o conftest); } && \
	  (test -s conftest && (./conftest; exit)); then \
	  ac_cv_sizeof_char=`cat conftestval`; \
	  echo "$$ac_cv_sizeof_char"; \
	else \
	  echo "failed to get size of char"; \
	  ac_cv_sizeof_char=0; \
	fi; \
	echo "#define LC_SIZEOF_CHAR $$ac_cv_sizeof_char" >> $(OSDIR)/config.h; \
	rm -f conftest.c conftest conftestval; \
	\
	echo -n "checking size of short... "; \
	printf ${CONFTEST} "short" > conftest.c; \
	if { (eval $(CC) conftest.c -o conftest); } && \
	  (test -s conftest && (./conftest; exit)); then \
	  ac_cv_sizeof_short=`cat conftestval`; \
	  echo "$$ac_cv_sizeof_short"; \
	else \
	  echo "failed to get size of short"; \
	  ac_cv_sizeof_short=0; \
	fi; \
	echo "#define LC_SIZEOF_SHORT $$ac_cv_sizeof_short" >> $(OSDIR)/config.h; \
	rm -f conftest.c conftest conftestval; \
	\
	echo -n "checking size of long... "; \
	printf ${CONFTEST} "long" > conftest.c; \
	if { (eval $(CC) conftest.c -o conftest); } && \
	  (test -s conftest && (./conftest; exit)); then \
	  ac_cv_sizeof_long=`cat conftestval`; \
	  echo "$$ac_cv_sizeof_long"; \
	else \
	  echo "failed to get size of long"; \
	  ac_cv_sizeof_long=0; \
	fi; \
	echo "#define LC_SIZEOF_LONG $$ac_cv_sizeof_long" >> $(OSDIR)/config.h; \
	rm -f conftest.c conftest conftestval; \
	\
	echo -n "checking size of int... "; \
	printf ${CONFTEST} "int" > conftest.c; \
	if { (eval $(CC) conftest.c -o conftest); } && \
	  (test -s conftest && (./conftest; exit)); then \
	  ac_cv_sizeof_int=`cat conftestval`; \
	  echo "$$ac_cv_sizeof_int"; \
	else \
	  echo "failed to get size of int"; \
	  ac_cv_sizeof_int=0; \
	fi; \
	echo "#define LC_SIZEOF_INT $$ac_cv_sizeof_int" >> $(OSDIR)/config.h; \
	rm -f conftest.c conftest conftestval; \
	\
	echo -n "checking size of void *... "; \
	printf ${CONFTEST} "void *" > conftest.c; \
	if { (eval $(CC) conftest.c -o conftest); } && \
	  (test -s conftest && (./conftest; exit)); then \
	  ac_cv_sizeof_void_p=`cat conftestval`; \
	  echo "$$ac_cv_sizeof_void_p"; \
	else \
	  echo "failed to get size of void *"; \
	  ac_cv_sizeof_void_p=0; \
	fi; \
	echo "#define LC_SIZEOF_VOID_P $$ac_cv_sizeof_void_p" >> $(OSDIR)/config.h; \
	if test "$$ac_cv_sizeof_void_p" -eq "8"; then \
	  echo "#define LC_POINTER_TO_INT(p) ((lcint32)(lcint64)(p))" >> $(OSDIR)/config.h; \
	else \
	  echo "#define LC_POINTER_TO_INT(p) ((lcint32)(p))" >> $(OSDIR)/config.h; \
	fi; \
	rm -f conftest.c conftest conftestval; \
	\
	echo -n "checking size of long long... "; \
	printf ${CONFTEST} "long long" > conftest.c; \
	if { (eval $(CC) conftest.c -o conftest); } && \
	  (test -s conftest && (./conftest; exit)); then \
	  ac_cv_sizeof_long_long=`cat conftestval`; \
	  echo "$$ac_cv_sizeof_long_long"; \
	else \
	  echo "failed to get size of long long"; \
	  ac_cv_sizeof_long_long=0; \
	fi; \
	echo "#define LC_SIZEOF_LONG_LONG $$ac_cv_sizeof_long_long" >> $(OSDIR)/config.h; \
	rm -f conftest.c conftest conftestval; \
	case 2 in \
	  $$ac_cv_sizeof_short)		lcint16=short;; \
	  $$ac_cv_sizeof_int)		lcint16=int;; \
	esac; \
	case 4 in \
	  $$ac_cv_sizeof_short)		lcint32=short;; \
	  $$ac_cv_sizeof_int)		lcint32=int;; \
	  $$ac_cv_sizeof_long)		lcint32=long;; \
	esac; \
	case 8 in \
	  $$ac_cv_sizeof_long_long)	lcint64="long long";; \
	esac; \
	echo "" >> $(OSDIR)/config.h; \
	echo "typedef signed char lcint8;" >> $(OSDIR)/config.h; \
	echo "typedef unsigned char lcuint8;" >> $(OSDIR)/config.h; \
	if test -n "$$lcint16"; then \
	  echo "typedef signed $$lcint16 lcint16;" >> $(OSDIR)/config.h; \
	  echo "typedef unsigned $$lcint16 lcuint16;" >> $(OSDIR)/config.h; \
	else \
	  echo "#error need to define lcint16 and lcuint16" >> $(OSDIR)/config.h; \
	fi; \
	if test -n "$$lcint32"; then \
	echo "typedef signed $$lcint32 lcint32;" >> $(OSDIR)/config.h; \
	echo "typedef unsigned $$lcint32 lcuint32;" >> $(OSDIR)/config.h; \
	else \
	  echo "#error need to define lcint32 and lcuint32" >> $(OSDIR)/config.h; \
	fi; \
	if test -n "$$lcint64"; then \
	echo "typedef signed $$lcint64 lcint64;" >> $(OSDIR)/config.h; \
	echo "typedef unsigned $$lcint64 lcuint64;" >> $(OSDIR)/config.h; \
	else \
	  echo "#error need to define lcint64 and lcuint64" >> $(OSDIR)/config.h; \
	fi; \
	echo "" >> $(OSDIR)/config.h

### Check if machine is little or big endian
	@echo -n "Determining endianess... "
	@echo "int main () { union { long l; char c[sizeof (long)]; } u;" > endiantest.c
	@echo "u.l = 1; return (u.c[sizeof (long) - 1] == 1); }" >> endiantest.c
	@if { (eval $(CC) endiantest.c -o endiantest); } && \
	  (test -s endiantest && (./endiantest; exit)); then \
	  echo "little endian"; \
	  echo "#define LC_LITTLE_ENDIAN" >> $(OSDIR)/config.h; \
	  echo "#define LCUINT16(val) val" >> $(OSDIR)/config.h; \
	  echo "#define LCUINT32(val) val" >> $(OSDIR)/config.h; \
	  echo "#define LCINT16(val) val" >> $(OSDIR)/config.h; \
	  echo "#define LCINT32(val) val" >> $(OSDIR)/config.h; \
	  echo "#define LCFLOAT(val) val" >> $(OSDIR)/config.h; \
	else \
	  echo "big endian"; \
	  echo "#define LC_BIG_ENDIAN" >> $(OSDIR)/config.h; \
	  echo "#define LCUINT16(val) ((lcuint16) ( \\" >> $(OSDIR)/config.h; \
	  echo "    (((lcuint16) (val) & (lcuint16) 0x00ffU) << 8) | \\" >> $(OSDIR)/config.h; \
	  echo "    (((lcuint16) (val) & (lcuint16) 0xff00U) >> 8)))" >> $(OSDIR)/config.h; \
	  echo "#define LCUINT32(val) ((lcuint32) ( \\" >> $(OSDIR)/config.h; \
	  echo "    (((lcuint32) (val) & (lcuint32) 0x000000ffU) << 24) | \\" >> $(OSDIR)/config.h; \
	  echo "    (((lcuint32) (val) & (lcuint32) 0x0000ff00U) <<  8) | \\" >> $(OSDIR)/config.h; \
	  echo "    (((lcuint32) (val) & (lcuint32) 0x00ff0000U) >>  8) | \\" >> $(OSDIR)/config.h; \
	  echo "    (((lcuint32) (val) & (lcuint32) 0xff000000U) >> 24)))" >> $(OSDIR)/config.h; \
	  echo "#define LCINT16(val) ((lcint16)LCUINT16(val))" >> $(OSDIR)/config.h; \
	  echo "#define LCINT32(val) ((lcint32)LCUINT32(val))" >> $(OSDIR)/config.h; \
	  echo -e "inline float LCFLOAT (float l)\n{" >> $(OSDIR)/config.h; \
	  echo -e "  union { unsigned char b[4]; float f; } in, out;\n" >> $(OSDIR)/config.h; \
	  echo -e "  in.f = l;\n  out.b[0] = in.b[3];\n  out.b[1] = in.b[2];" >> $(OSDIR)/config.h; \
	  echo -e "  out.b[2] = in.b[1];\n  out.b[3] = in.b[0];\n" >> $(OSDIR)/config.h; \
	  echo -e "  return out.f;\n}" >> $(OSDIR)/config.h; \
	fi; \
	echo "" >> $(OSDIR)/config.h
	@rm -f endiantest.c endiantest

#### Check if the user has GTK+ and GLIB installed.
ifeq ($(TEST_GTK), 1)
	@echo -n "Checking if GLIB and GTK+ are installed... "
	@if (pkg-config --atleast-version=2.0.0 glib-2.0) && (pkg-config --atleast-version=2.0.0 gtk+-2.0); then \
	  echo "ok"; \
	  echo "CFLAGS += \$$(shell pkg-config gtk+-2.0 --cflags)" >> $(OSDIR)/config.mk; \
	  echo "CXXFLAGS += \$$(shell pkg-config gtk+-2.0 --cflags)" >> $(OSDIR)/config.mk; \
	  echo "LIBS += \$$(shell pkg-config gtk+-2.0 --libs)" >> $(OSDIR)/config.mk; \
	else \
	  echo "failed"; \
	  rm -rf $(OSDIR)/config.mk $(OSDIR)/config.h; \
	  exit 1; \
	fi
endif

## Check if the user has libjpeg installed
	@echo -n "Checking for jpeg support... "
	@echo "char jpeg_read_header();" > jpegtest.c
	@echo "int main() { jpeg_read_header(); return 0; }" >> jpegtest.c
	@if { (eval $(CC) jpegtest.c -ljpeg -o jpegtest $(CPPFLAGS) $(LDFLAGS)); } && \
	  (test -s jpegtest); then  \
	  echo "ok"; \
	  echo "HAVE_JPEGLIB = yes" >> $(OSDIR)/config.mk; \
	  echo "#define LC_HAVE_JPEGLIB" >> $(OSDIR)/config.h; \
	else \
	  echo "no (libjpeg optional)"; \
	  echo "HAVE_JPEGLIB = no" >> $(OSDIR)/config.mk; \
	  echo "#undef LC_HAVE_JPEGLIB" >> $(OSDIR)/config.h; \
	fi
	@rm -f jpegtest.c jpegtest

### Check if the user has zlib installed
	@echo -n "Checking for zlib support... "
	@echo "char gzread();" > ztest.c
	@echo "int main() { gzread(); return 0; }" >> ztest.c
	@if { (eval $(CC) ztest.c -lz -o ztest $(CPPFLAGS) $(LDFLAGS)); } && \
	  (test -s ztest); then  \
	  echo "ok"; \
	  echo "HAVE_ZLIB = yes" >> $(OSDIR)/config.mk; \
	  echo "#define LC_HAVE_ZLIB" >> $(OSDIR)/config.h; \
	else \
	  echo "no (zlib optional)"; \
	  echo "HAVE_ZLIB = no" >> $(OSDIR)/config.mk; \
	  echo "#undef LC_HAVE_ZLIB" >> $(OSDIR)/config.h; \
	fi
	@rm -f ztest.c ztest

### Check if the user has libpng installed
	@echo -n "Checking for png support... "
	@echo "char png_read_info();" > pngtest.c
	@echo "int main() { png_read_info(); return 0; }" >> pngtest.c
	@if { (eval $(CC) pngtest.c -lm -lz -lpng -o pngtest $(CPPFLAGS) $(LDFLAGS)); } && \
	  (test -s pngtest); then  \
	  echo "ok"; \
	  echo "HAVE_PNGLIB = yes" >> $(OSDIR)/config.mk; \
	  echo "#define LC_HAVE_PNGLIB" >> $(OSDIR)/config.h; \
	else \
	  echo "no (libpng optional)"; \
	  echo "HAVE_PNGLIB = no" >> $(OSDIR)/config.mk; \
	  echo "#undef LC_HAVE_PNGLIB" >> $(OSDIR)/config.h; \
	fi
	@rm -f pngtest.c pngtest

	@echo "" >> $(OSDIR)/config.h
	@echo "#endif // _CONFIG_H_" >> $(OSDIR)/config.h