Skip to content
Permalink
Browse files

Modular make system, fix "make install" rule

  • Loading branch information
thp committed Jan 2, 2015
1 parent d9ad929 commit 0096c298407e1884dc8d7f4228a588594f20f085
Showing with 123 additions and 114 deletions.
  1. +1 −1 .gitignore
  2. +0 −5 external.in
  3. +9 −108 makefile
  4. +13 −0 mk/box2d.mk
  5. +5 −0 mk/deps.mk
  6. +18 −0 mk/funcs.mk
  7. +13 −0 mk/glaserl.mk
  8. +10 −0 mk/install.mk
  9. +10 −0 mk/main.in
  10. +2 −0 mk/objs.mk
  11. +4 −0 mk/pkgs.mk
  12. +7 −0 mk/rules.mk
  13. +7 −0 mk/silent.mk
  14. +11 −0 mk/top.mk
  15. +6 −0 mk/vars.mk
  16. +7 −0 platform/sdl2/platform.in
  17. 0 {data → tools}/icons.svg
  18. 0 {data → tools}/nph2npsvg.py
@@ -2,5 +2,5 @@
*.o
*.a
numptyphysics
external.mk
mk/main.mk
platform/*/platform.mk

This file was deleted.

117 makefile
@@ -1,123 +1,24 @@
APP := numptyphysics

APP = numptyphysics

DESTDIR ?=
PREFIX = /opt/numptyphysics

PLATFORM ?= sdl2

CXXFLAGS += -I. -Isrc -Wno-sign-compare
CXXFLAGS += -std=c++11 -Wall -DINSTALL_BASE_PATH=\"$(PREFIX)/data\"

GENERATED_MAKEFILES :=

ifeq ($(SILENT),0)
SILENTMSG := @true
SILENTCMD :=
else
SILENTMSG := @echo
SILENTCMD := @
endif

ifeq ($(V),1)
SILENTMSG := @true
SILENTCMD :=
endif

SOURCES = $(wildcard src/*.cpp)
SOURCES := $(wildcard src/*.cpp)
CXXFLAGS += -std=c++11 -Isrc -Wall -Wno-sign-compare

all: $(APP)

define add_pkgconfig
PKGS += $(1)
endef

define add_platform
CXXFLAGS += -Iplatform/$(1)
SOURCES += $(wildcard platform/$(1)/*.cpp)
endef

define add_external
CXXFLAGS += -Iexternal/$(1)
SOURCES += $(wildcard external/$(1)/*.cpp)
endef

define include_makefile
GENERATED_MAKEFILES += $(1)
-include $(1)
endef

%.mk: %.in
$(SILENTMSG) "\tSED\t$@"
$(SILENTCMD) sed -e 's/^\([^ ]*\)(\(.*\))$$/$$(eval $$(call \1,\2))/g' $< >$@ || rm -f $@

$(eval $(call add_platform,$(PLATFORM)))
$(eval $(call include_makefile,platform/$(PLATFORM)/platform.mk))
$(eval $(call include_makefile,external.mk))

UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
LIBS += -framework OpenGL
else
PKGS += gl
endif

CXXFLAGS += $(shell pkg-config --cflags $(PKGS))
LIBS += $(shell pkg-config --libs $(PKGS))

# Box2D Library
CXXFLAGS += -Iexternal/Box2D/Include
BOX2D_SOURCE := external/Box2D/Source
BOX2D_LIBRARY := Gen/float/libbox2d.a
LOCAL_LIBS += $(BOX2D_SOURCE)/$(BOX2D_LIBRARY)

$(BOX2D_SOURCE)/$(BOX2D_LIBRARY):
$(MAKE) -C $(BOX2D_SOURCE) $(BOX2D_LIBRARY)

# Glaserl Library
CXXFLAGS += -Iexternal/glaserl
GLASERL_SOURCE := external/glaserl
GLASERL_LIBRARY := libglaserl.a
LOCAL_LIBS += $(GLASERL_SOURCE)/$(GLASERL_LIBRARY)

$(GLASERL_SOURCE)/$(GLASERL_LIBRARY):
$(MAKE) -C $(GLASERL_SOURCE) $(GLASERL_LIBRARY)

LIBS += $(LOCAL_LIBS)

# Dependency tracking
DEPENDENCIES = $(SOURCES:.cpp=.d)
CXXFLAGS += -MD
-include $(DEPENDENCIES)

OBJECTS = $(SOURCES:.cpp=.o)
include mk/top.mk

$(APP): $(OBJECTS) $(LOCAL_LIBS)
$(SILENTMSG) "\tLD\t$@"
$(SILENTCMD) $(CXX) -o $@ $^ $(LIBS)

%.o: %.cpp
$(SILENTMSG) "\tCXX\t$@"
$(SILENTCMD) $(CXX) $(CXXFLAGS) -c -o $@ $<

clean:
clean: $(ADDITIONAL_CLEAN_TARGETS)
$(SILENTMSG) "\tCLEAN"
$(SILENTCMD) rm -f $(OBJECTS)
$(SILENTCMD) rm -f $(DEPENDENCIES)
$(SILENTCMD) $(RM) $(CLEAN_FILES)

distclean: clean
distclean: clean $(ADDITIONAL_DISTCLEAN_TARGETS)
$(SILENTMSG) "\tDISTCLEAN"
$(SILENTCMD) $(MAKE) -C $(BOX2D_SOURCE) clean
$(SILENTCMD) $(MAKE) -C $(GLASERL_SOURCE) distclean
$(SILENTCMD) rm -f $(APP)
$(SILENTCMD) rm -f $(GENERATED_MAKEFILES)

install: $(APP)
mkdir -p $(DESTDIR)/$(PREFIX)/bin
install -m 755 $(APP) $(DESTDIR)/$(PREFIX)/bin/
mkdir -p $(DESTDIR)/$(PREFIX)/data
cp -rpv data/*.png data/*.ttf $(DESTDIR)/$(PREFIX)/data/

$(SILENTCMD) $(RM) $(APP) $(GENERATED_MAKEFILES)
$(SILENTCMD) $(RM) $(DISTCLEAN_FILES)

.PHONY: all clean distclean
.DEFAULT: all
@@ -0,0 +1,13 @@
# Box2D Library
CXXFLAGS += -Iexternal/Box2D/Include
BOX2D_SOURCE := external/Box2D/Source
BOX2D_LIBRARY := Gen/float/libbox2d.a

LOCAL_LIBS += $(BOX2D_SOURCE)/$(BOX2D_LIBRARY)
$(BOX2D_SOURCE)/$(BOX2D_LIBRARY):
$(MAKE) -C $(BOX2D_SOURCE) $(BOX2D_LIBRARY)

ADDITIONAL_DISTCLEAN_TARGETS += box2d_distclean
box2d_distclean:
$(SILENTCMD) $(MAKE) -C $(BOX2D_SOURCE) clean
.PHONY: box2d_distclean
@@ -0,0 +1,5 @@
# Dependency tracking
DEPENDENCIES := $(SOURCES:.cpp=.d)
CXXFLAGS += -MD
-include $(DEPENDENCIES)
CLEAN_FILES += $(DEPENDENCIES)
@@ -0,0 +1,18 @@
define add_pkgconfig
PKGS += $(1)
endef

define add_platform
CXXFLAGS += -Iplatform/$(1)
SOURCES += $(wildcard platform/$(1)/*.cpp)
endef

define add_external
CXXFLAGS += -Iexternal/$(1)
SOURCES += $(wildcard external/$(1)/*.cpp)
endef

define include_makefile
GENERATED_MAKEFILES += $(1)
-include $(1)
endef
@@ -0,0 +1,13 @@
# Glaserl Library
CXXFLAGS += -Iexternal/glaserl
GLASERL_SOURCE := external/glaserl
GLASERL_LIBRARY := libglaserl.a

LOCAL_LIBS += $(GLASERL_SOURCE)/$(GLASERL_LIBRARY)
$(GLASERL_SOURCE)/$(GLASERL_LIBRARY):
$(MAKE) -C $(GLASERL_SOURCE) $(GLASERL_LIBRARY)

ADDITIONAL_DISTCLEAN_TARGETS += glaserl_distclean
glaserl_distclean:
$(SILENTCMD) $(MAKE) -C $(GLASERL_SOURCE) distclean
.PHONY: glaserl_distclean
@@ -0,0 +1,10 @@
DESTDIR ?=
PREFIX ?= /usr

install: $(APP)
mkdir -p $(DESTDIR)/$(PREFIX)/bin
install -m 755 $(APP) $(DESTDIR)/$(PREFIX)/bin/
mkdir -p $(DESTDIR)/$(PREFIX)/share/$(APP)
cp -rpv data $(DESTDIR)/$(PREFIX)/share/$(APP)/

.PHONY: install
@@ -0,0 +1,10 @@
PLATFORM ?= sdl2
add_platform($(PLATFORM))
include_makefile(platform/$(PLATFORM)/platform.mk)

add_external(thp)
add_external(tinyxml2)
add_external(slre)

include mk/box2d.mk
include mk/glaserl.mk
@@ -0,0 +1,2 @@
OBJECTS := $(SOURCES:.cpp=.o)
CLEAN_FILES += $(OBJECTS)
@@ -0,0 +1,4 @@
ifneq ($(PKGS),)
CXXFLAGS += $(shell pkg-config --cflags $(PKGS))
LIBS += $(shell pkg-config --libs $(PKGS))
endif
@@ -0,0 +1,7 @@
%.mk: %.in
$(SILENTMSG) "\tSED\t$@"
$(SILENTCMD) sed -e 's/^\([^( ]*\)(\(.*\))$$/$$(eval $$(call \1,\2))/g' $< >$@ || rm -f $@

%.o: %.cpp
$(SILENTMSG) "\tCXX\t$@"
$(SILENTCMD) $(CXX) $(CXXFLAGS) -c -o $@ $<
@@ -0,0 +1,7 @@
ifeq ($(V),1)
SILENTMSG := @true
SILENTCMD :=
else
SILENTMSG := @echo
SILENTCMD := @
endif
@@ -0,0 +1,11 @@
include mk/vars.mk
include mk/funcs.mk
include mk/silent.mk
include mk/rules.mk

$(eval $(call include_makefile,mk/main.mk))

include mk/pkgs.mk
include mk/deps.mk
include mk/objs.mk
include mk/install.mk
@@ -0,0 +1,6 @@
PKGS :=
GENERATED_MAKEFILES :=
ADDITIONAL_CLEAN_TARGETS :=
ADDITIONAL_DISTCLEAN_TARGETS :=
CLEAN_FILES :=
DISTCLEAN_FILES :=
@@ -8,3 +8,10 @@ add_pkgconfig(sdl2)
add_pkgconfig(SDL2_image)
add_pkgconfig(SDL2_ttf)
add_pkgconfig(gio-2.0)

# OpenGL library
ifeq ($(shell uname),Darwin)
LIBS += -framework OpenGL
else
add_pkgconfig(gl)
endif
File renamed without changes.
File renamed without changes.

0 comments on commit 0096c29

Please sign in to comment.