From 175418ab356b88a7d175deb372e1c00c29c37c16 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sat, 29 Jun 2024 17:05:13 +0200 Subject: [PATCH] New Makefile and project restructuration --- Makefile | 164 ++++------------ .../dimers random walk.xml | 0 automaton.h => include/automaton.h | 0 base.h => include/base.h | 0 callback.h => include/callback.h | 0 contain.h => include/contain.h | 0 dialog.h => include/dialog.h | 0 display.h => include/display.h | 0 graph_area.h => include/graph_area.h | 0 graphics.h => include/graphics.h | 0 parsing.h => include/parsing.h | 0 texts.h => include/texts.h | 0 tree.h => include/tree.h | 0 init.c.todo | 175 ------------------ automaton.c => src/automaton.c | 2 +- callback.c => src/callback.c | 0 contain.c => src/contain.c | 0 dialog.c => src/dialog.c | 0 display.c => src/display.c | 0 draw.c => src/draw.c | 0 graph_area.c => src/graph_area.c | 0 graph_stack.c => src/graph_stack.c | 0 grid.c => src/grid.c | 0 init.c => src/init.c | 0 src/main.c | 26 +++ parsing.c => src/parsing.c | 0 shader.frag => src/shader.frag | 0 shader.vert => src/shader.vert | 0 texts.c => src/texts.c | 0 tree.c => src/tree.c | 0 30 files changed, 67 insertions(+), 300 deletions(-) rename dimers random walk.xml => data/dimers random walk.xml (100%) rename automaton.h => include/automaton.h (100%) rename base.h => include/base.h (100%) rename callback.h => include/callback.h (100%) rename contain.h => include/contain.h (100%) rename dialog.h => include/dialog.h (100%) rename display.h => include/display.h (100%) rename graph_area.h => include/graph_area.h (100%) rename graphics.h => include/graphics.h (100%) rename parsing.h => include/parsing.h (100%) rename texts.h => include/texts.h (100%) rename tree.h => include/tree.h (100%) delete mode 100644 init.c.todo rename automaton.c => src/automaton.c (98%) rename callback.c => src/callback.c (100%) rename contain.c => src/contain.c (100%) rename dialog.c => src/dialog.c (100%) rename display.c => src/display.c (100%) rename draw.c => src/draw.c (100%) rename graph_area.c => src/graph_area.c (100%) rename graph_stack.c => src/graph_stack.c (100%) rename grid.c => src/grid.c (100%) rename init.c => src/init.c (100%) create mode 100644 src/main.c rename parsing.c => src/parsing.c (100%) rename shader.frag => src/shader.frag (100%) rename shader.vert => src/shader.vert (100%) rename texts.c => src/texts.c (100%) rename tree.c => src/tree.c (100%) diff --git a/Makefile b/Makefile index 18f51cb..de22701 100644 --- a/Makefile +++ b/Makefile @@ -15,144 +15,60 @@ BINDIR=bin BUILDDIR=build SRCDIR=src -sources = $(shell find . -maxdepth 1 -type f -name "*.c") -objects = $(patsubst %.c,%.o,$(sources)) -dependencies = $(patsubst %.c,%.d,$(sources)) +SOURCES = $(shell find $(SRCDIR) -type f -name "*.c") +OBJECTS = $(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES)) +DEPENDENCIES = $(patsubst %.c,$(BUILDDIR)/%.d,$(SOURCES)) -all: myprogram +all: $(BINDIR)/gem-graph-client --include $(dependencies) +-include /etc/os-release -myprogram: $(objects) - $(CC) $(LDFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) $^ -o $@ +# +# Directories +# +$(BUILDDIR): + mkdir -p $@ -%.o: %.c Makefile - $(CC) $(CFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) -c $< -o $@ +$(BINDIR): + mkdir -p $@ -%.d: %.c Makefile +# +# Dependencies +# +-include $(DEPENDENCIES) + +$(BUILDDIR)/%.d: %.c Makefile | $(BUILDDIR) + mkdir -p $(shell dirname $@) $(CC) $(CFLAGS) -MM -MT $(@:%.d=%.o) -MF $@ $< +# +# Main program +# +$(BINDIR)/gem-graph-client: $(OBJECTS) | $(BINDIR) + $(CC) $(LDFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) $^ -o $@ + +# +# Objects +# +$(BUILDDIR)/%.o: %.c Makefile | $(BUILDDIR) + mkdir -p $(shell dirname $@) + $(CC) $(CFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) -c $< -o $@ + +# +# Virtual recipes +# install: echo "Installing is not supported" -run: myprogram - ./myprogram +run: $(BINDIR)/gem-graph-client + $(BINDIR)/gem-graph-client clean: - rm -f myprogram - rm -f *.o - rm -f *.d - -# /!\ erreur fatale: GL/glu.h -# gcc -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -g -Wall -Wextra -# -std=c99 -lm *.c -o formattage `pkg-config --cflags --libs glib-2.0` - -#------------------------------------------------------------------------------# -# 'make' has an implicit rule for updating a ‘.o’ file # -# from a correspondingly named ‘.c’ file # -# using a ‘cc -c’ command. # -# Implicit rules are listed and applied in a predefined order (C before P...) # -# Predefined implicit rules are implemented in make as suffix rules # -# The default suffix list is: .out, .a, .ln, .o, .c, .cc, .C, .cpp, .p,... # -# Rules whose suffixes fail to be on the list are disabled. # -# You can define your own implicit rules by writing pattern rules. # -#------------------------------------------------------------------------------# - -# If there are many implicit rules with the same target pattern, -# the rule that actually applies is the one whose prerequisites exist or can be made -# ex: a .o can be made from a .c (C compiler) or a .p (Pascal compiler) - -# Variables allow a text string to be defined once -# and substituted in multiple places later. -# (see Chapter 6 [How to Use Variables], page 65) + rm -rf $(BINDIR) + rm -rf $(BUILDDIR) - -#------------------------------------------------------------------------------# -# To study : how can the following commands be modified ? # -#------------------------------------------------------------------------------# - -#SHELL = /bin/sh -#.SUFFIXES: -#.SUFFIXES: .c .o .h # is .h useful ? -#.PHONY = run -#.PHONY = clean -#.PHONY: Makefile - -#CC=gcc -#CFLAGS=`pkg-config --cflags gtk4 --libs gtk4` -#WARNINGS = -Wall -#DEBUG = -ggdb -fno-omit-frame-pointer -#OPTIMIZE = -O2 - -# in exec.o: -# $(WARNINGS) $(DEBUG) $(OPTIMIZE) < ne sont pas indispensables -# si le $@ est supprimé, main.cest modifié -#all: -# exec - -#install: -# echo "Installing is not supported" - - - - - - -#------------------------------------------------------------------------------# -# Personnal notes & links # -#------------------------------------------------------------------------------# - - -# gcc $( pkg-config --cflags gtk4 ) -o exec main.c $( pkg-config --libs gtk4 ) - +# More docs : # https://www.gnu.org/software/make/manual/ - -# Makefiles contain five kinds of things: -# explicit rules, implicit rules, variable definitions, directives and comments. - - -# Variables automatiques -------------------------------------------------- -# $@ fait référence à la cible de la règle (au nom de la cible). -# $< fait référence à la première dépendance. -# $? fait référence aux noms de touess les dépendances plus récentes que la cible. -# = les fichiers qui ont été modifiés après la compilation de code la plus récente -# $^ fait référence aux noms de touess les dépendances avec des espaces entre eux. - -# Variables implicites ------------------------------------------------- -# VPATH Équivalent utilitaire de la variable PATH de Bash. Vide par défaut. -# Les chemins sont séparés par le signe deux-points (:). -# CC Le programme pour compiler des fichiers C. -# La valeur par défaut est cc. (Habituellement, cc pointe vers gcc.) -# CPP Le programme qui exécute le préprocesseur C. -# La valeur par défaut est $ (CC) -E. -# LEX Le programme qui transforme les grammaires lexicales en code source. -# La valeur par défaut est lex. (Vous devriez remplacer cela par flex.) -# LINT Le programme qui lint votre code source. La valeur par défaut est lint. -# RM La commande pour supprimer un fichier. La valeur par défaut est rm -f. -# CFLAGS Contient tous les indicateurs du compilateur C (cc). -# CPPFLAGS tous les indicateurs du préprocesseur C. -# .PHONY Spécifie des cibles qui ne ressemblent pas au nom d'un fichier. -# Un exemple est la cible "make clean" ; où clean est une valeur de .PHONY - -# Syntaxe de Base -# Règles : Une règle se compose d'une cible, des dépendances et des commandes. -# Elle est généralement structurée comme suit : -# cible: dépendances -# commande -# -# La cible (target) est le fichier à générer, -# les dépendances (prerequisites) sont les fichiers requis pour construire la cible -# et les commandes (recipe) sont les instructions exécutées pour créer la cible. -# -# A simple makefile consists of “rules” with the following shape: -# target ... : prerequisites ... -# recipe -# ... -# A target is usually the name of a file that is generated by a program; -# examples of targets are executable or object files. -# A target can also be the name of an action to carry out, such as ‘clean’ - - # accessoirement : https://blog.stephane-robert.info/docs/makefile/ & /docs/task/ diff --git a/dimers random walk.xml b/data/dimers random walk.xml similarity index 100% rename from dimers random walk.xml rename to data/dimers random walk.xml diff --git a/automaton.h b/include/automaton.h similarity index 100% rename from automaton.h rename to include/automaton.h diff --git a/base.h b/include/base.h similarity index 100% rename from base.h rename to include/base.h diff --git a/callback.h b/include/callback.h similarity index 100% rename from callback.h rename to include/callback.h diff --git a/contain.h b/include/contain.h similarity index 100% rename from contain.h rename to include/contain.h diff --git a/dialog.h b/include/dialog.h similarity index 100% rename from dialog.h rename to include/dialog.h diff --git a/display.h b/include/display.h similarity index 100% rename from display.h rename to include/display.h diff --git a/graph_area.h b/include/graph_area.h similarity index 100% rename from graph_area.h rename to include/graph_area.h diff --git a/graphics.h b/include/graphics.h similarity index 100% rename from graphics.h rename to include/graphics.h diff --git a/parsing.h b/include/parsing.h similarity index 100% rename from parsing.h rename to include/parsing.h diff --git a/texts.h b/include/texts.h similarity index 100% rename from texts.h rename to include/texts.h diff --git a/tree.h b/include/tree.h similarity index 100% rename from tree.h rename to include/tree.h diff --git a/init.c.todo b/init.c.todo deleted file mode 100644 index 7789ec0..0000000 --- a/init.c.todo +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Gem-graph OpenGL experiments - * - * Desc: GL functions - * - * Copyright (C) 2023 Arthur Menges - * Copyright (C) 2023 Adrien Bourmault - * - * This file is part of Gem-graph. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -/* -------------------------------------------------------------------------- */ - -#include -#include -#include "base.h" -#include "contain.h" // instead of "ui.h" -#include "graph_area.h" - -/* Initializes the buffer of a gl_area - * Calls according to the user preferences - * @param gl_area, ptr to the gl_area widget - * @return void - */ -void graphics_init_buffers(const int stack_id) -{ - struct graphic_stack_t *stack = &graphic_stack[stack_id]; - - //XXX - graphics_model_setup(stack_id); - - GLuint vao, vertex_buffer, color_buffer; - - glGenBuffers(1, &vertex_buffer); - glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); - glBufferData(GL_ARRAY_BUFFER, - stack->buffer_vertex_size * - sizeof(stack->buffer_vertex_origin[0]), - stack->buffer_vertex_origin, - GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - - // colors - glGenBuffers(1, &color_buffer); - glBindBuffer(GL_ARRAY_BUFFER, color_buffer); - glBufferData(GL_ARRAY_BUFFER, stack->buffer_colors_size * - sizeof(stack->buffer_colors_origin[0]), - stack->buffer_colors_origin, - GL_STATIC_DRAW); - glBindBuffer(GL_ARRAY_BUFFER, 0); - - // We only use one VAO, so we always keep it bound - glGenVertexArrays(1, &vao); - glBindVertexArray(vao); - - stack->vao = vao; - stack->position_buffer = vertex_buffer; - stack->color_buffer = color_buffer; -} - -/* - * Initializes the shaders of a gl_area and link them to a program - * - * @param gl_area, ptr to the gl_area widget - * - * @return true if initialized - */ -bool graphics_init_shaders(const int stack_id) -{ - struct graphic_stack_t *stack = &graphic_stack[stack_id]; - char *vertex_shader; - char *fragment_shader; - int status; - GLuint vertex = 0, fragment; // 2024-06-05 j'initialise vertex à 0 (au pif !) - GLuint program = 0; - GLuint m = 0; - GLuint v = 0; - GLuint p = 0; - - // Load vertex shader file - vertex_shader = read_file(VERTEX_SHADER_FILE); - if (vertex_shader == NULL) - return false; - vertex = create_shader(stack_id, GL_VERTEX_SHADER, vertex_shader); - - if(vertex == 0) { - stack->program = 0; - g_free(vertex_shader); - return false; - } - - // Load fragment shader file - fragment_shader = read_file(FRAG_SHADER_FILE); - if (fragment_shader == NULL) - return false; - fragment = create_shader(stack_id, GL_FRAGMENT_SHADER, fragment_shader); - - if(fragment == 0) { - glDeleteShader(vertex); - stack->program = 0; - g_free(vertex_shader); - g_free(fragment_shader); - return false; - } - - // Link shaders to program - program = glCreateProgram(); - glAttachShader(program, vertex); - glAttachShader(program, fragment); - - glLinkProgram(program); - - glGetProgramiv(program, GL_LINK_STATUS, &status); - - if(status == GL_FALSE) { - int log_len; - char *buffer; - - glGetProgramiv(program, GL_INFO_LOG_LENGTH, &log_len); - - buffer = g_malloc(log_len + 1); - assert(buffer); - glGetProgramInfoLog(program, log_len, NULL, buffer); - - g_warning("Linking failure:\n%s", buffer); - - g_free(buffer); - - glDeleteProgram(program); - program = 0; - - glDeleteShader(vertex); - glDeleteShader(fragment); - - g_free(vertex_shader); - g_free(fragment_shader); - - return false; - } - - /* Get the location of the "mvp" uniform */ - m = glGetUniformLocation(program, "model_matrix"); - v = glGetUniformLocation(program, "view_matrix"); - p = glGetUniformLocation(program, "projection_matrix"); - - glDetachShader(program, vertex); - glDetachShader(program, fragment); - - glDeleteShader(vertex); - glDeleteShader(fragment); - - stack->program = program; - stack->m = m; - stack->v = v; - stack->p = p; - - g_free(vertex_shader); - g_free(fragment_shader); - - return true; -} diff --git a/automaton.c b/src/automaton.c similarity index 98% rename from automaton.c rename to src/automaton.c index 4f4f6fa..6e431df 100644 --- a/automaton.c +++ b/src/automaton.c @@ -1,6 +1,6 @@ #include #include -#include "callback.h" +#include "../include/callback.h" #include "automaton.h" diff --git a/callback.c b/src/callback.c similarity index 100% rename from callback.c rename to src/callback.c diff --git a/contain.c b/src/contain.c similarity index 100% rename from contain.c rename to src/contain.c diff --git a/dialog.c b/src/dialog.c similarity index 100% rename from dialog.c rename to src/dialog.c diff --git a/display.c b/src/display.c similarity index 100% rename from display.c rename to src/display.c diff --git a/draw.c b/src/draw.c similarity index 100% rename from draw.c rename to src/draw.c diff --git a/graph_area.c b/src/graph_area.c similarity index 100% rename from graph_area.c rename to src/graph_area.c diff --git a/graph_stack.c b/src/graph_stack.c similarity index 100% rename from graph_stack.c rename to src/graph_stack.c diff --git a/grid.c b/src/grid.c similarity index 100% rename from grid.c rename to src/grid.c diff --git a/init.c b/src/init.c similarity index 100% rename from init.c rename to src/init.c diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..a5f9b0c --- /dev/null +++ b/src/main.c @@ -0,0 +1,26 @@ +/******************************************************************************/ +/* */ +/* E coli by David S. Goodsell (2009) */ +/* --- */ +/* Let this freeze frame guide us towards the model */ +/* that alone can account for the phenomenon ! */ +/* */ +/******************************************************************************/ + +#include "callback.h" + +int main (int argc, char **argv) +{ + GtkApplication *app; + int status; + + app = gtk_application_new ("org.jean.GTK4_GG_hack", G_APPLICATION_DEFAULT_FLAGS); + g_signal_connect (app, "activate", G_CALLBACK (on_main_window_activation), NULL); + g_signal_connect (app, "activate", G_CALLBACK (on_dialog_window_activation), NULL); + status = g_application_run (G_APPLICATION (app), argc, argv); + g_object_unref (app); + + printf("in contain.get_SPACE_VIEW_box() (line 138) > ui_setup_glarea (0, GTK_WIDGET (middle_box)); < commented 2024/06/27 > TODO\n"); + + return status; +} diff --git a/parsing.c b/src/parsing.c similarity index 100% rename from parsing.c rename to src/parsing.c diff --git a/shader.frag b/src/shader.frag similarity index 100% rename from shader.frag rename to src/shader.frag diff --git a/shader.vert b/src/shader.vert similarity index 100% rename from shader.vert rename to src/shader.vert diff --git a/texts.c b/src/texts.c similarity index 100% rename from texts.c rename to src/texts.c diff --git a/tree.c b/src/tree.c similarity index 100% rename from tree.c rename to src/tree.c