GNU make"命令在第一个目标之前开始"

时间:2014-09-27 19:30:12

标签: makefile mingw msys

我一直在尝试使用MINGW在Windows上编译GLEW,如here所述 但是我在第一个目标"

之前开始执行"命令

Makefile(我无法在此处使格式化)

由于

1 个答案:

答案 0 :(得分:3)

使用以下形状预期“规则”:

target: prerequisites ...
    command
...

您需要在第一次调用gcc之前在makefile中定义目标。只需在开头添加一行glew:即可。带命令的每一行都需要以制表符开头。

有关详细信息,请查看制作手册的简介部分:https://www.gnu.org/software/make/manual/html_node/Introduction.html

修改后的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构建dll

make -f makefile.mod exe构建exe和dll(如果需要)