In Haxe, is there any script or command that can automatically run a Haxe program in multiple target languages? I'd like to write a script that does the following:
1) Compile Haxe source code to JavaScript, C++, PHP, and Java.
2) Display the output of the Haxe program in each target language.
You can do this with normal hxml, and a special js runtime that lets you output to the terminal. I'm using phantomjs, but other environments like node.js are possible.
Note that I need to add append a specific exit command in order for phantomjs to exit properly. See the phantomjs docs for more details. You'll also need to install hxjava and hxcpp from haxelib.
I'm using --next here to do multiple compilations in one pass. You can easily break this up into multiple hxml files, and manage it via a makefile, etc.
-main Main
-php php
-cmd echo "PHP:"
-cmd php php/index.php
-cmd echo "\n"
--next
-main Main
-js bin/Main.js
-cmd echo "phantom.exit();" >> bin/Main.js
-cmd echo "JS:"
-cmd phantomjs bin/Main.js
-cmd echo "\n"
--next
-main Main
-cpp cpp
-cmd echo "CPP:"
-cmd ./cpp/Main
-cmd echo "\n"
--next
-main Main
-java java
-cmd echo "JAVA:"
-cmd java -jar java/java.jar
-cmd echo "\n"
Related
My Haxe build has several targets and I have to manually c/p changes to each target. Can .hxml files handle variables?
No, but you can reduce duplication with --each and --next:
-main Example
-lib examplelib
--each
-neko bin/example.n
--next
-java bin/java
--next
-cpp bin/cpp32
-D HXCPP_M32
--next
-cpp bin/cpp64
-D HXCPP_M64
Well, the title pretty much says it all. I start up Qt Creator, I create a new project and click the plain C++ option. It creates the following code in the main.cpp file:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
I put a breakpoint on the line beginning with cout or return.
I set the project mode to debug.
I click the play button with the bug on it.
It doesn't stop at the breakpoint.
If I do the exact same thing but having created a Qt GUI Application, it works.
Help'd be much appreciated.
Thank you.
Oh yeah, if it makes any difference, I'm using the latest version of Linux Mint and from what I can tell, GCC and GDB are installed.
Edit: Here is the:
Compile Output:
23:27:37: Running build steps for project untitled2...
23:27:37: Starting: "/usr/bin/qmake-qt4" '/home/jean-luc/Desktop/untitled folder/untitled2/untitled2.pro' -r -spec linux-g++ CONFIG+=debug CONFIG+=declarative_debug
23:27:37: The process "/usr/bin/qmake-qt4" exited normally.
23:27:37: Starting: "/usr/bin/make" -w
make: Entering directory `/home/jean-luc/Desktop/untitled folder/untitled2-build-desktop-Qt_4_8_1_in_PATH__System__Debug'
g++ -c -pipe -g -Wall -W -DQT_WEBKIT -I/usr/share/qt4/mkspecs/linux-g++ -I../untitled2 -I../untitled2 -I. -o main.o ../untitled2/main.cpp
g++ -o untitled2 main.o
{ test -n "" && DESTDIR="" || DESTDIR=.; } && test $(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $DESTDIR" -ex quit 'untitled2' && test -f untitled2.gdb-index && objcopy --add-section '.gdb_index=untitled2.gdb-index' --set-section-flags '.gdb_index=readonly' 'untitled2' 'untitled2' && rm -f untitled2.gdb-index || true
make: Leaving directory `/home/jean-luc/Desktop/untitled folder/untitled2-build-desktop-Qt_4_8_1_in_PATH__System__Debug'
23:27:38: The process "/usr/bin/make" exited normally.
Application Output:
Debugging starts
Debugging has finished
Even though this is already a few days old, I'd like to add this resolution, as the problem described occasionally happens with Qt and Creator: Qt Creator has the nasty habit to suggest having the release and the debug objects in the same folder. So if you compile a release build, then decide to debug your program and make a debug build, it will link a debug application with release objects.
These objects cannot have a breakpoint set into. You need to clean the project completely, call qmake and make all in debug mode. Then you should be able to set breakpoints properly.
You can simply give cmake command cmake -DCMAKE_BUILD_TYPE=Debug
or
SET(CMAKE_BUILD_TYPE Debug) add this line to CMakeLists.txt and debug now. Breakpoints will get hit properly.
I'm trying to generalize a setup file by externally passing the version number. I want to be able to do this:
makensis myscript.nsi parameter=value
and then read the parameter within the script, so that using the same script I can generate differently versioned executables. I found this & this, but they seem to be for passing commandline parameters to the generated setup.exe. Is this possible, and how?
You can add symbols to the globally defined list from the command line using the /D switch:
makensis /DMyVersion="1.0.1" install.nsi
Then you can use them using the ${} syntax:
!ifdef MyVersion
StrCpy $Version "${MyInstallerName}"
!else
StrCpy $Version "1.0.0"
!endif
Also of possible interest is the GetVersion plugin discussed in this SO question: NSIS - put EXE version into name of installer
I would like to have the same Makefile for building on Linux and on Windows. I use the default GNU make on Linux and the mingw32-make (also GNU make) on Windows.
I want the Makefile to detect whether it operates on Windows or Linux.
For example make clean command on Windows looks like:
clean:
del $(DESTDIR_TARGET)
But on Linux:
clean:
rm $(DESTDIR_TARGET)
Also I would like to use different directory separator on Windows (\) and Linux (/).
It is possible to detect Windows operating system in Makefile?
PS: I do not want to emulate Linux on Windows (cygwin etc.)
There is similiar question: OS detecting makefile, but I didn't find the answer here.
I solved this by looking for an env variable that will only be set on windows.
ifdef OS
RM = del /Q
FixPath = $(subst /,\,$1)
else
ifeq ($(shell uname), Linux)
RM = rm -f
FixPath = $1
endif
endif
clean:
$(RM) $(call FixPath,objs/*)
Because %OS% is the type of windows, it should be set on all Windows computers but not on Linux.
The blocks then setups up variables for the different programs as well as a function for converting the forward slashes into backslashes.
You to have to use $(call FixPath,path) when you call an outside command (internal commands work fine). You could also use something like:
/ := /
and then
objs$(/)*
if you like that format better.
The SystemRoot trick didn't work for me on Windows XP but this did:
ifeq ($(OS),Windows_NT)
#Windows stuff
...
else
#Linux stuff
....
endif
You should probably use the $(RM) variable to remove some files.
Checking WINDIR or COMSPEC is case-sensitive. Instead, I came up
with the following solution, hope that helps someone someday:
# detect if running under unix by finding 'rm' in $PATH :
ifeq ($(wildcard $(addsuffix /rm,$(subst :, ,$(PATH)))),)
WINMODE=1
else
WINMODE=0
endif
ifeq ($(WINMODE),1)
# native windows setup :
UNLINK = del $(subst /,\,$(1))
CAT = type $(subst /,\,$(1))
else
# cross-compile setup :
UNLINK = $(RM) $(1)
CAT = cat $(1)
endif
I would like to have the same Makefile for building on Linux and on Windows.
Maybe you will like CMake
My projects almst always consist of:
Pairs of Foo.h and Foo.cpp
Some extra headers util.h etc.
What is the simplest way to write a makefile that
Runs
$CC -c foo.cpp
for each .cpp file, keeping a dependency to its coresponding .h file
Provides some way that I can manually add extra dependencies
Includes a linking step with my manuall set $LIBS variable.
I work with Linux(Ubuntu) and gcc/g++.
Please, just use automake. You'll get proper dependency tracking, makefiles that comply with the GNU Makefile Standards (e.g., make install does the correct thing and respects DESTDIR and prefix), the ability to check for system quirks as needed and support for building proper distribution tarballs.
This is a minimal configure.ac:
-*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.61])
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
AM_INIT_AUTOMAKE([foreign])
# Checks for programs.
AC_PROG_CXX
# Checks for libraries.
# Checks for header files.
# Checks for typedefs, structures, and compiler characteristics.
# Checks for library functions.
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
and a minimal Makefile.am:
## Process this file with automake to generate Makefile.in
bin_PROGRAMS = foo
foo_SOURCES = foo.cpp bar.h baz.h quux.cpp
Run autoreconf -i to generate the configure script, followed by ./configure and make.
Here is an excellent autotools tutorial.
How about this:
%.o: %.cpp %.h
$(CC) -c $< -o $#
# Some things have extra dependencies. (Headers like util.h are unlikely
# to change, but you can handle them this way if you really want to.)
#
# foo.o and bar.o both depend on baz.h
foo.o bar.o: baz.h
# foo.o also depends on gab.h and jig.h
foo.o: gab.h jig.h
# You will need a list of object files. You can build it by hand:
OBJ_FILES = foo.o bar.o snaz.o # and so on
# ...or just grab all the files in the source directory:
SOURCE_FILES = $(wildcard *.cpp)
OBJ_FILES = $(SOURCE_FILES:.cpp=.o)
# It is possible to get this from the environment, but not advisable.
LIBS = -lred -lblue
final-thing: $(OBJ_FILES)
$(CC) $(LIBS) $^ -o $#
Perhaps you can check out CMake?
If you're unfamiliar with CMake, it's basically a Makefile generator (or XCode, or Visual Studio Projects, etc, depending on platform), so it lets you specify just the variables you need, and takes care of header dependency issues for you, makefile generation, etc.
Here is a simple shell script that constructs a makefile from all .cpp files in a given directory:
# !sh
if [ $# = 0 ]
then
echo -e "please give executable name"
exit 1
fi
echo -e -n "CC=g++\nOPTIMS=\nLIBS= " > makefile
echo >> makefile
echo -n "$1: " >> makefile
for fic in *.cpp
do
echo -n "${fic%\.cpp}.o " >> makefile
done
echo >> makefile
echo -n -e "\t\$(CC) " >> makefile
for fic in *.cpp
do
echo -n "${fic%\.cpp}.o " >> makefile
done
echo -n -e "-o $1 \$(OPTIMS) \$(LIBS)\n" >> makefile
echo >> makefile
for fic in *.cpp
do
g++ -MM $fic >> makefile
echo -e "\t\$(CC) -c $fic \$(OPTIMS)\n" >> makefile
done
exit 0
It uses the -MM option of gcc for creating makefile dependency lines. Just create the script in the sources directory, (let's call it micmake), make it executable (chmod +x micmake) and type
./micmake go
It will create a makefile and the make command compile your project. The executable is named go. You can edit the makefile if you need special compilation options or libraries. For more complex projects and dependencies, you should use automake, cmake or scons.
start here simple makefile for gcc
Here is an example from one of my projects -- you can simply drop new pairs foo1.cc and foo1.h in there and they will automagically be built for you:
# determine all sources and from that all targets
sources := $(wildcard *.cpp)
programs := $(sources:.cpp=)
## compiler etc settings used in default make rules
CXX := g++
CPPFLAGS := -Wall
CXXFLAGS := -O3 -pipe
LDLIBS :=
# build all and strip programs afterwards
all: $(programs)
#test -x /usr/bin/strip && strip $^