Skip to content

Commit

Permalink
add Makefile/sh based "build system"
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Mar 22, 2017
1 parent 59c2b43 commit dacdd0b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 151 deletions.
5 changes: 3 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Auto detect text files and perform LF normalization
* text=auto

.gitattributes export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
appveyor.yml export-ignore
appveyor.yml export-ignore
*.sh eol=lf
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ tests/misc/projects/Issue4070/cpp/

/tests/sys/temp
*.dll
_build/
Makefile.dependencies
Makefile.modules
Loading

2 comments on commit dacdd0b

@Simn
Copy link
Member Author

@Simn Simn commented on dacdd0b Mar 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna document what this is doing here. The first thing we do is copy all .ml files from the source directories to _build if they are newer (-u flag). At this point we also run compile.sh which re-generates lexer.ml, parser.ml and version.ml if they are newer than the target file.

The make process afterwards consists of 4 passes:

  1. Use ls to get a list of all .ml files in _build and write that list to Makefile.modules.
  2. Run ocamldep -sort to get an ordered list of these modules and strip the .ml extension using sed. Write the new result to Makefile.modules again.
  3. Run ocamldep on all module files and write the output to Makefile.dependencies.
  4. Run the compilation as previously, using Makefile.modules as a list of modules and Makefile.dependencies for the dependencies.

The main reason I'm multi-passing is that I couldn't find a way to pass information to ocamldep otherwise, as it doesn't seem to support reading stdin.

@pleclech
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
I sometimes have trouble to recompile haxe when i only modified some files , i have to do a clean_haxe and rebuild all.

To circumvent this i have created a rsync.sh that will indicate if there is dependencies to rebuild:
rsync.sh:

#!/bin/sh
DONE=$(rsync -iu ${1}/*.ml _build/${1})
if [ $? -eq 0 ]; then
    if [ -n "${DONE}" ]; then 
        echo 1 >_build/.mkdepends 
    fi
else
    exit 1
fi

and in Makefile i have deleted the pass_build and avoid the reentrant call:
makefile pass for haxe:

copy_output_files:
	mkdir -p _build
	$(foreach dir,$(HAXE_DIRECTORIES:%=src/%),mkdir -p _build/$(dir) && (sh rsync.sh $(dir)) &&) true
	sh compile.sh $(ADD_REVISION)
ifneq ($(ADD_REVISION),0)
	$(MAKE) -f Makefile.version_extra -s --no-print-directory ADD_REVISION=$(ADD_REVISION) BRANCH=$(BRANCH) COMMIT_SHA=$(COMMIT_SHA) COMMIT_DATE=$(COMMIT_DATE) > _build/src/compiler/version.ml
endif

_build/.mkdepends: copy_output_files

Makefile.modules: _build/.mkdepends
	$(eval MODULES= $(shell ls -1 $(HAXE_DIRECTORIES:%=_build/src/%/*.ml) | tr '\n' ' '))
	$(eval MODULES= $(shell ocamldep -sort -slash $(INCLUDES) $(MODULES) | sed -e "s/\.ml//g"))
	echo MODULES=$(MODULES) > $@

Makefile.dependencies: Makefile.modules
	ocamlfind ocamldep -slash -native $(HAXE_INCLUDES) $(MODULES:%=%.ml) > Makefile.dependencies

haxe: Makefile.dependencies $(MODULES:%=%.$(MODULE_EXT))
	$(COMPILER) -linkpkg -o $(OUTPUT) $(NATIVE_LIBS) $(NATIVE_LIB_FLAG) $(LFLAGS) $(FINDLIB_PACKAGES) $(EXTLIB_INCLUDES) $(EXTLIB_LIBS:=.$(LIB_EXT)) $(MODULES:%=%.$(MODULE_EXT))

Please sign in to comment.