# # testExec # # To use, run the following commands: # make -f test.mk build # make -f test.mk debug # # .PHONY : generate_sources build clean run debug debug_tmp copy_tmp #---------------------------------- # sources #---------------------------------- NAME := test MACOS_VER := $(word 2,$(subst ., , $(shell sw_vers -productVersion))) ifeq (15,$(MACOS_VER)) EXEC_NAME := testCompiledOnCatalina else EXEC_NAME := testCompiledOnBigSur endif main.cpp : @echo "#include <stdio.h>" > $@ @echo "#include \"$(NAME).hpp\"" >> $@ @echo "int main() {" >> $@ @echo ' printMe();\n' >> $@; @echo "}\n" >> $@ $(NAME).hpp : @echo "#include <iostream>" > $@ @echo "void printMe();\n" >> $@ $(NAME).cpp : $(NAME).hpp @echo "#include \"$(NAME).hpp\"\n" > $@ @echo "void printMe() {" >> $@ @echo " std::cout << \"This is the most basic program ever\" << std::endl;\n" >> $@ @echo "}\n" >> $@ generate_sources : main.cpp $(NAME).hpp $(NAME).cpp #---------------------------------- # build #---------------------------------- CLANG := xcrun clang++ %.o : %.cpp @$(CLANG) -g -c $< lib$(NAME).dylib : $(NAME).o @$(CLANG) -dynamiclib -single_module -install_name @rpath/$@ -o $@ $< $(EXEC_NAME) : main.o lib$(NAME).dylib @$(CLANG) $< -o $@ -L. -l$(NAME) build : clean generate_sources $(EXEC_NAME) #---------------------------------- # run/debug #---------------------------------- run : @env DYLD_LIBRARY_PATH=./ ./$(EXEC_NAME) # $1 : exec path define RUN_DEBUG @echo "\nOnce lldb starts, run these commands:" @echo " (lldb) env DYLD_LIBRARY_PATH=./" @echo " (lldb) b printMe" @echo " (lldb) r\n" @echo "Starting debugger..." @xcrun lldb $(1) endef debug : $(if $(NOREBUILD),,clean build) $(call RUN_DEBUG,$(EXEC_NAME)) clean : @rm -f *.cpp *.hpp *.o *.dylib $(EXEC_NAME)