# Template makefile from $PTII/ptolemy/cg/kernel/generic/program/procedural/c/makefile.in # $Id: makefile.in 69028 2014-04-26 00:10:17Z cxh $ # The CodeGenerator class subsitutes strings like "@modelName@" with # the value of parameters and writes the results in the directory # where the source code is created. # # To use your _own_ makefile, create a makefile named "ModelName.mk.in". # For example, if the model is called Foo, then the code generator # looks for a makefile template file called "Foo.mk.in" and then # looks for $PTII/ptolemy/codegen/c/makefile.in. # # To compile using this makefile after substitution, run: # make -f @modelName@.mk PTCGLIBRARIES = @PTCGLibraries@ PTCGINCLUDES = @PTCGIncludes@ PTCG_CFILES = @PTCG_CFILES@ PTCG_OFILES = @PTCG_OFILES@ # Under Windows, to create a binary that does not pop up a console window, # compile with: make -f @modelName@.mk CC_FLAGS=-mwindows CC_FLAGS= # If the user would like to add compile time options, run with # make -f @modelName@.mk USER_CC_FLAGS=xxx USER_CC_FLAGS = -std=c99 # We use -ggdb because -g fails with very large .c files DEBUG = -ggdb # Flags for warnings # Use -Wall so we have better code. WARNING_CC_FLAGS = -Wall # To compile very large C files, try: # make -f @modelName@.mk WARNING_CC_FLAGS= USER_CC_FLAGS="-pipe -O0 --verbose -Q" # Each of the options above: # No -Wall: avoid any optimization # -pipe: avoid temporary files # -O0: avoid optimization # --verbose: print out steps # -Q: print out what functions are being compiled and timing stats. # We need -lm so we can get floor() for ftoi() # We need -D__int64="long long" when invoking jni interface under cygwin @modelName@: @modelName@_Main.c $(PTCG_CFILES) @PTCGCompiler@ -D__int64="long long" $(WARNING_CC_FLAGS) $(CC_FLAGS) $(USER_CC_FLAGS) $(DEBUG) $(PTCGINCLUDES) $^ -o @modelName@ -lm $(PTCGLIBRARIES) # Each subdirectory must supply rules for building sources it contributes ./build/%.o: ./src/%.c gcc $(WARNING_CC_FLAGS) $(CC_FLAGS) $(USER_CC_FLAGS) $(DEBUG) -c -o "$@" "$<" run: @modelName@ ./@modelName@ # Rule to compile with different optimizers O_FLAGS=-O0 -O -Os -O2 -O3 optimize: for O_FLAG in $(O_FLAGS); do \ echo "Compiling with $$O_FLAG"; \ time @PTCGCompiler@ $$O_FLAG -D__int64="long long" $(CC_FLAGS) $(USER_CC_FLAGS) $(DEBUG) @modelName@.c $(PTCGINCLUDES) -o @modelName@_$$O_FLAG -lm $(PTCGLIBRARIES); \ cp @modelName@_$${O_FLAG}.exe @modelName@_$${O_FLAG}_stripped.exe; \ strip @modelName@_$${O_FLAG}_stripped.exe; \ ls -l @modelName@_$${O_FLAG}.exe @modelName@_$${O_FLAG}_stripped.exe; \ echo "Running @modelName@_$${O_FLAG}.exe"; \ time ./@modelName@_$${O_FLAG}.exe; \ time ./@modelName@_$${O_FLAG}.exe; \ time ./@modelName@_$${O_FLAG}.exe; \ echo "Running @modelName@_$${O_FLAG}_stripped.exe"; \ time ./@modelName@_$${O_FLAG}_stripped.exe; \ time ./@modelName@_$${O_FLAG}_stripped.exe; \ time ./@modelName@_$${O_FLAG}_stripped.exe; \ done # Generate code coverage using gcov. # Under Mac OS X, to use gcov, use clang instead of gcc. # Use gcc --version to check that gcc is really gcc and not llvm-gcc. coverage: rm -f @modelName@ @modelName@.exe make -f @modelName@.mk USER_CC_FLAGS="-fprofile-arcs -ftest-coverage" ./@modelName@ #gcov @modelName@.c # Other Targets clean: rm -rf $(PTCG_OFILES) @modelName@ -@echo ' ' .PHONY: all clean dependents .SECONDARY: