Skip to content

Commit

Permalink
Second round of makefile/build.d consolidation
Browse files Browse the repository at this point in the history
  • Loading branch information
marler8997 committed Jul 24, 2019
1 parent 52c0570 commit e4fedad
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 258 deletions.
73 changes: 58 additions & 15 deletions src/build.d
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ alias opTabGen = memoize!(function() {
});

/// Returns: the dependencies that build the D backend
alias dBackend = memoize!(function () {
alias backendObj = memoize!(function () {
Dependency dependency = {
name: "dbackend",
target: env["G"].buildPath("dbackend").objName,
name: "backendObj",
target: env["G"].buildPath("backend").objName,
sources: sources.backend,
msg: "(DC) D_BACK_OBJS %-(%s, %)".format(sources.backend.map!(e => e.baseName).array),
deps: [opTabGen],
Expand All @@ -289,9 +289,9 @@ alias backend = memoize!(function() {
Dependency dependency = {
name: "backend",
msg: "(LIB) %s".format("BACKEND".libName),
sources: [ env["G"].buildPath("dbackend").objName ],
sources: [ env["G"].buildPath("backend").objName ],
target: env["G"].buildPath("backend").libName,
deps: [opTabGen, dBackend],
deps: [opTabGen, backendObj],
command: [env["HOST_DMD_RUN"], env["MODEL_FLAG"], "-lib", "-of$@", "$<"]
};
return new DependencyRef(dependency);
Expand Down Expand Up @@ -397,6 +397,7 @@ alias clean = memoize!(function() {
return new DependencyRef(dependency);
});


/**
Goes through the target list and replaces short-hand targets with their expanded version.
Special targets:
Expand Down Expand Up @@ -521,6 +522,31 @@ struct DependencyRange
/// Sets the environment variables
void parseEnvironment()
{
// This block is temporary until we can remove the windows make files
{
const ddebug = env.get("DDEBUG", null);
if (ddebug.length)
{
writefln("WARNING: the DDEBUG variable is deprecated");
if (ddebug == "-debug -g -unittest -cov")
{
environment["ENABLE_DEBUG"] = "1";
environment["ENABLE_UNITTEST"] = "1";
environment["ENABLE_COVERAGE"] = "1";
}
else if (ddebug == "-debug -g -unittest")
{
environment["ENABLE_DEBUG"] = "1";
environment["ENABLE_UNITTEST"] = "1";
}
else
{
writefln("Error: DDEBUG is not an expected value '%s'", ddebug);
exit(1);
}
}
}

env.getDefault("TARGET_CPU", "X86");
version (Windows)
{
Expand Down Expand Up @@ -755,22 +781,39 @@ auto sourceFiles()
.map!(e => e.name)
.filter!(e => !lexerRootFiles.canFind(e.baseName.stripExtension))
.array,
backend:
dirEntries(env["C"], "*.d", SpanMode.shallow)
.map!(e => e.name)
.filter!(e => !e.baseName.among("dt.d", "obj.d", "optabgen.d"))
.array,
backendHeaders: [
// can't be built with -betterC
"dt",
"obj",
].map!(e => env["C"].buildPath(e ~ ".d")).array,
backend: ("
bcomplex.d evalu8.d divcoeff.d dvec.d go.d gsroa.d glocal.d gdag.d gother.d gflow.d
out.d
gloop.d compress.d cgelem.d cgcs.d ee.d cod4.d cod5.d nteh.d blockopt.d mem.d cg.d cgreg.d
dtype.d debugprint.d fp.d symbol.d elem.d dcode.d cgsched.d cg87.d cgxmm.d cgcod.d cod1.d cod2.d
cod3.d cv8.d dcgcv.d pdata.d util2.d var.d md5.d backconfig.d ph2.d drtlsym.d dwarfeh.d ptrntab.d
dvarstats.d dwarfdbginf.d cgen.d os.d goh.d barray.d cgcse.d elpicpie.d
".split
~ versionTernary!"OSX"(["machobj.d"], ["elfobj.d"])
~ versionTernary!"Windows"("cgobj.d filespec.d mscoffobj.d newman.d".split, ["aarray.d"])
).map!(e => env["C"].buildPath(e)).array,
backendHeaders: "
cc.d cdef.d cgcv.d code.d cv4.d dt.d el.d global.d
obj.d oper.d outbuf.d rtlsym.d code_x86.d iasm.d codebuilder.d
ty.d type.d exh.d mach.d mscoff.d dwarf.d dwarf2.d xmm.d
dlist.d melf.d varstats.di
".split.map!(e => env["C"].buildPath(e)).array,
};
sources.backend ~= ((env["OS"] == "windows" && env["MODEL"] == "64") ? ["strtold.d", "longdouble.d"] : [])
.map!(e => env["ROOT"].buildPath(e)).array;

sources.dmd = sources.frontend ~ sources.backendHeaders;

return sources;
}

/// Returns the first argument if the given version is true, otherwise, returns the second argument.
auto versionTernary(string version_, T)(T trueCase, T falseCase)
{
mixin("version(" ~ version_ ~ ") { return trueCase; }");
return falseCase;
}

/**
Downloads a file from a given URL
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/backend/cgobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,14 @@ int insidx(char *p,uint index)
mov ECX,p - [ESP] ;
}
else
asm
asm nothrow
{
naked ;
mov EAX,index - [ESP+4] ;
mov ECX,p - [ESP+4] ;
}

asm
asm nothrow
{
cmp EAX,0x7F ;
jae L1 ;
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/backend/util2.d
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ int binary(const(char)* p, const(char)* *table,int high)
version (X86asm)
{
alias len = high; // reuse parameter storage
asm
asm nothrow
{

// First find the length of the identifier.
Expand Down
49 changes: 4 additions & 45 deletions src/posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -338,21 +338,6 @@ GLUE_SRCS=$(addsuffix .d, $(addprefix $D/,irstate toctype glue gluelayer todt to

DMD_SRCS=$(FRONT_SRCS) $(GLUE_SRCS) $(BACK_HDRS)

BACK_DOBJS = bcomplex.o evalu8.o divcoeff.o dvec.o go.o gsroa.o glocal.o gdag.o gother.o gflow.o \
out.o \
gloop.o compress.o cgelem.o cgcs.o ee.o cod4.o cod5.o nteh.o blockopt.o mem.o cg.o cgreg.o \
dtype.o debugprint.o fp.o symbol.o elem.o dcode.o cgsched.o cg87.o cgxmm.o cgcod.o cod1.o cod2.o \
cod3.o cv8.o dcgcv.o pdata.o util2.o var.o md5.o backconfig.o ph2.o drtlsym.o dwarfeh.o ptrntab.o \
aarray.o dvarstats.o dwarfdbginf.o elfobj.o cgen.o os.o goh.o barray.o cgcse.o elpicpie.o

G_DOBJS = $(addprefix $G/, $(BACK_DOBJS))

ifeq (osx,$(OS))
BACK_DOBJS += machobj.o
else
# BACK_DOBJS += elfobj.o
endif

######## DMD glue layer and backend

GLUE_SRC = \
Expand Down Expand Up @@ -407,7 +392,7 @@ SRC_MAKE = posix.mak osmodel.mak

STRING_IMPORT_FILES = $G/VERSION $G/SYSCONFDIR.imp $(RES)/default_ddoc_theme.ddoc

DEPS = $(patsubst %.o,%.deps,$(DMD_OBJS) $(BACK_OBJS) $(BACK_DOBJS))
DEPS = $(patsubst %.o,%.deps,$(DMD_OBJS))

RUN_BUILD = $(GENERATED)/build HOST_DMD="$(HOST_DMD)" OS=$(OS) BUILD=$(BUILD) MODEL=$(MODEL) AUTO_BOOTSTRAP="$(AUTO_BOOTSTRAP)" --called-from-make

Expand Down Expand Up @@ -439,21 +424,13 @@ toolchain-info:
@echo '==== Toolchain Information ===='
@echo

$G/backend.a: $(G_DOBJS) $(SRC_MAKE)
$(AR) rcs $@ $(G_DOBJS)

$G/dmd_frontend: $(FRONT_SRCS) $D/gluelayer.d $(ROOT_SRCS) $G/lexer.a $(STRING_IMPORT_FILES) $(HOST_DMD_PATH)
$(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J$(RES) $(DFLAGS) $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH),$^) -version=NoBackend

ifdef ENABLE_LTO
$G/dmd: $(DMD_SRCS) $(ROOT_SRCS) $G/lexer.a $(G_DOBJS) $(STRING_IMPORT_FILES) $(HOST_DMD_PATH)
$G/dmd: $(DMD_SRCS) $(ROOT_SRCS) $G/lexer.a $G/backend.o $(STRING_IMPORT_FILES) $(HOST_DMD_PATH)
$(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J$(RES) $(DFLAGS) $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH),$^)
else
$G/dmd: $(DMD_SRCS) $(ROOT_SRCS) $G/backend.a $G/lexer.a $(STRING_IMPORT_FILES) $(HOST_DMD_PATH)
$(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J$(RES) $(DFLAGS) $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH) $(LEXER_ROOT),$^)
endif

$G/dmd-unittest: $(DMD_SRCS) $(ROOT_SRCS) $(LEXER_SRCS) $(G_DOBJS) $(STRING_IMPORT_FILES) $(HOST_DMD_PATH)
$G/dmd-unittest: $(DMD_SRCS) $(ROOT_SRCS) $(LEXER_SRCS) $G/backend.o $(STRING_IMPORT_FILES) $(HOST_DMD_PATH)
$(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J$(RES) $(DFLAGS) -g -unittest -main -version=NoMain $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH),$^)

unittest: $G/dmd-unittest
Expand All @@ -476,7 +453,6 @@ build-examples: $(EXAMPLES)

clean:
rm -Rf $(GENERATED)
rm -f $(addprefix $D/backend/, $(optabgen_output))
@[ ! -d ${PGO_DIR} ] || echo You should issue manually: rm -rf ${PGO_DIR}

######## Download and install the last dmd buildable without dmd
Expand Down Expand Up @@ -508,19 +484,6 @@ export DEFAULT_DMD_CONF
$G/dmd.conf: $(SRC_MAKE)
echo "$$DEFAULT_DMD_CONF" > $@

######## optabgen generates some source
optabgen_output = tytab.d

$G/optabgen: $C/optabgen.d $C/cc.d $C/oper.d $(HOST_DMD_PATH)
$(HOST_DMD_RUN) -of$@ $(DFLAGS) $(MODEL_FLAG) $(BACK_MV) $<
$G/optabgen
mv $(optabgen_output) $G

optabgen_files = $(addprefix $G/, $(optabgen_output))
$(optabgen_files): optabgen.out
.INTERMEDIATE: optabgen.out
optabgen.out : $G/optabgen

######## VERSION
########################################################################
# The version file should be updated on every build
Expand All @@ -546,10 +509,6 @@ FORCE: ;

-include $(DEPS)

$(G_DOBJS): $G/%.o: $C/%.d $(optabgen_files) posix.mak $(HOST_DMD_PATH)
@echo " (HOST_DMD_RUN) BACK_DOBJS $<"
$(HOST_DMD_RUN) -c -of$@ $(DFLAGS) $(MODEL_FLAG) $(BACK_BETTERC) $(BACK_DFLAGS) $<

################################################################################
# Generate the man pages
################################################################################
Expand Down Expand Up @@ -605,7 +564,7 @@ dscanner: $(DSCANNER_DIR)/dsc
$G/cxxfrontend.o: $G/%.o: tests/%.c $(SRC) $(ROOT_SRC) $(SRC_MAKE)
$(CXX) -c -o$@ $(CXXFLAGS) $(DMD_FLAGS) $(MMD) $<

$G/cxx-unittest: $G/cxxfrontend.o $(DMD_SRCS) $(ROOT_SRCS) $G/lexer.a $(G_DOBJS) $(STRING_IMPORT_FILES) $(HOST_DMD_PATH)
$G/cxx-unittest: $G/cxxfrontend.o $(DMD_SRCS) $(ROOT_SRCS) $G/lexer.a $G/backend.o $(STRING_IMPORT_FILES) $(HOST_DMD_PATH)
CC=$(HOST_CXX) $(HOST_DMD_RUN) -of$@ $(MODEL_FLAG) -vtls -J$G -J$(RES) -L-lstdc++ $(DFLAGS) -version=NoMain $(filter-out $(STRING_IMPORT_FILES) $(HOST_DMD_PATH),$^)

cxx-unittest: $G/cxx-unittest
Expand Down
Loading

0 comments on commit e4fedad

Please sign in to comment.