0

I have been trying to compile GLEW with MINGW on Windows as explained here However I get the "commands commence before first target"

Makefile (I cannot get the formatting to work here)

Thanks

Community
  • 1
  • 1
Eejin
  • 770
  • 1
  • 8
  • 29
  • 1
    A makefile is not just a shell script. If you want to learn to write makefiles, you should read some tutorials and start with something simpler. – Beta Sep 27 '14 at 20:14

1 Answers1

3

Make expect “rules” with the following shape:

target: prerequisites ...
    command
...

You need to define a target in your makefile before the first call to gcc. Just add a line with glew: in the beginning. Each line with a command need to start with a tab character.

Have a look at the introduction section of the make manual for more information: https://www.gnu.org/software/make/manual/html_node/Introduction.html

modified version of your makefile (makefile.mod)

## makefile based on answer http://stackoverflow.com/a/6005262/663518
## http://stackoverflow.com/questions/6005076/building-glew-on-windows-with-mingw

.PHONY: glew
glew: libs exe

## libs
libs: lib/glew32.dll lib/glew32mx.dll

lib/glew32.dll:
    @echo ##compiling libglew32
    gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude  -DGLEW_BUILD -o src/glew.o -c src/glew.c
    gcc -shared -Wl,-soname,libglew32.dll -Wl,--out-implib,lib/libglew32.dll.a    -o lib/glew32.dll src/glew.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
    ar cr lib/libglew32.a src/glew.o

lib/glew32mx.dll:
    @echo ##compiling libglew32mx
    gcc -DGLEW_NO_GLU -DGLEW_MX -O2 -Wall -W -Iinclude  -DGLEW_BUILD -o src/glew.mx.o -c src/glew.c
    gcc -shared -Wl,-soname,libglew32mx.dll -Wl,--out-implib,lib/libglew32mx.dll.a -o lib/glew32mx.dll src/glew.mx.o -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32
    ar cr lib/libglew32mx.a src/glew.mx.o

## glewinfo and visualinfo programs. 
exe: bin/glewinfo.exe bin/visualinfo.exe

bin/glewinfo.exe: lib/glew32.dll
    @echo ##compiling glewinfo.exe
    gcc -c -O2 -Wall -W -Iinclude  -o src/glewinfo.o src/glewinfo.c
    gcc -O2 -Wall -W -Iinclude  -o bin/glewinfo.exe src/glewinfo.o -Llib  -lglew32 -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32

bin/visualinfo.exe: lib/glew32.dll
    @echo ##compiling visualinfo
    gcc -c -O2 -Wall -W -Iinclude  -o src/visualinfo.o src/visualinfo.c
    gcc -O2 -Wall -W -Iinclude  -o bin/visualinfo.exe src/visualinfo.o -Llib  -lglew32 -L/mingw/lib -lglu32 -lopengl32 -lgdi32 -luser32 -lkernel32

> make -f makefile.mod
##compiling libglew32
gcc -DGLEW_NO_GLU -O2 -Wall -W -Iinclude...
...


make -f makefile.mod libs builds the dll

make -f makefile.mod exe builds the exe and dll (if necessary)

David L.
  • 2,095
  • 23
  • 23
  • 1
    This is still not a makefile. It is still a shell script. – Mark Galeck Sep 28 '14 at 20:50
  • The manual says "The makefile can also tell make how to run miscellaneous commands when explicitly asked" ;-) – David L. Sep 28 '14 at 21:18
  • L OK I will ask you a rhetorical question. Suppose you have a shell script, and your boss says "this is inefficient, rewrite this in C". You write main(), then in main() you use sprintf to add the lines of the old script, to a single big string. Finally, you use "system()" function to execute the big string. The question is: would your boss be happy with this or not happy? In other words, is your program a C program, or is it still the shell script?? You can also say the same thing here "The manual for C stdlib says, there are functions "sprintf" and "system" " – Mark Galeck Sep 28 '14 at 21:53
  • 1
    Thank you, works like a charm! I had to replace the spaces by tabs but otherwise it worked perfectly. – Eejin Sep 29 '14 at 14:02