Skip to content

Instantly share code, notes, and snippets.

@schuberty
Created April 15, 2021 21:47
Show Gist options
  • Save schuberty/1a3096fd6302ea509e6a55ec5f7d5c68 to your computer and use it in GitHub Desktop.
Save schuberty/1a3096fd6302ea509e6a55ec5f7d5c68 to your computer and use it in GitHub Desktop.
Makefile for
# Makefile used for building C-Fortran program.
CC = gcc
GC = gfortran
CFLAGS = -Wall -g
OBJ = ./objs/
SRC = ./src/
NAME = "Project Name"
# Method used to differ from Windows or Linux.
ifdef OS
RM = del /Q
BIN = $(NAME).exe
FixPath = $(subst /,\,$1)
else
ifeq ($(shell uname), Linux)
RM = rm -f
BIN = $(NAME)
FixPath = $1
endif
endif
.PHONY: clean
all: $(OBJ)main.o $(OBJ)algorithms.o $(OBJ)searcher.o
@ $(GC) $(OBJ)main.o $(OBJ)algorithms.o $(OBJ)searcher.o -o $(NAME)
@ echo Finished building binary: $(BIN)
$(OBJ)main.o: $(SRC)/main.c
@ $(CC) -o $(OBJ)main.o -c $(SRC)main.c
$(OBJ)algorithms.o: $(SRC)algorithms.c
@ $(CC) -o $(OBJ)algorithms.o -c $(SRC)algorithms.c
$(OBJ)searcher.o: $(SRC)searcher.f90
@ $(GC) -o $(OBJ)searcher.o -c $(SRC)searcher.f90
clean:
@ $(RM) $(call FixPath,$(OBJ)*.o) $(BIN)
run: $(BIN)
@ echo Running $(BIN) with Test 1 input file.
@ ./$(BIN) test1.in
@ echo Running $(BIN) with Test 2 input file.
@ ./$(BIN) test2.in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment