Skip to content

Instantly share code, notes, and snippets.

@osvein
Created November 23, 2017 18:44
Show Gist options
  • Select an option

  • Save osvein/7075ea75de6e07097f07d46eb0a8d06f to your computer and use it in GitHub Desktop.

Select an option

Save osvein/7075ea75de6e07097f07d46eb0a8d06f to your computer and use it in GitHub Desktop.
export PROJECTFILE ?= $(realpath Project)
CHILDREN ?= $(sort $(dir $(wildcard */Makefile.custom) $(wildcard */Makefile)))
CHILDCARD ::= $(addsuffix %,$(CHILDREN))
%: $(CHILDCARD)
$(CHILDCARD):
dir = ${$@%%/*}
cd $dir
reltarget = ${$@#*/}
( test -f Makefile.custom\
&& $(MAKE) $dir -f Makefile.custom $reltarget )\
|| $(MAKE) $dir $reltarget
include $(PROJECTFILE)
PSC = PapyrusCompiler.exe
PAS = PapyrusAssembler.exe
SOURCES.psc = $(wildcard *.psc)
SOURCES.pas = $(wildcard *.pas)
SOURCES = $(SOURCES.psc) $(SOURCES.pas)
OBJECTS.psc = $(SOURCES.psc:.psc=.pex)
OBJECTS.pas = $(SOURCES.pas:.pas=.pex)
OBJECTS = $(OBJECTS.psc) $(OBJECTS.pas)
all:: $(OBJECTS)
#TODO: in the future, scripts will be compiled as prerequisites of a .esp
#TODO: automatic prerequisite generation (make depend)
.SUFFIXES: .psc .pas .pex
.psc.pex:
$(PSC) $* $(PSCFLAGS)
.psc.pas:
$(PSC) $* $(PSCFLAGS) -asmonly
.pas.pex:
$(PAS) $* $(PASFLAGS)
#.pex.pas:
# $(PAS) $* $(PASFLAGS) -D
include $(PROJECTFILE)
#TODO: clean pas files?
clean::
rm -r *.pex
.PHONY: all clean
.DEFAULT all clean::
( test -f ../Makefile.custom\
&& $(MAKE) -f ../Makefile.custom $@ )\
|| $(MAKE) -f ../Makefile $@
SOURCES.c = $(wildcard *.c)
SOURCES.C = $(wildcard *.C)
SOURCES.cc = $(wildcard *.cc)
SOURCES.cpp = $(wildcard *.cpp)
SOURCES = SOURCES.c SOURCES.C SOURCES.cc SOURCES.cpp
OBJECTS.c = $(SOURCES.c:.c=.o)
OBJECTS.C = $(SOURCES.C:.C=.o)
OBJECTS.cc = $(SOURCES.cc:.cc=.o)
OBJECTS.cpp = $(SOURCES.cpp:.cpp=.o)
OBJECTS = OBJECTS.c OBJECTS.C OBJECTS.cc OBJECTS.cpp
DEPENDS = $(OBJECTS:.o=.d)
# is the makefile running from its own directory?
ifeq ($(realpath $(CURDIR)), $(realpath $(dir $(lastword $(MAKEFILE_LIST)))))
$(MOD_NAME).dll: $(OBJECTS)
endif
%.dll:
$(LINK.o) -shared $^ $(LOADLIBES) $(LDLIBS) -o $@
depends:: $(DEPENDS) # for implementations that don't support remaking makefiles
DEPFLAGS = -MM -MG -MQ $*".o "$@ -MF $@
.SUFFIXES: .d
.c.d:
$(LINK.c) $(DEPFLAGS) $<
.cc.d:
$(LINK.cc) $(DEPFLAGS) $<
.C.d:
$(LINK.C) $(DEPFLAGS) $<
.cpp.d:
$(LINK.cpp) $(DEPFLAGS) $<
clean::
rm *.d *.o *.dll
include $(PROJECTFILE)
include $(DEPENDS)
.PHONY: depends clean
.DEFAULT depends clean::
( test -f ../Makefile.custom\
&& $(MAKE) -f ../Makefile.custom $@ )\
|| $(MAKE) -f ../Makefile $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment