From 35273c491b991cc4bb2d9e82e8a181c400e1d744 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Mon, 12 Apr 2021 08:24:27 +0200 Subject: [PATCH] Introduce generic variant targets Change Makefiles to allow multiple binary targets specified by VARIANT environment variabel. For specified variants a matching main-.c source file must be present. --- Makefile | 34 ++++++++++++---------------------- src/{core => }/allocate.c | 0 src/{core => }/atom.c | 0 src/{core => }/force.c | 0 src/{stub.c => main-stub.c} | 6 +++--- src/{core => }/neighbor.c | 0 src/{core => }/pbc.c | 0 src/{core => }/thermo.c | 0 src/{core => }/timing.c | 0 src/{core => }/util.c | 0 10 files changed, 15 insertions(+), 25 deletions(-) rename src/{core => }/allocate.c (100%) rename src/{core => }/atom.c (100%) rename src/{core => }/force.c (100%) rename src/{stub.c => main-stub.c} (98%) rename src/{core => }/neighbor.c (100%) rename src/{core => }/pbc.c (100%) rename src/{core => }/thermo.c (100%) rename src/{core => }/timing.c (100%) rename src/{core => }/util.c (100%) diff --git a/Makefile b/Makefile index c91a710..bc0e037 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,10 @@ #CONFIGURE BUILD SYSTEM +TARGET = MDBench-$(TAG) BUILD_DIR = ./$(TAG) -SRC_DIR = ./src/core +SRC_DIR = ./src MAKE_DIR = ./ Q ?= @ -TARGET_MDBENCH = MDBench-$(TAG) -TARGET_STUB = stub - #DO NOT EDIT BELOW include $(MAKE_DIR)/config.mk include $(MAKE_DIR)/include_$(TAG).mk @@ -23,31 +21,23 @@ endif VPATH = $(SRC_DIR) ASM = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.s,$(wildcard $(SRC_DIR)/*.c)) -OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c)) +OBJ = $(filter-out $(BUILD_DIR)/main%,$(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o,$(wildcard $(SRC_DIR)/*.c))) CPPFLAGS := $(CPPFLAGS) $(DEFINES) $(OPTIONS) $(INCLUDES) -all: ${TARGET_MDBENCH} ${TARGET_STUB} +ifneq ($(VARIANT),) + .DEFAULT_GOAL := ${TARGET}-$(VARIANT) +endif -${TARGET_MDBENCH}: $(BUILD_DIR) $(OBJ) $(BUILD_DIR)/main.o - @echo "===> LINKING $(TARGET_MDBENCH)" - $(Q)${LINKER} ${LFLAGS} -o $(TARGET_MDBENCH) $(OBJ) $(BUILD_DIR)/main.o $(LIBS) +${TARGET}: $(BUILD_DIR) $(OBJ) $(SRC_DIR)/main.c + @echo "===> LINKING $(TARGET)" + $(Q)${LINKER} $(CPPFLAGS) ${LFLAGS} -o $(TARGET) $(SRC_DIR)/main.c $(OBJ) $(LIBS) -${TARGET_STUB}: $(BUILD_DIR) $(OBJ) $(BUILD_DIR)/stub.o - @echo "===> LINKING $(TARGET_STUB)" - $(Q)${LINKER} ${LFLAGS} -o $(TARGET_STUB) $(OBJ) $(BUILD_DIR)/stub.o $(LIBS) +${TARGET}-%: $(BUILD_DIR) $(OBJ) $(SRC_DIR)/main-%.c + @echo "===> LINKING $(TARGET)-$* " + $(Q)${LINKER} $(CPPFLAGS) ${LFLAGS} -o $(TARGET)-$* $(SRC_DIR)/main-$*.c $(OBJ) $(LIBS) asm: $(BUILD_DIR) $(ASM) -$(BUILD_DIR)/main.o: ./src/main.c - @echo "===> COMPILE $@" - $(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - $(Q)$(CC) $(CPPFLAGS) -MT $(@:.d=.o) -MM $< > $(BUILD_DIR)/main.d - -$(BUILD_DIR)/stub.o: ./src/stub.c - @echo "===> COMPILE $@" - $(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ - $(Q)$(CC) $(CPPFLAGS) -MT $(@:.d=.o) -MM $< > $(BUILD_DIR)/stub.d - $(BUILD_DIR)/%.o: %.c @echo "===> COMPILE $@" $(Q)$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@ diff --git a/src/core/allocate.c b/src/allocate.c similarity index 100% rename from src/core/allocate.c rename to src/allocate.c diff --git a/src/core/atom.c b/src/atom.c similarity index 100% rename from src/core/atom.c rename to src/atom.c diff --git a/src/core/force.c b/src/force.c similarity index 100% rename from src/core/force.c rename to src/force.c diff --git a/src/stub.c b/src/main-stub.c similarity index 98% rename from src/stub.c rename to src/main-stub.c index c6f3c24..f2bf8fb 100644 --- a/src/stub.c +++ b/src/main-stub.c @@ -39,9 +39,9 @@ void init(Parameter *param) { } // Show debug messages -//#define DEBUG printf +//#define DEBUG(msg) printf(msg) // Do not show debug messages -#define DEBUG +#define DEBUG(msg) #define ADD_ATOM(x, y, z, vx, vy, vz) atom_x(atom->Nlocal) = base_x + x * NEIGH_DISTANCE; \ atom_y(atom->Nlocal) = base_y + y * NEIGH_DISTANCE; \ @@ -49,7 +49,7 @@ void init(Parameter *param) { atom->vx[atom->Nlocal] = vy; \ atom->vy[atom->Nlocal] = vy; \ atom->vz[atom->Nlocal] = vz; \ - atom->Nlocal++ + atom->Nlocal++ int main(int argc, const char *argv[]) { Atom atom_data; diff --git a/src/core/neighbor.c b/src/neighbor.c similarity index 100% rename from src/core/neighbor.c rename to src/neighbor.c diff --git a/src/core/pbc.c b/src/pbc.c similarity index 100% rename from src/core/pbc.c rename to src/pbc.c diff --git a/src/core/thermo.c b/src/thermo.c similarity index 100% rename from src/core/thermo.c rename to src/thermo.c diff --git a/src/core/timing.c b/src/timing.c similarity index 100% rename from src/core/timing.c rename to src/timing.c diff --git a/src/core/util.c b/src/util.c similarity index 100% rename from src/core/util.c rename to src/util.c