Skip to content

Instantly share code, notes, and snippets.

@ksf
Created June 5, 2010 16:33
Show Gist options
  • Save ksf/426753 to your computer and use it in GitHub Desktop.
Save ksf/426753 to your computer and use it in GitHub Desktop.
static. =
VERSION = $(if $(CheckProg git), $(shell git describe --tags --always), unknown)
FULLVERSION = $(VERSION) $(shell uname -m -o)
CXXFLAGS = -g3 -Wall -pedantic -pipe
CXXMM = $(CXX) $(CXXFLAGS) $(PREFIXED_INCLUDES) -MM # FIXME legacy: clean this
open OMakeconf
open OMakelib
.PHONY: cleanp clean
# .SUBDIRS:
# CXXFLAGS +=
# LDFLAGS +=
# INCLUDES +=
################################################
# Uncomment the following section if you want
# to build a C program in the current directory.
#
CProg(hello,main)
.DEFAULT: hello$(EXE)
CGeneratedFiles(version.h)
version.h: :value: $(FULLVERSION)
fprint( version.h, $"""$(AUTOGEN_WARNING)
#define VERSION "$(FULLVERSION)"
""")
cleanp:
git clean -xn
clean:
git clean -xf
@echo "!!! omake: remember to use omake -U on the next run"
# The heuristic couldn't be easier (to fool): If there's a .h file included that
# has a corresponding .cpp file, the main app depends on the resulting .o
ObjectDependencies(target) =
eprint( ---- $(addsuffix .o, $(target)): )
deps = $(shell $(CXXMM) $(addsuffix .cpp, $(target)))
deps = $(removesuffix $(filter %.h %.hpp, $(deps)))
deps = $(removesuffix $(filter-exists $(addsuffix .cpp, $(deps))))
eprintln( $(addsuffix .o, $(deps)) )
return $(deps)
ScanDependenciesI(target, acc) =
deps = $(ObjectDependencies $(target))
acc += $(target)
new = $(set-diff $(deps), $(acc))
acc += $(new)
foreach( n, $(new) )
acc = $(set $(ScanDependenciesI $n, $(acc)))
export
return $(acc)
ScanDependencies(target) =
eprintln( --- Generating object dependency tree for root $(target)... )
ret = $(set-diff $(ScanDependenciesI $(target), $(Sequence)), $(Sequence))
ret = $(addsuffix .o, $(ret))
eprintln( ----- $(target): $(ret))
return $(ret)
CProg(name, main) =
exe = $(name)$(EXE)
section
OMakeFlags( -s )
.SCANNER: $(exe): /.PHONY/CGeneratedFilesTarget :value: $(digest-in-path-optional $(INCLUDES), $&) :value: $(CXXMM)
println($(exe): $(string $(ScanDependencies $(main))))
$(exe): /.PHONY/CGeneratedFilesTarget
$(CXX) $(CXXFLAGS) $(LDOUT)$@ $(filter %.o, $(dependencies $(exe))) $(LDFLAGS)
AUTOGEN_WARNING = /* DO NOT EDIT: build-system autogenerated file */
open build/C
open build/LaTeX
DefineCommandVars()
.SUBDIRS: .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment