Created
November 18, 2012 05:58
-
-
Save hishidama/4103821 to your computer and use it in GitHub Desktop.
Cutter makefile example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "example.h" | |
int add(int m, int n) | |
{ | |
return m + n; | |
} | |
int sub(int m, int n) | |
{ | |
return m - n; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int add(int m, int n); | |
int sub(int m, int n); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include "example.h" | |
int main(int argc, char *argv[]) | |
{ | |
if (argc < 3) { | |
fprintf(stderr, "usage: %s m n\n", argv[0]); | |
return -1; | |
} | |
int m = atoi(argv[1]); | |
int n = atoi(argv[2]); | |
printf("add: %d\n", add(m, n)); | |
printf("sub: %d\n", sub(m, n)); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.ne.jp/asahi/hishidama/home/tech/c/cutter.html | |
SRC_DIR=src | |
TEST_DIR=test | |
LIB_DIR=lib | |
TEST_LIB_DIR=test-lib | |
TARGET=example.out | |
HEADERS=${wildcard $(SRC_DIR)/*.h} | |
SRCS=${wildcard $(SRC_DIR)/*.c} | |
OBJS=$(SRCS:$(SRC_DIR)/%.c=$(LIB_DIR)/%.o) | |
TEST_TARGET=$(TEST_LIB_DIR)/example.so | |
TEST_SRCS=${wildcard $(TEST_DIR)/*.c} | |
TEST_OBJS=$(TEST_SRCS:$(TEST_DIR)/%.c=$(TEST_LIB_DIR)/%.o) | |
CUTTER_FLAGS=${shell pkg-config --cflags cutter} | |
CUTTER_LIBS =${shell pkg-config --libs cutter} | |
all: $(TARGET) $(TEST_TARGET) | |
test: $(TEST_TARGET) | |
run-test: $(TEST_TARGET) | |
cutter $(TEST_LIB_DIR) | |
$(TARGET): $(OBJS) | |
gcc $(OBJS) -o $@ | |
$(LIB_DIR)/%.o: $(SRC_DIR)/%.c $(HEADERS) | |
gcc -O -fPIC -c $< -o $@ | |
$(TEST_TARGET): $(TEST_OBJS) $(OBJS) | |
gcc -shared $(TEST_OBJS) $(OBJS) $(CUTTER_LIBS) -o $@ | |
$(TEST_LIB_DIR)/%.o: $(TEST_DIR)/%.c $(HEADERS) | |
gcc -O -fPIC -c $< -I$(SRC_DIR) $(CUTTER_FLAGS) -o $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "example.h" | |
#include <cutter.h> | |
void test_add(void) | |
{ | |
cut_assert_equal_int(3, add(1, 2), cut_message("m=%d, n=%d", 1, 2)); | |
} | |
void test_sub(void) | |
{ | |
cut_assert_equal_int(-1, sub(1, 2)); | |
} | |
/* | |
void test_fork(void) | |
{ | |
pid_t pid = fork(); | |
if (pid < 0) { | |
perror("fork"); exit(-1); | |
} else if (pid == 0) { | |
// 子プロセス | |
cut_assert_equal_int(0, pid); | |
} else { | |
// 親プロセス | |
cut_assert_not_equal_int(0, pid); | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment