Skip to content

Commit

Permalink
Fixes for MakeDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
nddrylliog committed Jun 2, 2010
1 parent ee8c662 commit 9f23951
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
13 changes: 9 additions & 4 deletions source/rock/backend/cnaughty/CGenerator.ooc
Expand Up @@ -32,10 +32,15 @@ CGenerator: class extends Skeleton {

init: func ~cgenerator (=params, =module) {

hOutPath := File new(params libcachePath + File separator + module getSourceFolderName(), module getPath(""))
hOutPath parent() mkdirs()
hw = AwesomeWriter new(this, CachedFileWriter new(hOutPath path + ".h"))
fw = AwesomeWriter new(this, CachedFileWriter new(hOutPath path + "-fwd.h"))
if (params libcache) {
hOutPath := File new(params libcachePath + File separator + module getSourceFolderName(), module getPath(""))
hOutPath parent() mkdirs()
hw = AwesomeWriter new(this, CachedFileWriter new(hOutPath path + ".h"))
fw = AwesomeWriter new(this, CachedFileWriter new(hOutPath path + "-fwd.h"))
} else {
hw = AwesomeWriter new(this, CachedFileWriter new(File new(params outPath path, module getPath(".h")) path))
fw = AwesomeWriter new(this, CachedFileWriter new(File new(params outPath path, module getPath("-fwd.h")) path))
}

cOutPath := File new(params outPath path, module getPath(".c"))
cOutPath parent() mkdirs()
Expand Down
1 change: 1 addition & 0 deletions source/rock/frontend/CommandLine.ooc
Expand Up @@ -345,6 +345,7 @@ CommandLine: class {
module := Module new(fullName, params sourcePath getElement(moduleName) path, params , nullToken)
module token = Token new(0, 0, module)
module main = true
module lastModified = moduleFile lastModified()

// phase 1: parse
AstBuilder new(modulePath, module, params)
Expand Down
44 changes: 22 additions & 22 deletions source/rock/frontend/drivers/MakeDriver.ooc
Expand Up @@ -17,6 +17,9 @@ MakeDriver: class extends SequenceDriver {
wasSetup := static false
if(wasSetup) return

// no lib-caching for the make driver!
params libcache = false

// build/
builddir = File new("build")

Expand All @@ -40,7 +43,9 @@ MakeDriver: class extends SequenceDriver {
setup()

params outPath mkdirs()
for(candidate in module collectDeps()) {

toCompile := module collectDeps()
for(candidate in toCompile) {
CGenerator new(params, candidate) write()
}

Expand Down Expand Up @@ -120,13 +125,10 @@ MakeDriver: class extends SequenceDriver {

fW write("OBJECT_FILES:=")

toCompile := collectDeps(module, HashMap<String, SourceFolder> new(), ArrayList<String> new())

for(sourceFolder in toCompile) {
for(currentModule in sourceFolder modules) {
path := File new(originalOutPath, currentModule getPath("")) getPath()
fW write(path). write(".o ")
}
for(currentModule in toCompile) {
printf("%p, %s\n", currentModule, currentModule fullName)
path := File new(originalOutPath, currentModule getPath("")) getPath()
fW write(path). write(".o ")
}

fW write("\n\n.PHONY: compile link\n\n")
Expand All @@ -141,20 +143,18 @@ MakeDriver: class extends SequenceDriver {

oPaths := ArrayList<String> new()

for(sourceFolder in toCompile) {
for(currentModule in sourceFolder modules) {
path := File new(originalOutPath, currentModule getPath("")) getPath()
oPath := path + ".o"
cPath := path + ".c"
oPaths add(oPath)

fW write(oPath). write(": ").
write(cPath). write(" ").
write(path). write(".h ").
write(path). write("-fwd.h\n")

fW write("\t${CC} ${CFLAGS} -c %s -o %s\n" format(cPath, oPath))
}
for(currentModule in toCompile) {
path := File new(originalOutPath, currentModule getPath("")) getPath()
oPath := path + ".o"
cPath := path + ".c"
oPaths add(oPath)

fW write(oPath). write(": ").
write(cPath). write(" ").
write(path). write(".h ").
write(path). write("-fwd.h\n")

fW write("\t${CC} ${CFLAGS} -c %s -o %s\n" format(cPath, oPath))
}

fW write("\nlink: ${OBJECT_FILES}\n")
Expand Down
6 changes: 3 additions & 3 deletions source/rock/frontend/drivers/SequenceDriver.ooc
Expand Up @@ -336,7 +336,7 @@ SequenceDriver: class extends Driver {
Collect all modules imported from `module`, sort them by SourceFolder,
put them in `toCompile`, and return it.
*/
collectDeps: func (module: Module, toCompile: HashMap<String, SourceFolder>, done: ArrayList<String>) -> HashMap<String, SourceFolder> {
collectDeps: func (module: Module, toCompile: HashMap<String, SourceFolder>, done: ArrayList<Module>) -> HashMap<String, SourceFolder> {

name := File new(File new(module getPathElement()) getAbsolutePath()) name()

Expand All @@ -347,10 +347,10 @@ SequenceDriver: class extends Driver {
}

sourceFolder modules add(module)
done add(module getPath())
done add(module)

for(import1 in module getAllImports()) {
if(done contains(import1 getModule() getPath())) continue
if(done contains(import1 getModule())) continue
collectDeps(import1 getModule(), toCompile, done)
}

Expand Down

0 comments on commit 9f23951

Please sign in to comment.