Skip to content

Commit

Permalink
Merge pull request #38 from jbelinda/master
Browse files Browse the repository at this point in the history
Make it possible to build and use mlx on the FreeBSD OS
  • Loading branch information
alexandregv authored Oct 30, 2021
2 parents f2a9bce + f9df071 commit e9b7ee3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
7 changes: 5 additions & 2 deletions Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@

INC =%%%%


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

NAME = libmlx.a
NAME_UNAME = libmlx_$(shell uname).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 \
Expand Down
25 changes: 15 additions & 10 deletions configure
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/sh
#!/usr/bin/env sh

set -e

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

logging(){
local type=$1; shift
Expand Down Expand Up @@ -75,9 +75,9 @@ EOF

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

parse_args(){
Expand All @@ -98,6 +98,11 @@ parse_args(){
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."
Expand All @@ -113,9 +118,9 @@ main(){
cat test/Makefile.mk | grep -v %%%% >> test/Makefile.gen

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

main "$@"
8 changes: 6 additions & 2 deletions test/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ INC=%%%%

INCLIB=$(INC)/../lib

CC=gcc
UNAME := $(shell uname)

CFLAGS= -I$(INC) -O3 -I.. -g

Expand All @@ -13,11 +13,15 @@ OBJ = $(SRC:%.c=%.o)

LFLAGS = -L.. -lmlx -L$(INCLIB) -lXext -lX11 -lm

UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
# mac
CC = clang
else ifeq ($(UNAME), FreeBSD)
# FreeBSD
CC = clang
else
#Linux and others...
CC = gcc
LFLAGS += -lbsd
endif

Expand Down
20 changes: 12 additions & 8 deletions test/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/sh
#!/usr/bin/env sh

# This very basic script simulate user inputs for the CI
# Feel free to update, improve or remove it if proper
# intergration tests and/or unit tests are added.

set -e

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

logging(){
local type=$1; shift
Expand Down Expand Up @@ -47,7 +47,7 @@ sigint_handler(){

# look at test/main.c and run ./mlx-test to understand what this function does
test_default_main(){
make -f Makefile.gen all
${MAKE} -f Makefile.gen all
./mlx-test &
PID="$!"
log_info "./mlx-test running in background, pid:" $PID
Expand Down Expand Up @@ -80,11 +80,15 @@ test_default_main(){
}

main(){
case $(uname) in
FreeBSD) MAKE=gmake ;;
*) MAKE=make ;;
esac
cd $(dirname $0)
trap at_exit EXIT
trap sigint_handler INT

test_default_main
}

main "$@"
main "$@"

0 comments on commit e9b7ee3

Please sign in to comment.