premake 生成makefile(三)

1.新的lua脚本

solution "hello_world"
        configurations {"Debug", "Release"}
        platforms {"x32", "x64"}

        project "hello_world"
                kind "ConsoleApp"
                language "C++"
                files {"**.h", "**.cpp"}

                configuration "Debug"
                        defines {"DEBUG"}
                        flags {"Symbols"}

                configuration "Release"
                        defines {"NDEBUG"}
                        flags {"Optimize"}

这里添加了平台位数的配置。

2.生成.make文件

# GNU Make project makefile autogenerated by Premake
ifndef config
  config=debug32
endif

ifndef verbose
  SILENT = @
endif

CC = gcc
CXX = g++
AR = ar

ifndef RESCOMP
  ifdef WINDRES
    RESCOMP = $(WINDRES)
  else
    RESCOMP = windres
  endif
endif

ifeq ($(config),debug32)
  OBJDIR     = obj/x32/Debug
  TARGETDIR  = .
  TARGET     = $(TARGETDIR)/hello_world
  DEFINES   += -DDEBUG
  INCLUDES  +=
  ALL_CPPFLAGS  += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
  ALL_CFLAGS    += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -m32
  ALL_CXXFLAGS  += $(CXXFLAGS) $(ALL_CFLAGS)
  ALL_RESFLAGS  += $(RESFLAGS) $(DEFINES) $(INCLUDES)
  ALL_LDFLAGS   += $(LDFLAGS) -m32 -L/usr/lib32
  LDDEPS    +=
  LIBS      += $(LDDEPS)
  LINKCMD    = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
  define PREBUILDCMDS
  endef
  define PRELINKCMDS
  endef
  define POSTBUILDCMDS
  endef
endif

ifeq ($(config),release32)
  OBJDIR     = obj/x32/Release
  TARGETDIR  = .
  TARGET     = $(TARGETDIR)/hello_world
  DEFINES   += -DNDEBUG
  INCLUDES  +=
  ALL_CPPFLAGS  += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
  ALL_CFLAGS    += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -O2 -m32
  ALL_CXXFLAGS  += $(CXXFLAGS) $(ALL_CFLAGS)
  ALL_RESFLAGS  += $(RESFLAGS) $(DEFINES) $(INCLUDES)
  ALL_LDFLAGS   += $(LDFLAGS) -s -m32 -L/usr/lib32
  LDDEPS    +=
  LIBS      += $(LDDEPS)
  LINKCMD    = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
  define PREBUILDCMDS
  endef
  define PRELINKCMDS
  endef
  define POSTBUILDCMDS
  endef
endif

ifeq ($(config),debug64)
  OBJDIR     = obj/x64/Debug
  TARGETDIR  = .
  TARGET     = $(TARGETDIR)/hello_world
  DEFINES   += -DDEBUG
  INCLUDES  +=
  ALL_CPPFLAGS  += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
  ALL_CFLAGS    += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -g -m64
  ALL_CXXFLAGS  += $(CXXFLAGS) $(ALL_CFLAGS)
  ALL_RESFLAGS  += $(RESFLAGS) $(DEFINES) $(INCLUDES)
  ALL_LDFLAGS   += $(LDFLAGS) -m64 -L/usr/lib64
  LDDEPS    +=
  LIBS      += $(LDDEPS)
  LINKCMD    = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
  define PREBUILDCMDS
  endef
  define PRELINKCMDS
  endef
  define POSTBUILDCMDS
  endef
endif

ifeq ($(config),release64)
  OBJDIR     = obj/x64/Release
  TARGETDIR  = .
  TARGET     = $(TARGETDIR)/hello_world
  DEFINES   += -DNDEBUG
  INCLUDES  +=
  ALL_CPPFLAGS  += $(CPPFLAGS) -MMD -MP $(DEFINES) $(INCLUDES)
  ALL_CFLAGS    += $(CFLAGS) $(ALL_CPPFLAGS) $(ARCH) -O2 -m64
  ALL_CXXFLAGS  += $(CXXFLAGS) $(ALL_CFLAGS)
  ALL_RESFLAGS  += $(RESFLAGS) $(DEFINES) $(INCLUDES)
  ALL_LDFLAGS   += $(LDFLAGS) -s -m64 -L/usr/lib64
  LDDEPS    +=
  LIBS      += $(LDDEPS)
  LINKCMD    = $(CXX) -o $(TARGET) $(OBJECTS) $(RESOURCES) $(ARCH) $(ALL_LDFLAGS) $(LIBS)
  define PREBUILDCMDS
  endef
  define PRELINKCMDS
  endef
  define POSTBUILDCMDS
  endef
endif

OBJECTS := \
        $(OBJDIR)/hello_world.o \

RESOURCES := \

SHELLTYPE := msdos
ifeq (,$(ComSpec)$(COMSPEC))
  SHELLTYPE := posix
endif
ifeq (/bin,$(findstring /bin,$(SHELL)))
  SHELLTYPE := posix
endif

.PHONY: clean prebuild prelink

all: $(TARGETDIR) $(OBJDIR) prebuild prelink $(TARGET)
        @:

$(TARGET): $(GCH) $(OBJECTS) $(LDDEPS) $(RESOURCES)
        @echo Linking hello_world
        $(SILENT) $(LINKCMD)
        $(POSTBUILDCMDS)

$(TARGETDIR):
        @echo Creating $(TARGETDIR)
ifeq (posix,$(SHELLTYPE))
        $(SILENT) mkdir -p $(TARGETDIR)
else
        $(SILENT) mkdir $(subst /,\\,$(TARGETDIR))
endif

$(OBJDIR):
        @echo Creating $(OBJDIR)
ifeq (posix,$(SHELLTYPE))
        $(SILENT) mkdir -p $(OBJDIR)
else
        $(SILENT) mkdir $(subst /,\\,$(OBJDIR))
endif

clean:
        @echo Cleaning hello_world
ifeq (posix,$(SHELLTYPE))
        $(SILENT) rm -f  $(TARGET)
        $(SILENT) rm -rf $(OBJDIR)
else
        $(SILENT) if exist $(subst /,\\,$(TARGET)) del $(subst /,\\,$(TARGET))
        $(SILENT) if exist $(subst /,\\,$(OBJDIR)) rmdir /s /q $(subst /,\\,$(OBJDIR))
endif

prebuild:
        $(PREBUILDCMDS)

prelink:
        $(PRELINKCMDS)

ifneq (,$(PCH))
$(GCH): $(PCH)
        @echo $(notdir $<)
        $(SILENT) $(CXX) -x c++-header $(ALL_CXXFLAGS) -MMD -MP $(DEFINES) $(INCLUDES) -o "$@" -MF "$(@:%.gch=%.d)" -c "$<"
endif

$(OBJDIR)/hello_world.o: hello_world.cpp
        @echo $(notdir $<)
        $(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF $(@:%.o=%.d) -c "$<"

-include $(OBJECTS:%.o=%.d)
ifneq (,$(PCH))
  -include $(OBJDIR)/$(notdir $(PCH)).d
endif
                   

3. 生成Makefile文件

# GNU Make solution makefile autogenerated by Premake
# Type "make help" for usage help

ifndef config
  config=debug32
endif
export config

PROJECTS := hello_world

.PHONY: all clean help $(PROJECTS)

all: $(PROJECTS)

hello_world: 
        @echo "==== Building hello_world ($(config)) ===="
        @${MAKE} --no-print-directory -C . -f hello_world.make

clean:
        @${MAKE} --no-print-directory -C . -f hello_world.make clean

help:
        @echo "Usage: make [config=name] [target]"
        @echo ""
        @echo "CONFIGURATIONS:"
        @echo "   debug32"
        @echo "   release32"
        @echo "   debug64"
        @echo "   release64"
        @echo ""
        @echo "TARGETS:"
        @echo "   all (default)"
        @echo "   clean"
        @echo "   hello_world"
        @echo ""
        @echo "For more information, see http://industriousone.com/premake/quick-start"

4.指定make

[root@instance-4420gg0f hello_world]# make
==== Building hello_world (debug32) ====
Creating obj/x32/Debug
hello_world.cpp
In file included from /usr/include/features.h:399:0,
                 from /usr/include/c++/4.8.2/x86_64-redhat-linux/32/bits/os_defines.h:39,
                 from /usr/include/c++/4.8.2/x86_64-redhat-linux/32/bits/c++config.h:426,
                 from /usr/include/c++/4.8.2/iostream:38,
                 from hello_world.cpp:3:
/usr/include/gnu/stubs.h:7:27: 致命错误:gnu/stubs-32.h:没有那个文件或目录
 # include <gnu/stubs-32.h>
                           ^
编译中断。
make[1]: *** [obj/x32/Debug/hello_world.o] 错误 1
make: *** [hello_world] 错误 2
[root@instance-4420gg0f hello_world]# more/proc/version
-bash: more/proc/version: 没有那个文件或目录

5. 指定config

[root@instance-4420gg0f hello_world]# make config=release_x64
==== Building hello_world (release_x64) ====
[root@instance-4420gg0f hello_world]# ll
总用量 36
-rw-r--r-- 1 root root  147 9月  18 13:48 hello_world.cpp
-rw-r--r-- 1 root root  481 9月  18 15:02 hello_world.lua
-rw-r--r-- 1 root root 4322 9月  18 15:03 hello_world.make
-rwxr-xr-x 1 root root 9056 9月  18 13:59 hello_world.out
-rw-r--r-- 1 root root  769 9月  18 15:03 Makefile
drwxr-xr-x 3 root root 4096 9月  18 15:07 obj
[root@instance-4420gg0f hello_world]# make config=release_x32
==== Building hello_world (release_x32) ====
[root@instance-4420gg0f hello_world]# ll
总用量 36
-rw-r--r-- 1 root root  147 9月  18 13:48 hello_world.cpp
-rw-r--r-- 1 root root  481 9月  18 15:02 hello_world.lua
-rw-r--r-- 1 root root 4322 9月  18 15:03 hello_world.make
-rwxr-xr-x 1 root root 9056 9月  18 13:59 hello_world.out
-rw-r--r-- 1 root root  769 9月  18 15:03 Makefile
drwxr-xr-x 3 root root 4096 9月  18 15:07 obj
[root@instance-4420gg0f hello_world]# make config=debug_x64
==== Building hello_world (debug_x64) ====
[root@instance-4420gg0f hello_world]# ll
总用量 36
-rw-r--r-- 1 root root  147 9月  18 13:48 hello_world.cpp
-rw-r--r-- 1 root root  481 9月  18 15:02 hello_world.lua
-rw-r--r-- 1 root root 4322 9月  18 15:03 hello_world.make
-rwxr-xr-x 1 root root 9056 9月  18 13:59 hello_world.out
-rw-r--r-- 1 root root  769 9月  18 15:03 Makefile
drwxr-xr-x 3 root root 4096 9月  18 15:07 obj

6.观察后发现是config赋值有问题,不需要添加_x

[root@instance-4420gg0f hello_world]# make config=release64
==== Building hello_world (release64) ====
Creating obj/x64/Release
hello_world.cpp
Linking hello_world
[root@instance-4420gg0f hello_world]# 

7.但是32位的,根据make后的信息知道,缺少文件。安装后。

[root@instance-4420gg0f hello_world]# make
==== Building hello_world (debug32) ====
Linking hello_world

 

posted @ 2019-09-18 15:54  N_zero  阅读(397)  评论(0)    收藏  举报