Skip to content

Commit

Permalink
[doc] Revise howto (#3222)
Browse files Browse the repository at this point in the history
Improve howto
  • Loading branch information
zomen2 authored Mar 19, 2021
1 parent e02baa7 commit 1eaf280
Show file tree
Hide file tree
Showing 6 changed files with 510 additions and 246 deletions.
31 changes: 31 additions & 0 deletions docs/examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
project_root_dir := $(strip $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))))

runnable := $(project_root_dir)/ccexample

include_dir := $(project_root_dir)/incl
object_dir := $(project_root_dir)/objs
source_dir := $(project_root_dir)/src
sources := $(wildcard $(source_dir)/*.c)
objects := $(patsubst $(source_dir)/%.c,$(object_dir)/%.c.o,$(sources))
depends := $(patsubst $(source_dir)/%.c,$(object_dir)/%.c.d,$(sources))

CFLAGS = -MMD -MP -g -std=c99 -Wall
CFLAGS += -I $(include_dir)

all: $(runnable)

$(runnable): $(objects)
$(CC) $(LINKFLAGS) $^ -o $@

$(objects): $(object_dir)/%.c.o: $(source_dir)/%.c
@mkdir --parents $(object_dir)
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

.PHONY: clean
clean:
rm --recursive --force $(object_dir)
rm --force $(runnable)

ifneq ($(filter clean,$(MAKECMDGOALS)),clean)
-include $(depends)
endif
6 changes: 6 additions & 0 deletions docs/examples/incl/divide.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef DIVIDE_H
#define DIVIDE_H

long divide(long numerator, long denominator);

#endif // DIVIDE_H
6 changes: 6 additions & 0 deletions docs/examples/src/divide.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "divide.h"

long divide(long numerator, long denominator)
{
return numerator / denominator;
}
24 changes: 24 additions & 0 deletions docs/examples/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "divide.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(int argc, char* argv[])
{
long result;
long test_case;

if(argc < 1) {
printf("Please specify testcase id.\n");
return 1;
}
if (strcmp(argv[1], "all")) {
test_case = strtol(argv[1], NULL, 10);
// Division by zero, only detected when ctu analysis is on
result = divide(test_case, 0);
}

return (int)result;
}
Binary file modified docs/images/static_html.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1eaf280

Please sign in to comment.