New Makefile and project restructuration

This commit is contained in:
Jean Sirmai 2024-06-29 17:05:13 +02:00
parent 1d8fc9ef22
commit 175418ab35
Signed by: jean
GPG Key ID: FB3115C340E057E3
30 changed files with 67 additions and 300 deletions

164
Makefile
View File

@ -15,144 +15,60 @@ BINDIR=bin
BUILDDIR=build BUILDDIR=build
SRCDIR=src SRCDIR=src
sources = $(shell find . -maxdepth 1 -type f -name "*.c") SOURCES = $(shell find $(SRCDIR) -type f -name "*.c")
objects = $(patsubst %.c,%.o,$(sources)) OBJECTS = $(patsubst %.c,$(BUILDDIR)/%.o,$(SOURCES))
dependencies = $(patsubst %.c,%.d,$(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 $(BINDIR):
$(CC) $(CFLAGS) $(WARNINGS) $(DEBUG) $(OPTIMIZE) -c $< -o $@ mkdir -p $@
%.d: %.c Makefile #
# Dependencies
#
-include $(DEPENDENCIES)
$(BUILDDIR)/%.d: %.c Makefile | $(BUILDDIR)
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS) -MM -MT $(@:%.d=%.o) -MF $@ $< $(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: install:
echo "Installing is not supported" echo "Installing is not supported"
run: myprogram run: $(BINDIR)/gem-graph-client
./myprogram $(BINDIR)/gem-graph-client
clean: clean:
rm -f myprogram rm -rf $(BINDIR)
rm -f *.o rm -rf $(BUILDDIR)
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)
# More docs :
#------------------------------------------------------------------------------#
# 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 )
# https://www.gnu.org/software/make/manual/ # 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/ # accessoirement : https://blog.stephane-robert.info/docs/makefile/ & /docs/task/

View File

@ -1,175 +0,0 @@
/*
* Gem-graph OpenGL experiments
*
* Desc: GL functions
*
* Copyright (C) 2023 Arthur Menges <arthur.menges@a-lec.org>
* Copyright (C) 2023 Adrien Bourmault <neox@a-lec.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/* -------------------------------------------------------------------------- */
#include <stdlib.h>
#include <time.h>
#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;
}

View File

@ -1,6 +1,6 @@
#include <gtk-4.0/gtk/gtk.h> #include <gtk-4.0/gtk/gtk.h>
#include <assert.h> #include <assert.h>
#include "callback.h" #include "../include/callback.h"
#include "automaton.h" #include "automaton.h"

View File

View File

View File

26
src/main.c Normal file
View File

@ -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;
}

View File