root / tags / leocad-0-74 / config.mk

Revision 405, 11.6 kB (checked in by leo, 4 years ago)

Fixed make error when GTK+ isn't found.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# LeoCAD configuration file
2#
3include version.mk
4
5default: all
6
7CC  := gcc
8CXX := g++
9
10# (Add a -g for debugging)
11CPPFLAGS += -O2 -Wall
12
13# Add compile options, such as -I option to include jpeglib's headers
14# CPPFLAGS += -I/home/fred/jpeglib
15
16# Add linker options, such as -L option to include jpeglib's libraries
17# LDFLAGS += -L/home/fred/jpeglib
18
19### Linux configuration
20
21ifeq ($(shell uname), Linux)
22
23OS     := -DLC_LINUX
24OSDIR      := linux
25
26endif
27
28### FreeBSD configuration
29
30ifeq ($(shell uname), FreeBSD)
31
32OS     := -DLC_LINUX
33OSDIR      := linux
34CPPFLAGS   += -L/usr/local/lib
35
36endif
37
38### Default directory
39
40ifeq ($(PREFIX), )
41PREFIX := /usr/local
42endif
43
44.PHONY: config config-help
45
46config-help:
47    @echo "This target attempts to detect your system settings,"
48    @echo "it will create $(OSDIR)/config.mk and $(OSDIR)/config.h"
49    @echo "Valid parameters and their default values are:"
50    @echo "  PREFIX=/usr/local"
51    @echo "  DESTDIR="
52
53### Automatic configuration
54
55config:
56    @echo "Automatic configuration"
57
58    @echo "### LeoCAD configuration" > $(OSDIR)/config.mk
59    @echo "### Auto-generated file, DO NOT EDIT" >> $(OSDIR)/config.mk
60    @echo "" >> $(OSDIR)/config.mk
61    @echo "PREFIX := $(PREFIX)" >> $(OSDIR)/config.mk;
62    @echo "DESTDIR := $(DESTDIR)" >> $(OSDIR)/config.mk;
63    @echo "" >> $(OSDIR)/config.mk
64
65    @echo "//" > $(OSDIR)/config.h
66    @echo "// LeoCAD configuration" >> $(OSDIR)/config.h
67    @echo "//" >> $(OSDIR)/config.h
68    @echo "// Auto-generated file, DO NOT EDIT" >> $(OSDIR)/config.h
69    @echo "//" >> $(OSDIR)/config.h
70    @echo "" >> $(OSDIR)/config.h
71    @echo "#ifndef _CONFIG_H_" >> $(OSDIR)/config.h
72    @echo "#define _CONFIG_H_" >> $(OSDIR)/config.h
73    @echo "" >> $(OSDIR)/config.h
74
75### Version information
76    @echo "#define LC_VERSION_MAJOR $(MAJOR)" >> $(OSDIR)/config.h
77    @echo "#define LC_VERSION_MINOR $(MINOR)" >> $(OSDIR)/config.h
78    @echo "#define LC_VERSION_PATCH $(PATCHLVL)" >> $(OSDIR)/config.h
79    @echo "#define LC_VERSION_OSNAME \"$(shell uname)\"" >> $(OSDIR)/config.h
80    @echo "#define LC_VERSION_TEXT \"$(MAJOR).$(MINOR).$(PATCHLVL)\"" >> $(OSDIR)/config.h
81    @echo "#define LC_VERSION_TAG \"$(VERSIONTAG)\"" >> $(OSDIR)/config.h
82    @echo "#define LC_INSTALL_PREFIX \"$(PREFIX)\"" >> $(OSDIR)/config.h
83    @echo "" >> $(OSDIR)/config.h
84
85### Determine variable sizes
86    @echo -n "checking size of char... "; \
87    echo "#include <stdio.h>" > conftest.c; \
88    echo "main() { FILE *f=fopen(\"conftestval\", \"w\");" >> conftest.c; \
89    echo "if (!f) exit(1); fprintf(f, \"%d\\n\", sizeof(char)); exit(0); }" >> conftest.c; \
90    if { (eval $(CC) conftest.c -o conftest) 2> /dev/null; } && \
91      (test -s conftest && (./conftest; exit) 2> /dev/null); then \
92      ac_cv_sizeof_char=`cat conftestval`; \
93      echo "$$ac_cv_sizeof_char"; \
94    else \
95      echo "failed to get size of char"; \
96      ac_cv_sizeof_char=0; \
97    fi; \
98    echo "#define LC_SIZEOF_CHAR $$ac_cv_sizeof_char" >> $(OSDIR)/config.h; \
99    rm -f conftest.c conftest conftestval; \
100    \
101    echo -n "checking size of short... "; \
102    echo "#include <stdio.h>" > conftest.c; \
103    echo "main() { FILE *f=fopen(\"conftestval\", \"w\");" >> conftest.c; \
104    echo "if (!f) exit(1); fprintf(f, \"%d\\n\", sizeof(short)); exit(0); }" >> conftest.c; \
105    if { (eval $(CC) conftest.c -o conftest) 2> /dev/null; } && \
106      (test -s conftest && (./conftest; exit) 2> /dev/null); then \
107      ac_cv_sizeof_short=`cat conftestval`; \
108      echo "$$ac_cv_sizeof_short"; \
109    else \
110      echo "failed to get size of short"; \
111      ac_cv_sizeof_short=0; \
112    fi; \
113    echo "#define LC_SIZEOF_SHORT $$ac_cv_sizeof_short" >> $(OSDIR)/config.h; \
114    rm -f conftest.c conftest conftestval; \
115    \
116    echo -n "checking size of long... "; \
117    echo "#include <stdio.h>" > conftest.c; \
118    echo "main() { FILE *f=fopen(\"conftestval\", \"w\");" >> conftest.c; \
119    echo "if (!f) exit(1); fprintf(f, \"%d\\n\", sizeof(long)); exit(0); }" >> conftest.c; \
120    if { (eval $(CC) conftest.c -o conftest) 2> /dev/null; } && \
121      (test -s conftest && (./conftest; exit) 2> /dev/null); then \
122      ac_cv_sizeof_long=`cat conftestval`; \
123      echo "$$ac_cv_sizeof_long"; \
124    else \
125      echo "failed to get size of long"; \
126      ac_cv_sizeof_long=0; \
127    fi; \
128    echo "#define LC_SIZEOF_LONG $$ac_cv_sizeof_long" >> $(OSDIR)/config.h; \
129    rm -f conftest.c conftest conftestval; \
130    \
131    echo -n "checking size of int... "; \
132    echo "#include <stdio.h>" > conftest.c; \
133    echo "main() { FILE *f=fopen(\"conftestval\", \"w\");" >> conftest.c; \
134    echo "if (!f) exit(1); fprintf(f, \"%d\\n\", sizeof(int)); exit(0); }" >> conftest.c; \
135    if { (eval $(CC) conftest.c -o conftest) 2> /dev/null; } && \
136      (test -s conftest && (./conftest; exit) 2> /dev/null); then \
137      ac_cv_sizeof_int=`cat conftestval`; \
138      echo "$$ac_cv_sizeof_int"; \
139    else \
140      echo "failed to get size of int"; \
141      ac_cv_sizeof_int=0; \
142    fi; \
143    echo "#define LC_SIZEOF_INT $$ac_cv_sizeof_int" >> $(OSDIR)/config.h; \
144    rm -f conftest.c conftest conftestval; \
145    \
146    echo -n "checking size of void *... "; \
147    echo "#include <stdio.h>" > conftest.c; \
148    echo "main() { FILE *f=fopen(\"conftestval\", \"w\");" >> conftest.c; \
149    echo "if (!f) exit(1); fprintf(f, \"%d\\n\", sizeof(void *)); exit(0); }" >> conftest.c; \
150    if { (eval $(CC) conftest.c -o conftest) 2> /dev/null; } && \
151      (test -s conftest && (./conftest; exit) 2> /dev/null); then \
152      ac_cv_sizeof_void_p=`cat conftestval`; \
153      echo "$$ac_cv_sizeof_void_p"; \
154    else \
155      echo "failed to get size of void *"; \
156      ac_cv_sizeof_void_p=0; \
157    fi; \
158    echo "#define LC_SIZEOF_VOID_P $$ac_cv_sizeof_void_p" >> $(OSDIR)/config.h; \
159    rm -f conftest.c conftest conftestval; \
160    \
161    echo -n "checking size of long long... "; \
162    echo "#include <stdio.h>" > conftest.c; \
163    echo "main() { FILE *f=fopen(\"conftestval\", \"w\");" >> conftest.c; \
164    echo "if (!f) exit(1); fprintf(f, \"%d\\n\", sizeof(long long)); exit(0); }" >> conftest.c; \
165    if { (eval $(CC) conftest.c -o conftest) 2> /dev/null; } && \
166      (test -s conftest && (./conftest; exit) 2> /dev/null); then \
167      ac_cv_sizeof_long_long=`cat conftestval`; \
168      echo "$$ac_cv_sizeof_long_long"; \
169    else \
170      echo "failed to get size of long long"; \
171      ac_cv_sizeof_long_long=0; \
172    fi; \
173    echo "#define LC_SIZEOF_LONG_LONG $$ac_cv_sizeof_long_long" >> $(OSDIR)/config.h; \
174    rm -f conftest.c conftest conftestval; \
175    case 2 in \
176      $$ac_cv_sizeof_short)     lcint16=short;; \
177      $$ac_cv_sizeof_int)       lcint16=int;; \
178    esac; \
179    case 4 in \
180      $$ac_cv_sizeof_short)     lcint32=short;; \
181      $$ac_cv_sizeof_int)       lcint32=int;; \
182      $$ac_cv_sizeof_long)      lcint32=long;; \
183    esac; \
184    echo "" >> $(OSDIR)/config.h; \
185    echo "typedef signed char lcint8;" >> $(OSDIR)/config.h; \
186    echo "typedef unsigned char lcuint8;" >> $(OSDIR)/config.h; \
187    if test -n "$$lcint16"; then \
188      echo "typedef signed $$lcint16 lcint16;" >> $(OSDIR)/config.h; \
189      echo "typedef unsigned $$lcint16 lcuint16;" >> $(OSDIR)/config.h; \
190    else \
191      echo "#error need to define lcint16 and lcuint16" >> $(OSDIR)/config.h; \
192    fi; \
193    if test -n "$$lcint32"; then \
194    echo "typedef signed $$lcint32 lcint32;" >> $(OSDIR)/config.h; \
195    echo "typedef unsigned $$lcint32 lcuint32;" >> $(OSDIR)/config.h; \
196    else \
197      echo "#error need to define lcint32 and lcuint32" >> $(OSDIR)/config.h; \
198    fi; \
199    echo "" >> $(OSDIR)/config.h
200
201### Check if machine is little or big endian
202    @echo -n "Determining endianess... "
203    @echo "main () { union { long l; char c[sizeof (long)]; } u;" > endiantest.c
204    @echo "u.l = 1; exit (u.c[sizeof (long) - 1] == 1); }" >> endiantest.c
205    @if { (eval $(CC) endiantest.c -o endiantest) 2> /dev/null; } && \
206      (test -s endiantest && (./endiantest; exit) 2> /dev/null); then \
207      echo "little endian"; \
208      echo "#define LC_LITTLE_ENDIAN" >> $(OSDIR)/config.h; \
209      echo "#define LCUINT16(val) val" >> $(OSDIR)/config.h; \
210      echo "#define LCUINT32(val) val" >> $(OSDIR)/config.h; \
211      echo "#define LCINT16(val) val" >> $(OSDIR)/config.h; \
212      echo "#define LCINT32(val) val" >> $(OSDIR)/config.h; \
213      echo "#define LCFLOAT(val) val" >> $(OSDIR)/config.h; \
214    else \
215      echo "big endian"; \
216      echo "#define LC_BIG_ENDIAN" >> $(OSDIR)/config.h; \
217      echo "#define LCUINT16(val) ((lcuint16) ( \\" >> $(OSDIR)/config.h; \
218      echo "    (((lcuint16) (val) & (lcuint16) 0x00ffU) << 8) | \\" >> $(OSDIR)/config.h; \
219      echo "    (((lcuint16) (val) & (lcuint16) 0xff00U) >> 8)))" >> $(OSDIR)/config.h; \
220      echo "#define LCUINT32(val) ((lcuint32) ( \\" >> $(OSDIR)/config.h; \
221      echo "    (((lcuint32) (val) & (lcuint32) 0x000000ffU) << 24) | \\" >> $(OSDIR)/config.h; \
222      echo "    (((lcuint32) (val) & (lcuint32) 0x0000ff00U) <<  8) | \\" >> $(OSDIR)/config.h; \
223      echo "    (((lcuint32) (val) & (lcuint32) 0x00ff0000U) >>  8) | \\" >> $(OSDIR)/config.h; \
224      echo "    (((lcuint32) (val) & (lcuint32) 0xff000000U) >> 24)))" >> $(OSDIR)/config.h; \
225      echo "#define LCINT16(val) ((lcint16)LCUINT16(val))" >> $(OSDIR)/config.h; \
226      echo "#define LCINT32(val) ((lcint32)LCUINT32(val))" >> $(OSDIR)/config.h; \
227      echo -e "inline float LCFLOAT (float l)\n{" >> $(OSDIR)/config.h; \
228      echo -e "  union { unsigned char b[4]; float f; } in, out;\n" >> $(OSDIR)/config.h; \
229      echo -e "  in.f = l;\n  out.b[0] = in.b[3];\n  out.b[1] = in.b[2];" >> $(OSDIR)/config.h; \
230      echo -e "  out.b[2] = in.b[1];\n  out.b[3] = in.b[0];\n" >> $(OSDIR)/config.h; \
231      echo -e "  return out.f;\n}" >> $(OSDIR)/config.h; \
232    fi; \
233    echo "" >> $(OSDIR)/config.h
234    @rm -f endiantest.c endiantest
235
236#### Check if the user has GTK+ and GLIB installed.
237    @echo -n "Checking if GLIB and GTK+ are installed... "
238    @if (pkg-config --atleast-version=2.0.0 glib-2.0) && (pkg-config --atleast-version=2.0.0 gtk+-2.0); then \
239      echo "ok"; \
240      echo "CFLAGS += \$$(shell pkg-config gtk+-2.0 --cflags)" >> $(OSDIR)/config.mk; \
241      echo "CXXFLAGS += \$$(shell pkg-config gtk+-2.0 --cflags)" >> $(OSDIR)/config.mk; \
242      echo "LIBS += \$$(shell pkg-config gtk+-2.0 --libs)" >> $(OSDIR)/config.mk; \
243    else \
244      echo "failed"; \
245      rm -rf $(OSDIR)/config.mk; \
246      exit 1; \
247    fi
248
249## Check if the user has libjpeg installed
250    @echo -n "Checking for jpeg support... "
251    @echo "char jpeg_read_header();" > jpegtest.c
252    @echo "int main() { jpeg_read_header(); return 0; }" >> jpegtest.c
253    @if { (eval $(CC) jpegtest.c -ljpeg -o jpegtest $(CPPFLAGS) $(LDFLAGS)) 2> /dev/null; } && \
254      (test -s jpegtest); then  \
255      echo "ok"; \
256      echo "HAVE_JPEGLIB = yes" >> $(OSDIR)/config.mk; \
257      echo "#define LC_HAVE_JPEGLIB" >> $(OSDIR)/config.h; \
258    else \
259      echo "no (libjpeg optional)"; \
260      echo "HAVE_JPEGLIB = no" >> $(OSDIR)/config.mk; \
261      echo "#undef LC_HAVE_JPEGLIB" >> $(OSDIR)/config.h; \
262    fi
263    @rm -f jpegtest.c jpegtest
264
265### Check if the user has zlib installed
266    @echo -n "Checking for zlib support... "
267    @echo "char gzread();" > ztest.c
268    @echo "int main() { gzread(); return 0; }" >> ztest.c
269    @if { (eval $(CC) ztest.c -lz -o ztest $(CPPFLAGS) $(LDFLAGS)) 2> /dev/null; } && \
270      (test -s ztest); then  \
271      echo "ok"; \
272      echo "HAVE_ZLIB = yes" >> $(OSDIR)/config.mk; \
273      echo "#define LC_HAVE_ZLIB" >> $(OSDIR)/config.h; \
274    else \
275      echo "no (zlib optional)"; \
276      echo "HAVE_ZLIB = no" >> $(OSDIR)/config.mk; \
277      echo "#undef LC_HAVE_ZLIB" >> $(OSDIR)/config.h; \
278    fi
279    @rm -f ztest.c ztest
280
281### Check if the user has libpng installed
282    @echo -n "Checking for png support... "
283    @echo "char png_read_info();" > pngtest.c
284    @echo "int main() { png_read_info(); return 0; }" >> pngtest.c
285    @if { (eval $(CC) pngtest.c -lz -lpng -o pngtest $(CPPFLAGS) $(LDFLAGS)) 2> /dev/null; } && \
286      (test -s pngtest); then  \
287      echo "ok"; \
288      echo "HAVE_PNGLIB = yes" >> $(OSDIR)/config.mk; \
289      echo "#define LC_HAVE_PNGLIB" >> $(OSDIR)/config.h; \
290    else \
291      echo "no (libpng optional)"; \
292      echo "HAVE_PNGLIB = no" >> $(OSDIR)/config.mk; \
293      echo "#undef LC_HAVE_PNGLIB" >> $(OSDIR)/config.h; \
294    fi
295    @rm -f pngtest.c pngtest
296
297    @echo "" >> $(OSDIR)/config.h
298    @echo "#endif // _CONFIG_H_" >> $(OSDIR)/config.h
Note: See TracBrowser for help on using the browser.