replace Makefile with a premake script for generating make/ide files

This commit is contained in:
gered 2012-09-23 12:53:25 -04:00
parent e6b0de1f19
commit 54d64411ab
4 changed files with 74 additions and 154 deletions

154
Makefile
View file

@ -1,154 +0,0 @@
# this Makefile is based on the ones from devkitPro
# TODO: probably should simplify it a bunch (mainly the rules at the bottom)
TARGET := md2tomesh
#-------------------------------------------------------------------------------
# detect build configuration
#-------------------------------------------------------------------------------
ifndef ("CFG")
CFG=Debug
endif
ifeq ("$(CFG)","Debug")
BUILD := Debug
endif
ifeq ("$(CFG)","Release")
BUILD := Release
endif
ifeq ("$(BUILD)", "")
$(error invalid configuration specified via CFG argument)
endif
$(info $(CFG) configuration selected)
#-------------------------------------------------------------------------------
# set up platform specifics
#-------------------------------------------------------------------------------
UNAME := $(shell uname)
#-------------------------------------------------------------------------------
# default windows libraries and options
PLATFORM := win32
PLATFORM_LD_FLAGS := -static-libgcc -static-libstdc++
#-------------------------------------------------------------------------------
ifeq ($(UNAME), Linux)
PLATFORM := linux
PLATFORM_LD_FLAGS :=
endif
#-------------------------------------------------------------------------------
ifeq ($(UNAME), Darwin)
PLATFORM := osx
PLATFORM_LD_FLAGS :=
endif
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
ifeq ("$(BUILD)","Debug")
DEFINES := -DDEBUG -DDEBUG_ASSERT_BREAK
CFLAGS := $(DEFINES) -g -Wall
CXXFLAGS := $(CFLAGS)
LDFLAGS := $(PLATFORM_LD_FLAGS)
LIBS := -g
endif
#-------------------------------------------------------------------------------
ifeq ("$(BUILD)","Release")
DEFINES :=
CFLAGS := $(DEFINES) -O2 -Wall
CXXFLAGS := $(CFLAGS)
LDFLAGS := -O2 $(PLATFORM_LD_FLAGS)
LIBS :=
endif
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# find sources, setup commands
#-------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#-------------------------------------------------------------------------------
SOURCES := ${shell find ./src -type d}
export OUTPUT := $(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir))
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
export CXX := g++
export CC := g++
export LD := g++
export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
.PHONY: $(BUILD) clean
#-------------------------------------------------------------------------------
$(BUILD):
$(info building ...)
@[ -d $@ ] || mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#-------------------------------------------------------------------------------
clean:
$(info clean ...)
@rm -fr $(BUILD)
@rm $(OUTPUT)
#-------------------------------------------------------------------------------
else
#-------------------------------------------------------------------------------
# main targets
#-------------------------------------------------------------------------------
$(OUTPUT): $(OFILES)
$(info linking $(notdir $@))
$(LD) -o $@ $(LDFLAGS) $(OFILES) $(LIBS)
cp $(OUTPUT) ../
#-------------------------------------------------------------------------------
# build rules by filetype
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
%.a:
#-------------------------------------------------------------------------------
$(info $(notdir $<))
@rm -f $@
@$(AR) -rc $@ $^
#-------------------------------------------------------------------------------
%.o: %.cpp
$(info $(notdir $<))
@$(CXX) -c $< -o $@ $(CXXFLAGS)
#-------------------------------------------------------------------------------
%.o: %.c
$(info $(notdir $<))
@$(CC) -c $< -o $@ $(CFLAGS)
#-------------------------------------------------------------------------------
%.o: %.s
$(info $(notdir $<))
@$(CC) -x assembler-with-cpp $(ASFLAGS) -c $< -o $@
#-------------------------------------------------------------------------------
%.o: %.S
@echo $(notdir $<)
@$(CC) -x assembler-with-cpp $(ASFLAGS) -c $< -o $@
#-------------------------------------------------------------------------------
endif
#-------------------------------------------------------------------------------

3
generate_makefile.sh Executable file
View file

@ -0,0 +1,3 @@
#!/bin/sh
type premake4 >/dev/null 2>&1 || { echo >&2 "'premake4' not found in your path."; exit 1; }
premake4 --file=premake.lua gmake

8
generate_vs2010.bat Normal file
View file

@ -0,0 +1,8 @@
@echo off
for %%X in (premake4.exe) do (set FOUND=%%~$PATH:X)
if not defined FOUND (
echo 'premake4' not found in your path.
exit /b
)
premake4 --file=premake.lua vs2010

63
premake.lua Normal file
View file

@ -0,0 +1,63 @@
BUILD_DIR = "build"
if _ACTION == "clean" then
os.rmdir(BUILD_DIR)
end
solution "Md2ToMesh"
configurations { "Debug", "Release" }
location (BUILD_DIR .. "/" .. _ACTION)
project "Md2ToMesh"
kind "ConsoleApp"
language "C++"
location (BUILD_DIR .. "/" .. _ACTION)
files {
"./src/**.c*",
"./src/**.h",
}
debugdir "."
---- PLATFORM SPECIFICS ----------------------------------------------------
configuration "vs*"
flags {
"NoPCH",
"NoMinimalRebuild"
}
buildoptions { "/MP" }
defines {
"_CRT_SECURE_NO_WARNINGS",
"_CRT_NONSTDC_NO_WARNINGS"
}
configuration "gmake"
kind "ConsoleApp"
buildoptions { "-Wall" }
configuration { "windows", "gmake" }
kind "ConsoleApp"
defines {
"_GNU_SOURCE=1",
}
links {
"mingw32",
}
linkoptions {
"-static-libgcc",
"-static-libstdc++",
}
----------------------------------------------------------------------------
configuration "Debug"
defines {
"DEBUG",
"DEBUG_ASSERT_BREAK",
}
flags { "Symbols" }
configuration "Release"
defines {
"NDEBUG",
}
flags { "Optimize" }