diff -ur cgx_2.18.orig/src/Makefile cgx_2.18/src/Makefile
--- cgx_2.18.orig/src/Makefile	2022-07-20 15:44:41.000000000 -0500
+++ cgx_2.18/src/Makefile	2022-07-20 15:50:15.000000000 -0500
@@ -1,15 +1,16 @@
-CFLAGS = -O2 -Wall -Wno-narrowing \
+CFLAGS += -O2 -Wall -Wno-narrowing \
   -I./ \
-  -I/usr/include \
-  -I/usr/include/GL \
+  -I@PREFIX@/include \
+  -I@PREFIX@/include/GL \
   -I../../libSNL/src \
-  -I../../glut-3.5/src \
-  -I/usr/X11/include 
+  -I../../glut-3.5/src
 
-LFLAGS = \
-  -L/usr/lib64 -lGL -lGLU \
-  -L/usr/X11R6/lib64 -lX11 -lXi -lXmu -lXext -lXt -lSM -lICE \
-  -lm -lpthread -lrt
+LFLAGS += \
+  -lGL -lGLU -lglut \
+  -lX11 -lXi -lXmu -lXext -lXt -lSM -lICE \
+  -lm -lpthread
+
+CXXFLAGS += 
 
 
 # on 32bit systems change lib64 to lib
@@ -22,41 +23,6 @@
  userFunction.c
 
 SUTIL = \
- ../../glut-3.5/src/layerutil.c \
- ../../glut-3.5/src/glut_dials.c \
- ../../glut-3.5/src/glut_ext.c \
- ../../glut-3.5/src/glut_mesa.c \
- ../../glut-3.5/src/glut_menu.c \
- ../../glut-3.5/src/glut_modifier.c \
- ../../glut-3.5/src/glut_space.c \
- ../../glut-3.5/src/glut_shapes.c \
- ../../glut-3.5/src/glut_tablet.c \
- ../../glut-3.5/src/glut_warp.c \
- ../../glut-3.5/src/glut_8x13.c \
- ../../glut-3.5/src/glut_9x15.c \
- ../../glut-3.5/src/glut_hel10.c \
- ../../glut-3.5/src/glut_hel18.c \
- ../../glut-3.5/src/glut_hel12.c \
- ../../glut-3.5/src/glut_tr10.c \
- ../../glut-3.5/src/glut_tr24.c \
- ../../glut-3.5/src/glut_bitmap.c \
- ../../glut-3.5/src/glut_cursor.c \
- ../../glut-3.5/src/glut_event.c \
- ../../glut-3.5/src/glut_get.c \
- ../../glut-3.5/src/glut_overlay.c \
- ../../glut-3.5/src/glut_input.c \
- ../../glut-3.5/src/glut_stroke.c \
- ../../glut-3.5/src/glut_teapot.c \
- ../../glut-3.5/src/glut_winmisc.c \
- ../../glut-3.5/src/glut_fullscrn.c \
- ../../glut-3.5/src/glut_cindex.c \
- ../../glut-3.5/src/glut_roman.c \
- ../../glut-3.5/src/glut_mroman.c \
- ../../glut-3.5/src/glut_swidth.c \
- ../../glut-3.5/src/glut_bwidth.c \
- ../../glut-3.5/src/glut_win.c \
- ../../glut-3.5/src/glut_init.c \
- ../../glut-3.5/src/glut_util.c \
  uselibSNL.cpp \
  generateTet.cpp \
  ../../libSNL/src/*.cpp
@@ -66,7 +32,7 @@
 OUTIL = $(SUTIL:.c=.o)
 
 cgx: $(OLIB) $(OUTIL) $(OULIB)
-	g++  $(OULIB)  $(OLIB) $(OUTIL)  $(CFLAGS) $(LFLAGS) -o  $@
+	$(CXX)  $(OULIB)  $(OLIB) $(OUTIL)  $(CFLAGS) $(LFLAGS) $(CXXFLAGS) -o  $@
 
 
 
diff -ur cgx_2.18.orig/src/cgx.h cgx_2.18/src/cgx.h
--- cgx_2.18.orig/src/cgx.h	2022-07-20 15:44:41.000000000 -0500
+++ cgx_2.18/src/cgx.h	2022-07-20 15:54:36.000000000 -0500
@@ -25,6 +25,13 @@
 #include "extUtil.h"
 #include "trackball.h"
 
+/* change from sem_init to sem_open */
+#define sem_n *nptr
+#define sem_g *gptr
+#define sem_rep *rptr
+#define sem_stn *sptr
+#define sem_map3d *mptr
+#define sem_cute *cptr
 
 /* factors for the geometric tolerance for merging */
 /* the space used by all lines will be multiplied with this value to calculate the default */
@@ -88,8 +88,8 @@
   /* default tet mesher, 0:Netgen ng_vol, 1:tetgen */
   #define     TETMESHER  1
 #else
-  #define     HELPFILE        {"/usr/local/CalculiX/cgx_2.18/doc/cgx/cgx.html",\
-    "/usr/local/CalculiX/ccx_2.18/doc/ccx/ccx.html"}
+  #define     HELPFILE        {"@PREFIX@/share/doc/CalculiX/cgx/cgx.html",\
+    "@PREFIX@/share/doc/CalculiX/ccx/ccx.html"}
   /* default tet mesher, 0:Netgen ng_vol, 1:tetgen */
   #define     TETMESHER  1
 #endif
@@ -105,9 +105,9 @@
 #else
 /* #define     BROWSER         {"netscape"} */
 /*   #define     BROWSER         {"mozilla"} */
-  #define     BROWSER         {"firefox"}
+  #define     BROWSER         {"openbrowser"}
 /* #define     PSVIEWER         {"ghostview"} */
-  #define     PSVIEWER         {"gv"}
+  #define     PSVIEWER         {"open"}
   #define     ALLOW_SYS_FLAG   0
 #endif
 
diff -ur cgx_2.18.orig/src/cgx.c cgx_2.18/src/cgx.c
--- cgx_2.18.orig/src/cgx.c	2022-07-25 16:50:14.000000000 -0500
+++ cgx_2.18/src/cgx.c	2022-07-25 18:21:54.000000000 -0500
@@ -854,14 +854,24 @@
     while( access( "0__.tga", F_OK ) != 0 );
     while( access( "1__.tga", F_OK ) != 0 );
     while( access( "2__.tga", F_OK ) != 0 );
-    //sprintf( buffer, "composite -compose atop -gravity SouthWest -geometry +1+1 2__.tga 1__.tga 3__.tga");
+    sprintf(buffer, "mogrify -auto-orient 0__.tga");
+    system(buffer);
+    sprintf(buffer, "mogrify -auto-orient 1__.tga");
+    system(buffer);
+    sprintf(buffer, "mogrify -auto-orient 2__.tga");
+    system(buffer);
+
     sprintf( buffer, "composite -gravity SouthWest -geometry +1+1 2__.tga 1__.tga 3__.tga");
     system (buffer);
     while( access( "3__.tga", F_OK ) != 0 );
+    sprintf(buffer, "mogrify -auto-orient 3__.tga");
+    system(buffer);
     //sprintf( buffer, "composite -compose atop -gravity NorthWest -geometry +%d+%d 3__.tga 0__.tga hcpy_%d.tga",
     sprintf( buffer, "composite -alpha off -gravity NorthWest -geometry +%d+%d 3__.tga 0__.tga hcpy_%d.tga",
 		(GLint)width_menu*19/20, (GLint)height_menu/10, nr);
     system (buffer);
+    sprintf(buffer, "mogrify -auto-orient hcpy_%d.tga", nr);
+    system(buffer);
     //printf("%s",buffer);
     sprintf( buffer, "rm -f *__.tga %s",DEV_NULL);
     system (buffer);
@@ -906,7 +916,7 @@
       getTGAScreenShot(psNr);
       /* on some systems PS has to be changed to PS2 */
       //sprintf( buffer, "convert -density %dx%d -page +49+196 -gamma %lf hcpy_%d.tga PS:hcpy_%d.ps   ", (int)((double)(PS_DENSITY*width_w0)/(double)(INI_SCREEN+INI_MENU_WIDTH)),(int)((double)(PS_DENSITY*width_w0)/(double)(INI_SCREEN+INI_MENU_WIDTH)) , GAMMA, psNr, psNr);
-      sprintf( buffer, "convert hcpy_%d.tga -page A4 %s", psNr, fileName);
+      sprintf( buffer, "convert hcpy_%d.tga -auto-orient -page A4 %s", psNr, fileName);
       system (buffer);
       printf("%s\n", buffer);
       sprintf( buffer, "rm -f hcpy_%d.tga %s",psNr,DEV_NULL);
@@ -939,7 +949,7 @@
       getTGAScreenShot(0);
       while( access( "hcpy_0.tga", F_OK ) != 0 );
       gifNr++;
-      sprintf( buffer, "convert hcpy_0.tga _%d.gif",gifNr);
+      sprintf( buffer, "convert hcpy_0.tga -auto-orient _%d.gif",gifNr);
       printf("%s\n",buffer);
       system (buffer);
       if((movieFrames)&&(gifNr>=movieFrames))
@@ -963,7 +973,7 @@
       if(filePtr!=NULL) sprintf(fileName,"%s.gif",filePtr); else sprintf(fileName,"hcpy_%d.gif",gifNr);
       printf("create %s\n ",fileName);
       getTGAScreenShot(gifNr);
-      sprintf( buffer, "convert hcpy_%d.tga %s", gifNr, fileName);
+      sprintf( buffer, "convert hcpy_%d.tga -auto-orient %s", gifNr, fileName);
       system (buffer);
       sprintf( buffer, "rm -f hcpy_%d.tga %s",gifNr,DEV_NULL);
       system (buffer);
@@ -978,7 +988,7 @@
       if(filePtr!=NULL) sprintf(fileName,"%s.png",filePtr); else sprintf(fileName,"hcpy_%d.png",pngNr);
       printf("create %s\n ",fileName);
       getTGAScreenShot(pngNr);
-      sprintf( buffer, "convert hcpy_%d.tga %s", pngNr, fileName);
+      sprintf( buffer, "convert hcpy_%d.tga -auto-orient %s", pngNr, fileName);
       system (buffer);
       sprintf( buffer, "rm -f hcpy_%d.tga %s",pngNr,DEV_NULL);
       system (buffer);
@@ -6473,10 +6475,18 @@
 
   setall=seto( "all" );
 
-  if(sem_init(&sem_n, 0, 1) < 0) printf("Error in:sem_init\n");
-  if(sem_init(&sem_g, 0, 1) < 0) printf("Error in:sem_init\n");
-  if(sem_init(&sem_rep, 0, 1) < 0) printf("Error in:sem_init\n");
-  if(sem_init(&sem_stn, 0, 1) < 0) printf("Error in:sem_init\n");
+  nptr = sem_open("/sem_n", O_CREAT, 0644, 1);
+  sem_unlink("/sem_n");
+  if((nptr == SEM_FAILED)) printf("Error in:sem_open\n");
+  gptr = sem_open("/sem_g", O_CREAT, 0644, 1);
+  sem_unlink("/sem_g");
+  if((gptr == SEM_FAILED)) printf("Error in:sem_open\n");
+  rptr = sem_open("/sem_rep", O_CREAT, 0644, 1);
+  sem_unlink("/sem_rep");
+  if((rptr == SEM_FAILED)) printf("Error in:sem_open\n");
+  sptr = sem_open("/sem_stn", O_CREAT, 0644, 1);
+  sem_unlink("/sem_stn");
+  if((sptr == SEM_FAILED)) printf("Error in:sem_open\n");
 
   if( (parameter= (char **)malloc( MAX_STACK_PARAMS*sizeof(char *))) == NULL )
     printf("\n\n ERROR: malloc failed\n\n") ;
diff -ur cgx_2.18.orig/src/parser.c cgx_2.18/src/parser.c
--- cgx_2.18.orig/src/parser.c	2022-07-28 11:06:14.000000000 -0500
+++ cgx_2.18/src/parser.c	2022-07-28 11:24:23.000000000 -0500
@@ -1,3 +1,3 @@
-#include <extUtil.h>
+#include <cgx.h>
 
 
diff -ur cgx_2.18.orig/src/pickFunktions.c cgx_2.18/src/pickFunktions.c
--- cgx_2.18.orig/src/pickFunktions.c	2022-07-25 18:42:56.000000000 -0500
+++ cgx_2.18/src/pickFunktions.c	2022-07-25 19:18:21.000000000 -0500
@@ -4594,7 +4594,7 @@ void moveLineEndPoint(int lineNr, int pntNr, double ll
     else
     {
       printf("ERROR: selected point:%s is no line endpoint\n", point[pntNr].name);
-      return(-1);
+      return;
     }
     u=flag*llength;
     u/=scale->w;
@@ -7535,7 +7537,9 @@
     /* daten der geschnittenen elemente */
     if ((cutParam=(CutParam *)malloc((anz->emax+1)*sizeof(CutParam)) ) == NULL ) { printf(" ERROR: malloc failure\n\n"); return;}
 
-    if(sem_init(&sem_cute, 0, 1) < 0) printf("Error in:sem_init\n");
+    cptr = sem_open("/sem_cute", O_CREAT, 0644, 1);
+    sem_unlink("/sem_cute");
+    if((cptr = SEM_FAILED)) printf("Error in:sem_open\n");
     if(threads>anz->e) { nlocalThreads=anz->e; }
     else nlocalThreads=threads;
     //nlocalThreads=1;
@@ -7563,7 +7566,7 @@
     glob_cutElement=0;
     free(tid); tid=NULL;
     free(targ); targ=NULL;
-    if(sem_destroy(&sem_cute) < 0) printf("Error in:sem_init\n");
+    if(sem_close(cptr) < 0) printf("Error in:sem_open\n");
 
     for(e=1; e<anz_e; e++)
     {
diff -ur cgx_2.18.orig/src/setFunktions.c cgx_2.18/src/setFunktions.c
--- cgx_2.18.orig/src/setFunktions.c	2022-07-25 18:42:56.000000000 -0500
+++ cgx_2.18/src/setFunktions.c	2022-07-25 19:08:02.000000000 -0500
@@ -12087,7 +12088,9 @@
 
 #else
 
-  if(sem_init(&sem_map3d, 0, 1) < 0) printf("Error in:sem_init\n");
+  mptr = sem_open("/sem_map3d", O_CREAT, 0644, 1);
+  sem_unlink("/sem_map3d");
+  if((mptr = SEM_FAILED)) printf("Error in:sem_open\n");
   if(threads>set[set1].anz_n) { nlocalThreads=set[set1].anz_n; }
   else nlocalThreads=threads;
   //nlocalThreads=1;
@@ -12137,7 +12139,7 @@
   glob_map3d=0;
   free(tid); tid=NULL;
   free(targ); targ=NULL;
-  if(sem_destroy(&sem_map3d) < 0) printf("Error in:sem_init\n");
+  if(sem_close(mptr) < 0) printf("Error in:sem_open\n");
 #endif
 
   if(rsort) free(rsort);
