Fancy general Makefile

This commit is contained in:
Thomas Applencourt 2017-03-17 15:27:31 -05:00
parent ea5fa02b26
commit eb176ec0a2
3 changed files with 116 additions and 67 deletions

View File

@ -1,21 +1,22 @@
IRPF90= ../bin/irpf90
IRPF90FLAGS=
# Make | Ninja
BUILD_SYSTEM= make
.EXPORT_ALL_VARIABLES:
AR = ar
CC = gcc
CFLAGS = -O2
CXX = g++
CXXFLAGS = -O2
FC = gfortran
FCFLAGS = -O2
LIB =
RANLIB = ranlib
OBJ =
SRC =
OBJ =
# Compiler ! Will be overwriten by the ENV one if avalaible.
FC ?= gfortran-6
FCFLAGS ?= -O2
CC ?= gcc
CFLAGS ?= -O2
CXX ?= g++
CXXFLAGS ?= -O2
# Dark magic below modify with caution!
# "You are Not Expected to Understand This"
@ -32,38 +33,44 @@ SRC =
# | | I _________
# | | I c(` ')o
# | l I \. ,/
# _/j L l\_! _//^---^\\_
# _/j L l\_! _//
#Misc
AR ?=
RANLIB ?=
# Variable need by IRPF90
ifeq ($(BUILD_SYSTEM),ninja)
BUILD_FILE=IRPF90_temp/build.ninja
IRPF90FLAGS += -j
BUILD_FILE=IRPF90_temp/build.ninja
IRPF90FLAGS += -j
else ifeq ($(BUILD_SYSTEM),make)
BUILD_FILE=IRPF90_temp/build.make
BUILD_SYSTEM += -j
BUILD_FILE=IRPF90_temp/build.make
BUILD_SYSTEM += -j
else
DUMMY:
$(error 'Wrong BUILD_SYSTEM: $(BUILD_SYSTEM)')
endif
define run_and_touch
$(BUILD_SYSTEM) -C $(dir $(1) ) -f $(notdir $(1) ) $(addprefix $(CURDIR)/, $(2)) && touch $(2)
endef
# Actual Rule
EXE := $(shell egrep -ri '^\s*program' *.irp.f | cut -d'.' -f1)
.PHONY: all
.PHONY: clean all
all: $(BUILD_FILE)
$(call run_and_touch, $<, $(EXE))
all: $(EXE)
.NOTPARALLEL: $(EXE)
$(EXE): $(BUILD_FILE)
$(call run_and_touch, $<, $(EXE))
@printf "%b" "\033[0;32m Build $@...\033[m\n"
@$(BUILD_SYSTEM) -C $(dir $< ) -f $(notdir $< ) $(addprefix $(CURDIR)/, $@) && touch $@
.NOTPARALLEL: $(BUILD_FILE)
$(BUILD_FILE): $(shell find . -maxdepth 2 -path ./IRPF90_temp -prune -o -name '*.irp.f' -print)
$(IRPF90) $(IRPF90FLAGS)
@printf "%b" "\033[0;32m Running the IRPF90-compiler...\033[m\n"
@$(IRPF90) $(IRPF90FLAGS)
clean:
rm -f -- $(BUILD_FILE) $(EXE) $(shell find IRPF90_temp -type f \( -name "*.o" -o -name "*.mod" -name "*.a" \) -delete;)
rm -f -- $(BUILD_FILE) $(EXE)
veryclean: clean
rm -rf IRPF90_temp/ IRPF90_man/ irpf90_entities dist tags

View File

@ -282,49 +282,15 @@ def create_build_remaining(f, ninja):
def create_makefile(d_flags, d_var, irpf90_flags, ninja=True):
result = [
"IRPF90= irpf90", "IRPF90FLAGS= %s" % irpf90_flags,
"BUILD_SYSTEM= %s" % ('ninja' if ninja else 'make'), ""
]
# Export all the env variable used by irpf90
result += [
'.EXPORT_ALL_VARIABLES:', '', '\n'.join("{0} = {1}".format(k, v)
for k, v in sorted(d_flags.iteritems())), '',
'\n'.join("{0} = {1}".format(k, ' '.join(v)) for k, v in sorted(d_var.iteritems())), ''
]
result += [
r'# Dark magic below modify with caution!', r'# "You are Not Expected to Understand This"',
r"# .", r"# /^\ .", r'# /\ "V",',
r"# /__\ I O o", r"# //..\\ I .", r"# \].`[/ I",
r"# /l\/j\ (] . O", r"# /. ~~ ,\/I .", r"# \\L__j^\/I o",
r"# \/--v} I o .", r"# | | I _________", r"# | | I c(` ')o",
r"# | l I \. ,/", r"# _/j L l\_! _//^---^\\_", r""
]
result += [
"", "ifeq ($(BUILD_SYSTEM),ninja)", "\tBUILD_FILE=IRPF90_temp/build.ninja",
"\tIRPF90FLAGS += -j", "else ifeq ($(BUILD_SYSTEM),make)",
"\tBUILD_FILE=IRPF90_temp/build.make", "\tBUILD_SYSTEM += -j", "else", "DUMMY:",
"\t$(error 'Wrong BUILD_SYSTEM: $(BUILD_SYSTEM)')", "endif"
]
result += [
"", "define run_and_touch",
" $(BUILD_SYSTEM) -C $(dir $(1) ) -f $(notdir $(1) ) $(addprefix $(CURDIR)/, $(2)) && touch $(2)",
"endef", "", "EXE := $(shell egrep -ri '^\s*program' *.irp.f | cut -d'.' -f1)", "",
".PHONY: all", "", "all: $(BUILD_FILE)", "\t$(call run_and_touch, $<, $(EXE))", "",
".NOTPARALLEL: $(EXE)", "$(EXE): $(BUILD_FILE)", "\t$(call run_and_touch, $<, $(EXE))",
"$(BUILD_FILE): $(shell find . -maxdepth 2 -path ./IRPF90_temp -prune -o -name '*.irp.f' -print)",
"\t$(IRPF90) $(IRPF90FLAGS)", "", "clean:", '\trm -f -- $(BUILD_FILE) $(EXE)'
'\t$(shell find IRPF90_temp -type f \\( -name "*.o" -o -name "*.mod" -name "*.a" \\) -delete;)',
"veryclean: clean", "\trm -rf IRPF90_temp/ IRPF90_man/ irpf90_entities dist tags"
]
d = {'BUILD_SYSTEM': 'ninja' if ninja else 'make',
'irpf90_flags': irpf90_flags}
d.update(d_flags)
d.update(d_var)
import util
data = '%s\n' % '\n'.join(result)
util.lazy_write_file('Makefile', data, conservative=True)
str_ = util.ashes_env.render('general.make', d)
util.lazy_write_file('Makefile', str_, conservative=True)
def create_make_all_clean(l_main):

View File

@ -0,0 +1,76 @@
IRPF90= irpf90
IRPF90FLAGS= {irpf90_flags}
# Make | Ninja
BUILD_SYSTEM= {BUILD_SYSTEM}
.EXPORT_ALL_VARIABLES:
LIB = {LIB}
SRC = {SRC}
OBJ = {OBJ}
# Compiler ! Will be overwriten by the ENV one if avalaible.
FC ?= {FC}
FCFLAGS ?= {FCFLAGS}
CC ?= {CC}
CFLAGS ?= {CFLAGS}
CXX ?= {CXX}
CXXFLAGS ?= {CXXFLAGS}
# Dark magic below modify with caution!
# "You are Not Expected to Understand This"
# .
# /^\ .
# /\ "V",
# /__\ I O o
# //..\\ I .
# \].`[/ I
# /l\/j\ (] . O
# /. ~~ ,\/I .
# \\L__j^\/I o
# \/--v} I o .
# | | I _________
# | | I c(` ')o
# | l I \. ,/
# _/j L l\_! _//
#Misc
AR ?= {ar}
RANLIB ?= {ranlib}
# Variable need by IRPF90
ifeq ($(BUILD_SYSTEM),ninja)
BUILD_FILE=IRPF90_temp/build.ninja
IRPF90FLAGS += -j
else ifeq ($(BUILD_SYSTEM),make)
BUILD_FILE=IRPF90_temp/build.make
BUILD_SYSTEM += -j
else
DUMMY:
$(error 'Wrong BUILD_SYSTEM: $(BUILD_SYSTEM)')
endif
# Actual Rule
EXE := $(shell egrep -ri '^\s*program' *.irp.f | cut -d'.' -f1)
.PHONY: clean all
all: $(EXE)
$(EXE): $(BUILD_FILE)
@printf "%b" "\033[0;32m Build $@...\033[m\n"
@$(BUILD_SYSTEM) -C $(dir $< ) -f $(notdir $< ) $(addprefix $(CURDIR)/, $@) && touch $@
.NOTPARALLEL: $(BUILD_FILE)
$(BUILD_FILE): $(shell find . -maxdepth 2 -path ./IRPF90_temp -prune -o -name '*.irp.f' -print)
@printf "%b" "\033[0;32m Running the IRPF90-compiler...\033[m\n"
@$(IRPF90) $(IRPF90FLAGS)
clean:
rm -f -- $(BUILD_FILE) $(EXE)
veryclean: clean
rm -rf IRPF90_temp/ IRPF90_man/ irpf90_entities dist tags