I have a simple C# program that needs to be run from the command line in Linux through mono. Here's what I have for my makefile so far. It's based off of a C++ makefile I found for another program. I tried modifying it to work with my C# program but it says certain source files could not be found.
.PHONY : build view clean
build : test
@# do nothing
test : test.o
gmcs test test.o
test.o : test.cs
gmcs test.cs
view :
@\less test.cs
clean :
-\rm *.exe
-\rm test
I've never worked with makefiles before so I don't really know what I'm doing wrong. There's only one file in my entire project and that's just test.cs. The final goal of this is to be able to run the program by typing in the command line:
./test
And it should clean up the .exe files generated too.
I put together a really simple Mono Makefile that works for me:
.PHONY: test.cs
all: run
test.exe: test.cs
@gmcs test.cs
clean:
@rm -f test.exe
run: test.exe
@mono test.exe
This has the nice property that if you just type 'make' it will re-compile and execute test.cs.
I'm using a pretty simple model of Makefile in my projects. (PS: I'm compiling using mono on GNU/Linux, but it is pretty easy to change the configurations (read my comments))
#change this to the name of the Main class file, without file extension
MAIN_FILE = App/Program
#change this to the depth of the project folders
#if needed, add a prefix for a common project folder
CSHARP_SOURCE_FILES = $(wildcard */*/*.cs */*.cs *.cs)
#add needed flags to the compilerCSHARP_FLAGS = -out:$(EXECUTABLE)
CSHARP_FLAGS = -out:$(EXECUTABLE)
#change to the environment compiler
CSHARP_COMPILER = mcs
#if needed, change the executable file
EXECUTABLE = $(MAIN_FILE).exe
#if needed, change the remove command according to your system
RM_CMD = -rm -f $(EXECUTABLE)
all: $(EXECUTABLE)
$(EXECUTABLE): $(CSHARP_SOURCE_FILES)
@ $(CSHARP_COMPILER) $(CSHARP_SOURCE_FILES) $(CSHARP_FLAGS)
@ echo compiling...
run: all
./$(EXECUTABLE)
clean:
@ $(RM_CMD)
remake:
@ $(MAKE) clean
@ $(MAKE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With