Skip to content
Permalink
Browse files

Attempt to simplify Makefile

  • Loading branch information...
Cydrak Cydrak
Cydrak authored and Cydrak committed Aug 3, 2013
1 parent 73a4a07 commit 12357721e74a217ba5cbc68e0c597295b67d6b4d
Showing with 145 additions and 230 deletions.
  1. +3 −0 .gitignore
  2. +52 −117 Makefile
  3. +90 −0 Platform.make
  4. +0 −17 nds/Makefile
  5. 0 obj/.gitignore
  6. 0 out/.gitignore
  7. +0 −96 ui/Makefile
@@ -1,8 +1,11 @@
database.bml
firmware
build*/*
*.zip
*.exe
*.dll
*.dylib
*.so
*.res
*.[doa]
*.log
169 Makefile
@@ -1,127 +1,62 @@
.SUFFIXES:
name = dasShiny
ARCH = -march=native
CFLAGS = -I. -O3
CXXFLAGS =
LDFLAGS = -Wl,-Map,build/$(name).map

include Platform.make
include nall/Makefile

nds := nds

profile := accuracy
target := ethos

# options += console

# compiler
c := $(compiler) -std=gnu99
cpp := $(subst cc,++,$(compiler)) -std=gnu++0x
flags := -I. -O3
link :=
objects := libco

# gprof mode
# pgo := profile

# profile-guided optimization mode
# pgo := instrument
# pgo := optimize

ifneq ($(findstring debug,$(options)),)
flags += -g
link += -g
else ifneq ($(pgo),profile)
link += -s
endif

ifneq ($(findstring x86,$(options)),)
flags += -m32
link += -m32
resfmt = --target=pe-i386
endif
ifneq ($(findstring x64,$(options)),)
flags += -m64
link += -m64
resfmt = --target=pe-x86-64
include phoenix/Makefile
include ruby/Makefile

add = $(foreach m,$2,$(eval $(call addmodule,$1,$(m))))
rule = $(if $(wildcard $2),$2; @echo Building $1;$3)

define addmodule
objects += build/$(subst /,-,$1)$2.o

# double $$ defers evaluation so target-specific variables will work
build/$(subst /,-,$1)$2.o: \
$(call rule, $1$2, $1$2/$2.c, $$(CC) $$(ARCH) $$(CFLAGS) -MMD -MP -MF build/$(subst /,-,$1)$2.d -c $$< -o $$@) \
$(call rule, $1$2, $1$2/$2.cpp, $$(CXX) $$(ARCH) $$(CFLAGS) $$(CXXFLAGS) -MMD -MP -MF build/$(subst /,-,$1)$2.d -c $$< -o $$@)
endef

all: build $(name)$(exe)
build:; @mkdir $@

ifneq ($(filter osx,$(platform)),)
# Objective-C++ for ruby/phoenix Cocoa ports
build/phoenix.o: CXX := $(OBJCXX)
build/ruby.o: CXX := $(OBJCXX)
endif
build/phoenix.o: CXXFLAGS += $(phoenixflags)
build/ruby.o: CXXFLAGS += $(rubyflags)

ifneq ($(pgo),profile)
flags += -fomit-frame-pointer
endif

ifeq ($(pgo),profile)
flags += -pg
link += -pg -lgcov
else ifeq ($(pgo),instrument)
flags += -fprofile-generate
link += -lgcov
else ifeq ($(pgo),optimize)
flags += -fprofile-use
endif

# platform
ifeq ($(platform),x)
flags += -march=native
link += -ldl -lX11 -lXext
else ifeq ($(platform),osx)
else ifeq ($(platform),win)
link += $(if $(findstring console,$(options)),-mconsole,-mwindows)
link += -mthreads -luuid -lkernel32 -luser32 -lgdi32 -lcomctl32 -lcomdlg32 -lshell32 -lole32
link += -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc
else
unknown_platform: help;
endif

# implicit rules
compile = \
$(strip \
$(if $(filter %.c,$<), \
$(c) -MMD -MP -MF $*.d $(flags) $1 -c $< -o $@, \
$(if $(filter %.cpp,$<), \
$(cpp) -MMD -MP -MF $*.d $(flags) $1 -c $< -o $@ \
) \
) \
)

%.d: ;
%.o: $<; $(call compile)

all: build;

obj/libco.o: libco/libco.c libco/*
# Embedded resources (note: both zip and ld are path-sensitive here).
build/data-resources.o: $(shell find data/resources/ -iname '*' | sed 's/ /\\ /g')
@echo Packing $(notdir $(basename $@))
@cd data/resources; zip -9qr ../../build/resources.zip .
@cd build; ld -r -b binary -o $(notdir $@) resources.zip

include ui/Makefile
flags := $(flags) $(foreach o,$(call strupper,$(options)),-D$o)
# Windows icon + manifest
build/win-resources.o: ui/resource.rc data/dasShiny.manifest data/dasShiny.ico
@echo Building $(notdir $(basename $@))
@$(WINRC) $< $@

# targets
clean:
-@$(call delete,obj/*.d)
-@$(call delete,obj/*.o)
-@$(call delete,obj/*.a)
-@$(call delete,obj/*.so)
-@$(call delete,obj/*.dylib)
-@$(call delete,obj/*.dll)
-@$(call delete,*.res)
-@$(call delete,*.pgd)
-@$(call delete,*.pgc)
-@$(call delete,*.ilk)
-@$(call delete,*.pdb)
-@$(call delete,*.manifest)
-@$(call RM,build/*)
-@rmdir build

sync:
if [ -d ./libco ]; then rm -r ./libco; fi
if [ -d ./nall ]; then rm -r ./nall; fi
if [ -d ./ruby ]; then rm -r ./ruby; fi
if [ -d ./phoenix ]; then rm -r ./phoenix; fi
cp -r ../libco ./libco
cp -r ../nall ./nall
cp -r ../ruby ./ruby
cp -r ../phoenix ./phoenix
rm -r libco/doc
rm -r libco/test
rm -r nall/test
rm -r ruby/_test
rm -r phoenix/nall
rm -r phoenix/test
$(call add,nds/, apu cpu gpu interface memory ppu slot1 slot2 system utility video wifi)
$(call add,ui/, configuration general input interface settings utility window)
$(call add,, ui phoenix ruby libco)

archive:
if [ -f dasShiny.tar.bz2 ]; then rm dasShiny.tar.bz2; fi
tar -cjf dasShiny.tar.bz2 `ls`
objects += $(if $(filter win,$(platform)),build/win-resources.o)

help:;
$(name)$(exe): $(objects) build/data-resources.o
@echo Linking $(name)
@$(LD) $(ARCH) -o $@ $^ $(LDFLAGS) $(phoenixlink) $(rubylink)

-include obj/*.d
%.d:;
-include build/*.d
@@ -0,0 +1,90 @@

# Architecture: x86, amd64 (default: native)
ifneq ($(filter x86,$(arch)),)
ARCH := -m32
BITS := 32
else ifneq ($(filter amd64,$(arch)),)
ARCH := -m64
BITS := 64
endif

# Build target: debug, release
ifneq ($(filter debug,$(target)),)
CFLAGS += -g
LDFLAGS += -g
else
CFLAGS += -fomit-frame-pointer
LDFLAGS += -s
endif

# Profiling: manual, auto, optimize
ifeq ($(profile),manual)
CFLAGS += -pg
LDFLAGS += -pg -lgcov
else ifeq ($(profile),auto)
CFLAGS += -fprofile-generate
LDFLAGS += -lgcov
else ifeq ($(profile),optimize)
CFLAGS += -fprofile-use
endif

# Autodetect host platform: win, osx, x
ifeq ($(platform),)
uname := $(shell uname -a)
RM = rm -f $1

ifneq ($(filter Windows Msys CYGWIN,$(uname)),)
# Cygwin, Msys, or other POSIX-like variant
platform := win

else ifeq ($(uname),)
# Windows command shell
platform := win
RM = del $(subst /,\,$1)

else ifneq ($(findstring Darwin,$(uname)),)
# Mac OS X
platform := osx
ruby += video.cgl audio.openal input.carbon

CC := clang -x c -std=gnu99
CXX := clang++ -x c++ -std=gnu++11
OBJC := clang -x objective-c -std=gnu99
OBJCXX := clang++ -x objective-c -std=gnu++11
LD := clang++
CFLAGS += -w -stdlib=libc++
LDFLAGS += -lc++ -lobjc

else
# Assume Linux
platform := x
ruby += video.glx
ruby += audio.alsa audio.openal audio.oss audio.pulseaudio audio.pulseaudiosimple audio.ao
ruby += input.sdl input.x

CC := gcc-4.7 -x c -std=gnu99
CXX := g++-4.7 -x c++ -std=gnu++11
LD := g++-4.7
LDFLAGS += -ldl -lX11 -lXext
endif

ifneq ($(filter win cygwin,$(platform)),)
ruby += video.wgl audio.xaudio2 input.rawinput

exe = .exe
CC := gcc -x c -std=gnu99
CXX := g++ -x c++ -std=gnu++11
LD := g++
LDFLAGS += $(if $(filter console,$(options)),-mconsole,-mwindows) \
-mthreads -lkernel32 -luser32 -lgdi32 -lcomctl32 -lcomdlg32 -luuid \
-lshell32 -lole32 -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc

# If needed, detect bitness for the resource compiler. Note, 32-bit shells
# always have P.._ARCHITECTURE=x86, while possibly P.._ARCHITEW6432=AMD64.
BITS ?= $(if $(filter AMD64,$(PROCESSOR_ARCHITEW6432) $(PROCESSOR_ARCHITECTURE)),64,32)
WINRC := windres $(if $(filter 64,$(BITS)),--target=pe-x86-64,--target=pe-i386)
endif

# suppress defines in nall/Makefile
compiler := $(CC)
endif

This file was deleted.

No changes.
No changes.

This file was deleted.

0 comments on commit 1235772

Please sign in to comment.
You can’t perform that action at this time.