Skip to content

Instantly share code, notes, and snippets.

@rolandoam
Created March 19, 2013 19:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolandoam/5199237 to your computer and use it in GitHub Desktop.
Save rolandoam/5199237 to your computer and use it in GitHub Desktop.
makefile for both native and emscripten projects: make js # will make the js port, output a projectname.js make native # will compile the native port, output project.native make sure there are no important files named `project.*` because they will be cleaned by the `clean` target
EMSCRIPTEN_HOME = ~/Documents/inbox/emscripten
PROJECT = myproject
SOURCES = $(wildcard *.cc) $(wildcard *.c)
OBJECTS = $(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(SOURCES)))
set-native:
$(eval CXX := clang -x c++)
$(eval CC := clang)
$(eval CPPFLAGS := -g -O2 -DHAS_TR1)
$(eval CXXFLAGS := -std=c++11)
$(eval LDFLAGS := -lstdc++)
$(eval TARGET := native)
set-js:
$(eval CXX := $(EMSCRIPTEN_HOME)/em++)
$(eval CC := $(EMSCRIPTEN_HOME)/emcc)
$(eval CXXFLAGS := -std=c++11 -s ASM_JS=1)
$(eval LDFLAGS := -lc++ -O2)
$(eval TARGET := js)
compile: $(OBJECTS)
$(CC) $(LDFLAGS) $^ -o $(PROJECT).$(TARGET)
native: set-native compile
js: set-js compile
show-vars:
echo $(SOURCES)
echo $(OBJECTS)
clean:
rm -f *.o
rm -rf $(PROJECT).* *.dSYM
@isc30
Copy link

isc30 commented Nov 25, 2017

thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment