Skip to content

Commit

Permalink
Renaming 'mlx_linux' to 'mlx'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jules MUNTZ-BERGER committed Aug 28, 2022
1 parent d2d026e commit 677ca0a
Show file tree
Hide file tree
Showing 60 changed files with 8,292 additions and 0 deletions.
88 changes: 88 additions & 0 deletions mlx/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ${{ matrix.os }}
env:
DISPLAY: ":99"
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]

timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- name: Install mlx dependencies
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get update -qq
sudo apt-get install -y -qq gcc make xorg libxext-dev libbsd-dev
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install xquartz
echo "/usr/X11/bin" >> $GITHUB_PATH
else
echo "$RUNNER_OS not supported"
exit 1
fi
- name: Setup x11 headless testing environment
run: |
set -x
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install xvfb xdotool valgrind
Xvfb $DISPLAY -screen 0 1280x1024x24 &
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install xdotool
defaults write org.x.X11 enable_test_extensions -boolean true
sudo Xvfb $DISPLAY -screen 0 1280x1024x24 &
else
echo "$RUNNER_OS not supported"
exit 1
fi
- name: Run ./configure
run: ./configure

- name: make check Linux
if: matrix.os == 'ubuntu-latest'
run: make -f Makefile.gen check
- name: make check MacOS
continue-on-error: true
if: matrix.os == 'macos-latest'
run: make -f Makefile.gen check
# Didn't find a way to simulate inputs on Macos. libxdo seem to no longer work on macos.
# It can be partially fixed writing proper unit-tests, thus avoiding the need of libxdo.

- name: Check leaks from binary "test/mlx-test"
run: |
cd test
if [ "$RUNNER_OS" == "Linux" ]; then
echo "Info: Still reachable doesn't matter. Valgrind will return success on thoses reports.
It is fine, we searching for lost pointers. Valgrind will return exit status 42 if any block is lost."
valgrind --leak-check=full --show-leak-kinds=definite,indirect,possible --errors-for-leak-kinds=definite,indirect,possible --error-exitcode=42 ./mlx-test > /dev/null &
PID=$!
sleep 30
xdotool search --name Title3 windowfocus key Escape
xdotool search --name Title2 windowfocus key Escape
wait $PID
elif [ "$RUNNER_OS" == "macOS" ]; then
MallocStackLoggingNoCompact=1
./mlx-test &
sleep 30
leaks mlx-test
pkill mlx-test
fi
- name: Norminette, just for fun
continue-on-error: true
run: |
pip3 install Norminette
norminette *.c *.h
norminette --version
25 changes: 25 additions & 0 deletions mlx/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BSD 2-Clause License

Copyright (c) 2021, Ecole 42
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 changes: 24 additions & 0 deletions mlx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
##
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
##
## Made by Olivier Crouzet
## Login <[email protected]>
##
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
## Last update Tue May 15 15:44:41 2007 Olivier Crouzet
##

## Please use configure script


all : do_configure

do_configure :
./configure

clean :
./configure clean

fclean : clean

re : fclean all
66 changes: 66 additions & 0 deletions mlx/Makefile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
##
## Makefile for MiniLibX in /home/boulon/work/c/raytraceur/minilibx
##
## Made by Olivier Crouzet
## Login <[email protected]>
##
## Started on Tue Oct 5 15:56:43 2004 Olivier Crouzet
## Last update Tue May 15 15:41:20 2007 Olivier Crouzet
##

## Please use configure script


INC =%%%%

UNAME = $(shell uname)
CC = gcc
ifeq ($(UNAME),FreeBSD)
CC = clang
endif

NAME = libmlx.a
NAME_UNAME = libmlx_$(UNAME).a

SRC = mlx_init.c mlx_new_window.c mlx_pixel_put.c mlx_loop.c \
mlx_mouse_hook.c mlx_key_hook.c mlx_expose_hook.c mlx_loop_hook.c \
mlx_int_anti_resize_win.c mlx_int_do_nothing.c \
mlx_int_wait_first_expose.c mlx_int_get_visual.c \
mlx_flush_event.c mlx_string_put.c mlx_set_font.c \
mlx_new_image.c mlx_get_data_addr.c \
mlx_put_image_to_window.c mlx_get_color_value.c mlx_clear_window.c \
mlx_xpm.c mlx_int_str_to_wordtab.c mlx_destroy_window.c \
mlx_int_param_event.c mlx_int_set_win_event_mask.c mlx_hook.c \
mlx_rgb.c mlx_destroy_image.c mlx_mouse.c mlx_screen_size.c \
mlx_destroy_display.c

OBJ_DIR = obj
OBJ = $(addprefix $(OBJ_DIR)/,$(SRC:%.c=%.o))
CFLAGS = -O3 -I$(INC)

all : $(NAME)

$(OBJ_DIR)/%.o: %.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@

$(NAME) : $(OBJ)
ar -r $(NAME) $(OBJ)
ranlib $(NAME)
cp $(NAME) $(NAME_UNAME)

check: all
@test/run_tests.sh

show:
@printf "NAME : $(NAME)\n"
@printf "NAME_UNAME : $(NAME_UNAME)\n"
@printf "CC : $(CC)\n"
@printf "CFLAGS : $(CFLAGS)\n"
@printf "SRC :\n $(SRC)\n"
@printf "OBJ :\n $(OBJ)\n"

clean :
rm -rf $(OBJ_DIR)/ $(NAME) $(NAME_UNAME) *~ core *.core

.PHONY: all check show clean
55 changes: 55 additions & 0 deletions mlx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[![Build](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml/badge.svg)](https://github.com/42Paris/minilibx-linux/actions/workflows/ci.yml)

This is the MinilibX, a simple X-Window (X11R6) programming API
in C, designed for students, suitable for X-beginners.


Contents

- source code in C to create the mlx library
- man pages (in man/ directory)
- a test program (in test/ directory) is built
with the library
- a public include file mlx.h
- a tiny configure script to generate an appropriate Makefile.gen

Requirements for Linux

- MinilibX only support TrueColor visual type (8,15,16,24 or 32 bits depth)
- gcc
- make
- X11 include files (package xorg)
- XShm extension must be present (package libxext-dev)
- Utility functions from BSD systems - development files (package libbsd-dev)
- **e.g. _sudo apt-get install gcc make xorg libxext-dev libbsd-dev_ (Debian/Ubuntu)**

Requirements for MacOS
- [Xquartz](https://www.xquartz.org/)

```bash
~ Brew install Xquartz
~ reboot
~ xeyes # run an hello world X11 app
```

MlX Color Opacity / Transparency / Alpha (32 bits depth)
- 0xFF (fully transparent) or 0x00 (fully opaque)

Compile MinilibX

- run ./configure or make
both will make a few tests, create Makefile.gen
and then automatically run make on this generated Makefile.gen .
libmlx.a and libmlx_$(HOSTTYPE).a are created.
test/mlx-test binary is also created.


Install MinilibX

- no installation script is provided. You may want to install
- libmlx.a and/or libmlx_$(HOSTTYPE).a in /usr/X11/lib or /usr/local/lib
- mlx.h in /usr/X11/include or /usr/local/include
- man/man3/mlx*.1 in /usr/X11/man/man3 or /usr/local/man/man3


Olivier CROUZET - 2014-01-06 -
126 changes: 126 additions & 0 deletions mlx/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env sh

set -e

BOLD="\033[1m"
RESET="\033[0m"
LIGHT_RED="\033[91m"
LIGHT_GREEN="\033[92m"
LIGHT_CYAN="\033[96m"

logging(){
local type=$1; shift
printf "${LIGHT_CYAN}${BOLD}configure${RESET} [%b] : %b\n" "$type" "$*"
}
log_info(){
logging "${LIGHT_GREEN}info${RESET}" "$@"
}
log_error(){
logging "${LIGHT_RED}error${RESET}" "$@" >&2
}

# find and print x11 header path
get_xlib_include_path(){
local result=""

for inc in \
/usr/X11/include \
/usr/X11R6/include \
/usr/X11R5/include \
/usr/X11R4/include \
\
/usr/include \
/usr/include/X11 \
/usr/include/X11R6 \
/usr/include/X11R5 \
/usr/include/X11R4 \
\
/usr/local/X11/include \
/usr/local/X11R6/include \
/usr/local/X11R5/include \
/usr/local/X11R4/include \
\
/usr/local/include/X11 \
/usr/local/include/X11R6 \
/usr/local/include/X11R5 \
/usr/local/include/X11R4 \
\
/usr/X386/include \
/usr/x386/include \
/usr/XFree86/include/X11 \
\
/usr/local/include \
/usr/athena/include \
/usr/local/x11r5/include \
/usr/lpp/Xamples/include \
\
/usr/openwin/include \
/usr/openwin/share/include
do
if [ -f "$inc/X11/Xlib.h" -a -f "$inc/X11/extensions/XShm.h" ]; then
result=$inc
break
fi
done
echo $result
}

show_help(){
cat <<EOF
Usage :
$0 Auto-configure and make MinilibX
$0 clean Execute the clean rule of both Makefile.gen
EOF
}

clean(){
log_info 'Execute "make clean" from "makefile.gen"'
${MAKE} -f Makefile.gen clean
log_info 'Execute "make clean" from "test/makefile.gen"'
${MAKE} -f Makefile.gen -C test/ --no-print-directory clean
}

parse_args(){
case "$1" in
--help | -h)
show_help
exit 0;;
clean)
clean
exit 0;;
"") return;;
*)
log_error "unknown command \"$1\"\nRun \"./configure --help\" for usage."
exit 1;;
esac
}

main(){
local xlib_inc="$(get_xlib_include_path)"

case $(uname) in
FreeBSD) MAKE=gmake ;;
*) MAKE=make ;;
esac

parse_args "$@"
if [ -z "$xlib_inc" ]; then
log_error "Can't find a suitable X11 include directory."
exit 1
fi
log_info "Found X11 include path directory: $xlib_inc"

log_info 'Generate "makefile.gen" from template "makefile.mk"'
echo "INC=$xlib_inc" > Makefile.gen
cat Makefile.mk | grep -v %%%% >> Makefile.gen
log_info 'Generate "test/makefile.gen" from template "test/makefile.mk"'
echo "INC=$xlib_inc" > test/Makefile.gen
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen

log_info 'Execute "make all" from file "makefile.gen"'
${MAKE} -f Makefile.gen all
log_info 'Execute "make all" from file "test/makefile.gen"'
(cd test ; ${MAKE} -f Makefile.gen all )
}

main "$@"
Loading

0 comments on commit 677ca0a

Please sign in to comment.