Adding the Cygwin/mingw documentation from Jean-Seb (see e-mail dated Thu 7/9/2009...
[freeglut] / README.cygwin_mingw
1 Glut then!\r
2 \r
3 By Jean-Seb on Friday July 10, 2009, 00:18\r
4 Translated by Babelfish with a scrub from John F. Fay.  For points of confusion\r
5 please refer to the original French version.\r
6 \r
7 Freeglut is an open-source evolution of GLUT.\r
8 Under Windows, one can use it with Cygwin.\r
9 Easy? Yes, if one agrees to distribute "cygwin1.dll".\r
10 Let us help freeglut gain its independence !\r
11 m.à.j 10/7/2009: generation of a library for linking without the DLL.\r
12 \r
13 \r
14 Recovery of the sources\r
15 \r
16     * Download the sources of version 2.6.0 which integrates recent changes.\r
17     * For the moment, it is a RC (Release Candidate), but the final version\r
18       should not delay.\r
19     * The use of the 2.6 is preferable with the 2.4-stable branch because many\r
20       bugs have been corrected.\r
21     * You will find the sources on the site of Freeglut:\r
22           o http://freeglut.sourceforge.net/\r
23 \r
24 \r
25 Objectives and preparation\r
26 Objectives\r
27 \r
28     * We will create a DLL related to Cygwin, and an independent static library\r
29     * We will also create a dynamic library, allowing linking with the DLL.\r
30 \r
31 \r
32 List of generated files\r
33 \r
34     * freeglut.dll: a traditional DLL for the dynamic linkage.\r
35     * libfreeglut.a: the static library. The final program is autonomous (at\r
36       least for OpenGL).\r
37     * libfreeglutdll.a: the dynamic library. The final program needs\r
38       freeglut.dll.\r
39 \r
40 \r
41 Preparation\r
42 \r
43     * Extract the files from the freeglut archive.\r
44     * Go in the directory src (located at the root of the Freeglut directory),\r
45       and create a "Gl" sub-directory\r
46           o In this sub-directory, copy the files of the directory "include/Gl"\r
47 \r
48     * Why is it necessary to create a "Gl" directory for compilation?\r
49           o I needed it to simplify things during my tests.\r
50           o If not you can create the repertories directly, and copy the files\r
51             as indicated in the point installation (see below).\r
52 \r
53     * Do a little housekeeping in /lib:\r
54           o Erase all the references to the glut, so as not to conflict with the\r
55             linking.\r
56           o This stage is optional, you can also choose to do the housekeeping\r
57             only after a successful compilation of Freeglut.\r
58           o In your enthusiasm to clean things up, be careful not to erase the\r
59             library glu32.lib (not to be confused with glut32.lib).\r
60 \r
61 \r
62 Compilation\r
63 \r
64     * Forget the "./configure, make, make install" triptych.\r
65           o It does not go at all with Cygwin.\r
66 \r
67     * Here Makefile which will make the deal:\r
68 \r
69 #Makefile for Freeglut 2.6.0-rc and Cygwin\r
70 #To place in the directory \93src\94\r
71 \r
72 sources=$ (wildcard *.c)\r
73 objs=$ (sources: .c=.o)\r
74 libname=freeglut\r
75 \r
76 \r
77 CFLAGS=-O2 - DTARGET_HOST_MS_WINDOWS - DX_DISPLAY_MISSING - DFREEGLUT_STATIC - I./\r
78 LDFLAGS=-lopengl32 - lgdi32 - lwinmm\r
79 \r
80 nocyg=-mno-cygwin - mwindows\r
81 \r
82 all: $ (objs)\r
83         #construction DLL related to cygwin1.dll\r
84         GCC $ (nocyg) $ (objs) - shared $ (LDFLAGS) - O $ (libname) .dll\r
85         Nm $ (libname) .dll  | awk \93BEGIN {print \93EXPORTS\94} /T _glut/{sub (/^.*T _/,\94 \ T "); print}\94 > $ (libname) .def\r
86         dlltool --dllname $ (libname) .dll --input-def $ (libname) .def --output-lib lib$ (libname) dll.a\r
87 \r
88         #construction static library independent of cygwin\r
89         rear Cr lib$ (libname) .a $ (objs)\r
90         #pas inevitably obligatory (creation of an index to accelerate the accesses)\r
91         ranlib lib$ (libname) .a\r
92 \r
93 %.o: %.c\r
94         GCC $ (nocyg) - C $ (CFLAGS) $<\r
95 \r
96 clean:\r
97         rm - F *.o $ (libname) .dll $ (libname) .def lib$ (libname) dll.a lib$ (libname) .a\r
98 \r
99 \r
100 \r
101 \r
102 Some remarks on the makefile\r
103 \r
104     * This makefile creates a DLL, a static library (a file, in other words) and\r
105       the dynamic library which will allow the use of the DLL.\r
106 \r
107     * Do not try to strip the static library! You may not be able to compile\r
108       applications with static library any more.\r
109           o On the other hand, you can strip the final executable obtained after\r
110             compiling your application.\r
111 \r
112     * I chose to call the DLL and the libraries by their "true names":\r
113       freeglut.dll libfreeglutdll.a and libfreeglut.a.\r
114           o Script configures recreated (for reasons of compatibility with the\r
115             old GLUT library) glut.dll and libglut.a.\r
116           o During the my tests, I had conflicts with an authentic "glut" which\r
117             trailed in my "/lib". I decided to call the things by their name, in\r
118             order to avoid confusions.\r
119           o Nothing prevents you from renaming the DLL, if you need to use GLUT\r
120             programs which you cannot recompile.\r
121 \r
122     * The dynamic library is generated starting from the DLL.\r
123           o For reasons of brevity, I used awk. It generates the export file\r
124             used by dlltool.\r
125           o The only notable thing is the selection of the functions whose name\r
126             starts with _glut, in order to avoid including in the dynamic\r
127             library the functions that are not related to freeglut.\r
128           o then, one uses dlltool in a very traditional way.\r
129 \r
130 Nm $ (libname) .dll  | awk \93BEGIN {print \93EXPORTS\94} /T _glut/{sub (/^.*T _/,\94 \ T "); print}\94 > $ (libname) .def\r
131 dlltool --dllname $ (libname) .dll --input-def $ (libname) .def --output-lib lib$ (libname) dll.a\r
132 \r
133 \r
134 \r
135 \r
136 Installation\r
137 \r
138     * Copy libfreeglut.a, libfreeglutdll.a into the Cygwin directory /lib.\r
139     * Copy freglut.dll in the system32 of Windows (this is practical, but not\r
140       clean!).\r
141     * Copy the files headers of Freeglut (/include/gl) into the Cygwin directory\r
142       /usr/include/Gl.\r
143     * Copy the files headers (always /include/gl) into /usr/include/mingw/Gl:\r
144       this is used for compilations with the flag - mno-cygwin, which uses the\r
145       includes in mingw.\r
146           o You may need to erase the old GLUT include files if you installed it\r
147             with Cygwin.\r
148 \r
149 \r
150 Use of the library\r
151 \r
152     * We will test with the program shapes, found in progs/demonstrations/shapes\r
153           o -mno-cygwin is used to force the use of Mingw without the large\r
154             dependence cygwin1.dll.\r
155           o -mwindows is only used to remove the horrible Shell window (very\r
156             useful for the settling, on the other hand).\r
157           o -L. (note the period after the "L"): I left libfreeglut.a,\r
158             libfreeglutdll.a and freeglut.dll in the test directory, at the time \r
159             of the tests.\r
160 \r
161 \r
162 Compilation of the static freeglut library, without cygwin\r
163 \r
164     * All the simplicity lies in the define: -DFREEGLUT_STATIC\r
165           o It serves to obtain good decoration of the function names in the\r
166             imports of the lib Freeglut.\r
167           o You can test without and use a hex editor to see the differences\r
168             in the objects.\r
169     * attention with the order of the libraries: -lfreeglut (static) must be\r
170       before the declaration of the dynamic libraries.\r
171 \r
172     * gcc shapes.c -L. -lfreeglut -lopengl32 -lwinmm -lgdi32 -mno-cygwin -mwindows -DFREEGLUT_STATIC\r
173 \r
174 \r
175 Compilation with DLL freeglut, without cygwin\r
176 \r
177     * For the define, see the notices above\r
178     * The order of the libraries is no longer important.\r
179 \r
180     * gcc shapes.c -L. -lopengl32 -lwinmm -lgdi32 -lfreeglut -mno-cygwin -DFREEGLUT_STATIC\r
181 \r
182 \r
183 Compilation with DLL freeglut, Cygwin\r
184 \r
185     * This example is given only for reference, the topic of this ticket being\r
186       to get rid of Cygwin.\r
187           o Let us say that can be used to make the point (and later).\r
188 \r
189     * gcc shapes.c -L. -lopengl32 -lwinmm -lgdi32 -lfreeglut\r
190 \r
191 \r
192 \r
193 Where are the dooooocs?\r
194 \r
195     * Freeglut is delivered with its documentation, more very up to date.\r
196           o It seems that there is a problem with the original GLUT\r
197             documentation. Not only it does not correspond completely to the\r
198             operation of Freeglut, but moreover, its author (Mark Kilgard)\r
199             copyrighted it. Its distribution is thus difficult.\r
200 \r
201     * Jocelyn Fréchot undertook a levelling of the docs for version 2.6.0. One can find them on his site for the moment:\r
202           o http://jocelyn.frechot.free.fr/freeglut/\r
203 \r
204 \r
205 Something survived\85\r
206 \r
207     * I also tested the recompiling of the demonstrations of the original lib\r
208       GLUT (peace with its ashes).\r
209           o Nothing in particular to be announced.\r
210 \r
211     * Thank you with all the courageous maintainers for Freeglut, that one\r
212       believed dead, but which still move.\r